Skip to content

Instantly share code, notes, and snippets.

@wonderb0lt
Created November 28, 2013 16:38
Show Gist options
  • Save wonderb0lt/7694705 to your computer and use it in GitHub Desktop.
Save wonderb0lt/7694705 to your computer and use it in GitHub Desktop.
A quick fiddle with which you can assert that httmock was called in a certain way.
class httmock_assert:
def __init__(self, method=None, url=None):
self.method = method
self.url = url
self.data = None
self.headers = []
self.response = {'status_code': 200}
def assert_header(self, key, value):
self.headers.append((key, value))
return self
def assert_data(self, data):
self.data = data
return self
def and_return_on_success(self, httmock_dict):
self.response = httmock_dict
return self
def __call__(self, *args, **kwargs):
url, request = args
if self.method:
assert_that(request.method, is_(self.method))
if self.url:
assert_that(request.url, is_(self.url))
if self.data:
assert_that(request.data, is_(self.data))
for k, v in self.headers:
assert_that(request.headers, has_entry(k, v))
# If we came this far no assert failed. Hooray!
return self.response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment