Skip to content

Instantly share code, notes, and snippets.

@mojtabaahn
Created September 2, 2022 06:40
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 mojtabaahn/d86d78494c6710e9c01fb9b6ea426e33 to your computer and use it in GitHub Desktop.
Save mojtabaahn/d86d78494c6710e9c01fb9b6ea426e33 to your computer and use it in GitHub Desktop.
Mocking SDKs in python [4]
from httpx import Response, Client
from app import app
from factories import UserFactory, BasketFactory
from unittest.mock import MagicMock
def test_purchase_basket_controller():
get_gateway_url = payment_sdk.get_gateway_url
payment_sdk.get_gateway_url = MagicMock(return_value='https://sample_bank_url.test')
with Client(app=app, base_url="http://testserver.test", timeout=0.1) as client:
user = UserFactory.create_one()
basket = BasketFactory.create_one(user_id=user.id)
response = client.post(
url='/basket/purchase',
headers=dict(Accept='application/json')
)
assert response.status_code == 307
payment_sdk.get_gateway_url = get_gateway_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment