btnamespace
[not actively supported outside of internal Venmo usage]
A Braintree namespace isolates state on the Braintree gateway:
import braintree
import btnamespace
with btnamespace.Namespace():
customer = braintree.Customer.create({"id": "123"})
assert customer.id == "123"
braintree.Customer.find("123") # success
braintree.Customer.find("123") # NotFound exception
This is primarily useful during integration tests:
def setUp(self):
self.namespace = btnamespace.Namespace()
self.namespace.__enter__()
def test_some_sandbox_integration(self):
#...
def tearDown(self):
self.namespace.__exit__()
Compared to calling eg braintree.Customer.delete during tearDown, this has a number of advantages:
it’s faster, since no teardown is needed
it’s simpler, since it doesn’t require any bookkeeping
it’s robust, since tests can be written without any state assumptions
You can install it with $ pip install btnamespace.
What’s supported
Customer create, update, find, delete
CreditCard create, update, find, delete
Transaction create, find
All operations involving subresources - eg creating a CreditCard and Customer in one call - work as expected.
Adding support for other operations is easy; we just haven’t needed them yet. Contributions welcome!
How it Works
Under the hood, a Namespace globally patches the braintree client library.
During create operations, any provided ids are removed. This forces the gateway to respond with unique ids, which are later mapped back to the originally-provided ids. Here’s an example:
on a call to braintree.Customer.create({'id': '123', ...}), '123' is stored as a Customer id and the call becomes braintree.Customer.create({...}).
then, the server returns a unique id 'abcde' for the Customer. '123' is mapped to 'abcde', and the resulting Customer object’s id is set to '123'.
later, a call to braintree.Customer.find('123') becomes braintree.Customer.find('abcde').
Contributing
Inside your vitualenv:
$ cd btnamespace
$ pip install -e .
$ pip install -r dev-requirements.txt
To run the tests, first add your sandbox credentials:
$ export BT_MERCHANT_ID=merchant-id
$ export BT_PUBLIC_KEY=public-id
$ export BT_PRIVATE_KEY=private-key
Then run $ pytest.
History
2.1.1
released 2022-03-18
Add missing history notes
2.1.0
released 2022-03-18
Add support for Python 3.5 and 3.7
2.0.0
released 2016-07-15
breaking: drop python 2.6 support
fix a bug affecting operations after exiting a namespace
add strict_missing and strict_missing_exception options
1.1.1
released 2014-09-26
pin bidict to 0.1.5 to avoid breaking changes in newer versions
1.1.0
released 2014-07-28
add schema for braintree.ClientToken.generate
1.0.1
released 2014-04-08
use less expensive introspection
remove decorator dependency
1.0.0
released 2014-04-07
initial release
Metadata
Release files for btnamespace 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| btnamespace-2.1.1.tar.gz | 9.9 kB | Without provenance | Details for btnamespace-2.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| btnamespace-2.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for btnamespace-2.1.1-py2.py3-none-any.whl |
Total release size: 21.0 kB
Release files / btnamespace-2.1.1.tar.gz
| Download URL | btnamespace-2.1.1.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95213dcb9c4e91abca4d1d2f41cab2a626718dec4915e35375a8872b0393c477
|
|
BLAKE2b-256 checksum How to use checksums |
75ba56c45e1676c352352ba5d6bb1508ef7ec5029d75740677c54662f81bf2bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
|
Release files / btnamespace-2.1.1-py2.py3-none-any.whl
| Download URL | btnamespace-2.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
ce0594942e22d9a31d731be9cdec619ea541eb31b51585fcd55cf7ecd39953bb
|
|
BLAKE2b-256 checksum How to use checksums |
a25a522d55f6d81fe4b52344d789c351bb749b5ddcfa6431d547aef668575bc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
|
Security for btnamespace 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.