Created
December 6, 2017 07:44
-
-
Save ishan1608/d6b64f02508f171df033ee4036f83888 to your computer and use it in GitHub Desktop.
HTTMock Example
This file contains 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 json | |
import requests | |
from httmock import urlmatch, HTTMock | |
class HTTMockTest: | |
def test_hook_bin(self): | |
@urlmatch(netloc=r'(.*\.)?hookb\.in$') | |
def httpbin_mock(url, request): | |
print "Request Captured for {}, {}".format(url, request.method) | |
result = json.loads(request.body) == {"a": "b"} | |
return 'SUCCESS' if result else 'FAILURE' | |
with HTTMock(httpbin_mock): | |
response = requests.post('https://hookb.in/vX8dJ8G1', json={"a": "b"}) | |
print response.content | |
HTTMockTest().test_hook_bin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment