Created
September 16, 2016 09:50
-
-
Save chrisglass/20fb526511969e7487ff041244912d8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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