Skip to content

Instantly share code, notes, and snippets.

@chrisglass
Created September 16, 2016 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisglass/20fb526511969e7487ff041244912d8e to your computer and use it in GitHub Desktop.
Save chrisglass/20fb526511969e7487ff041244912d8e to your computer and use it in GitHub Desktop.
def run(payment=payment, **kwargs): # here the trick is to pass the payment instance as default value.
# Since we have an instance of payment in parameter now, we can inject it in the tests easily.
# Check that the client payed.
try:
contains_payment = payment.contains_payment(_price, request.headers, **kwargs)
except BadRequest as e:
return Response(e.description, BAD_REQUEST)
# Actually do stuff
run_params = request.get_json(silent=False)
...
# In the tests:
def test_payment_method(self):
class FakePayment(object): # That's a Fake. It looks like a Payment, with only the method we care about
def contains_payment(self):
return True # You have to write a test that returns False as well!
result = run(payment=FakePayment())
# (assert somehting on the result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment