def match(self, request, recorded_request): recorded = deserialize_prepared_request(recorded_request) if (request.headers.get("Content-Type") != self.content_type or recorded.headers.get("Content-Type") != self.content_type): return False body = parse_qs(request.body) if request.body else None recorded_body = parse_qs(recorded.body) if recorded.body else None return body == recorded_body
def test_deserialize_prepared_request(self): s = { "body": "key=value", "headers": {"User-Agent": "betamax/test header"}, "method": "GET", "uri": "http://example.com/", } p = util.deserialize_prepared_request(s) assert p.body == "key=value" assert p.headers == CaseInsensitiveDict({"User-Agent": "betamax/test header"}) assert p.method == "GET" assert p.url == "http://example.com/"
def match(self, request, recorded_request): """Determine if the JSON encoded bodies match.""" recorded = deserialize_prepared_request(recorded_request) # If neither of them have the right Content-Type set, return False if not (is_json(request.headers.get('Content-Type')) and is_json(recorded.headers.get('Content-Type'))): return False request_json = json.loads(request.body) if request.body else None recorded_json = json.loads(recorded.body) if recorded.body else None return request_json == recorded_json
def test_deserialize_prepared_request(self): s = { 'body': 'key=value', 'headers': { 'User-Agent': 'betamax/test header', }, 'method': 'GET', 'uri': 'http://example.com/', } p = util.deserialize_prepared_request(s) assert p.body == 'key=value' assert p.headers == CaseInsensitiveDict( {'User-Agent': 'betamax/test header'}) assert p.method == 'GET' assert p.url == 'http://example.com/'
def test_deserialize_prepared_request(self): s = { 'body': 'key=value', 'headers': { 'User-Agent': 'betamax/test header', }, 'method': 'GET', 'uri': 'http://example.com/', } p = util.deserialize_prepared_request(s) assert p.body == 'key=value' assert p.headers == CaseInsensitiveDict( {'User-Agent': 'betamax/test header'} ) assert p.method == 'GET' assert p.url == 'http://example.com/'
def neq_request(recorded_request): """Provide a not equal request.""" req = recorded_request.copy() req['body'] = {'string': '{}', 'encoding': 'utf-8'} return deserialize_prepared_request(req)
def eq_request(recorded_request): """Provide a perfectly equal request.""" return deserialize_prepared_request(recorded_request)
def match(self, request, recorded_request): recorded_request = deserialize_prepared_request(recorded_request) recorded_body = recorded_request.body.split('&') request_body = (request.body or b'').split('&') return sorted(request_body) == sorted(recorded_body)