Skip to content

Instantly share code, notes, and snippets.

@jamielennox
Created October 27, 2018 06:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamielennox/b8c4a81f6824568b97a80c3929d20c62 to your computer and use it in GitHub Desktop.
Save jamielennox/b8c4a81f6824568b97a80c3929d20c62 to your computer and use it in GitHub Desktop.
import requests
import requests_mock
def match_limited(request):
return '"Limit":10' in request.text
def match_limitless(request):
return '"Limit":10' not in request.text
limited_response = "limited"
limitless_response = "limitless"
with requests_mock.Mocker() as mocker:
mocker.post("/?Key=MessageGetList",
additional_matcher=match_limited,
text=limited_response)
mocker.post("/?Key=MessageGetList",
additional_matcher=match_limitless,
text=limitless_response)
print(requests.post("http://test.com/?Key=MessageGetList",
json={'hello': 'world'}).text)
import requests
import requests_mock
def my_response(request, context):
if '"Limit":10' in (request.text or ''):
return 'limited'
else:
return "limitless"
with requests_mock.Mocker() as mocker:
mocker.post("/?Key=MessageGetList", text=my_response)
print(requests.post("http://test.com/?Key=MessageGetList",
json={'hello': 'world'}).text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment