Skip to content

Instantly share code, notes, and snippets.

@ishan1608
Created December 6, 2017 07:44
Show Gist options
  • Save ishan1608/d6b64f02508f171df033ee4036f83888 to your computer and use it in GitHub Desktop.
Save ishan1608/d6b64f02508f171df033ee4036f83888 to your computer and use it in GitHub Desktop.
HTTMock Example
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