def assert_called(self, method, url, body=None, pos=-1): """Assert than an API method was just called.""" expected = (method, utils.order_url(url)) called = (self.client.callstack[pos][0], utils.order_url(self.client.callstack[pos][1])) assert self.client.callstack, \ "Expected %s %s but no calls were made." % expected assert expected == called, \ 'Expected %s %s; got %s %s' % (expected + called) if body is not None: if self.client.callstack[pos][2] != body: raise AssertionError('%r != %r' % (self.client.callstack[pos][2], body))
def assert_called_anytime(self, method, url, body=None): """Assert than an API method was called anytime in the test. """ expected = (method, utils.order_url(url)) assert self.callstack, \ "Expected %s %s but no calls were made." % expected found = False entry = None for entry in self.callstack: if expected == (entry[0], utils.order_url(entry[1])): found = True break assert found, 'Expected %s %s; got %s' % \ (method, url, self.callstack) if body is not None: assert entry[3] == body, "%s != %s" % (entry[3], body) self.callstack = []
def assert_called_anytime(self, method, url, body=None): """Assert than an API method was called anytime in the test.""" expected = (method, utils.order_url(url)) assert self.client.callstack, \ "Expected %s %s but no calls were made." % expected found = False for entry in self.client.callstack: if expected == (entry[0], utils.order_url(entry[1])): found = True break assert found, 'Expected %s; got %s' % (expected, self.client.callstack) if body is not None: try: assert entry[2] == body except AssertionError: print(entry[2]) print("!=") print(body) raise self.client.callstack = []