Created
October 27, 2018 06:37
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
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) |
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
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