0

I've been writing unit tests for my app, which uses braintree and braintree_python for billing. The module is installed using pip.

For some of my unit tests, I need to have a transaction's status transition from 'submitted_for_settlement' to 'settled', which, in the sandbox, takes too long for a quick unit test.

From the Docs, and other Questions (1, 2), I gather this can be done using TestHelper.

Problem is, while TestHelper seems to exist in the braintree/braintree_python repo, I cannot figure out how to import it.

Is there a way to import TestHelper and use it in my unit tests?

Community
  • 1
  • 1
Evan Giesel
  • 371
  • 1
  • 4
  • 13

1 Answers1

2

Full disclosure: I work at Braintree.

You can use TestHelper, but instead I would suggest using the TestingGateway. Import it in your test file:

from braintree_python.braintree import TestingGateway

Initialize an instance of it with a gateway configured for use with your sandbox and call its methods on a sandbox transaction:

config = Configuration(braintree.Environment.Sandbox, "your_merchant_id", "your_public_key", "your_private_key")
braintree_gateway = BraintreeGateway(config)
testing_gateway = TestingGateway(braintree_gateway)

testing_gateway.settle_transaction("transaction_id")

Both these classes require API calls out to the Braintree sandbox, so this may be a better fit for your integration tests.

Jessica d
  • 753
  • 6
  • 12
  • That seems to be working, thanks! Any reason the [docs](https://developers.braintreepayments.com/reference/general/testing/python#settlement-status) only mention TestHelper, and not this? – Evan Giesel Jan 14 '16 at 16:52
  • 2
    @Evan Giesel Glad you got it working! We're planning to update the docs to include this. – Jessica d Jan 15 '16 at 20:00