Skip to content

Commit f0f7c5d

Browse files
committed
Add parsed_body and querystring for profiles tests compatibility
1 parent 5b21583 commit f0f7c5d

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/shipchain_common/test_utils/httpretty_asserter.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,50 @@ def register_uri(self, # noqa
4343
self.mock.add(method=method, url=uri, body=body, status=status,
4444
adding_headers=adding_headers, match_querystring=match_querystring, headers=headers)
4545

46+
class Call:
47+
def __init__(self, responses_call):
48+
self.call = responses_call
49+
self.url = urlparse(self.call.request.url)
50+
51+
def __getattr__(self, item):
52+
return getattr(self.call, item)
53+
54+
@property
55+
def parsed_body(self):
56+
body = self.call.request.body or ''
57+
if self.call.request.headers.get('content-type', '') in ('application/json', 'text/json'):
58+
body = parse_value(body)
59+
else:
60+
body = parse_urlencoded_data(body)
61+
62+
return body
63+
64+
@property
65+
def querystring(self):
66+
return parse_urlencoded_data(self.url.query)
67+
68+
4669
@property
4770
def latest_requests(self):
48-
return self.mock.calls
71+
return [self.Call(call) for call in self.mock.calls]
4972

5073
def last_request(self):
51-
return self.mock.calls[-1] if self.mock.calls else None
74+
return self.Call(self.mock.calls[-1]) if self.mock.calls else None
5275

5376
def reset(self):
5477
self.mock._calls.reset() # pylint:disable=protected-access
5578

79+
5680
class ResponsesAsserter(ResponsesHTTPrettyWrapper):
5781
def _parse_calls_into_list(self):
5882
calls_list = []
5983
assert self.latest_requests, 'Error: No calls made to be parsed.'
6084
for call in self.latest_requests:
61-
url = urlparse(call.request.url)
62-
body = call.request.body or ''
63-
if call.request.headers.get('content-type', '') in ('application/json', 'text/json'):
64-
body = parse_value(body)
65-
else:
66-
body = parse_urlencoded_data(body)
67-
6885
calls_list.append({
69-
'path': url.path,
70-
'query': parse_urlencoded_data(url.query),
71-
'body': body,
72-
'host': url.hostname
86+
'path': call.url.path,
87+
'query': call.querystring,
88+
'body': call.parsed_body,
89+
'host': call.url.hostname
7390
})
7491
assert calls_list, 'Error: No calls made to be parsed.'
7592
return calls_list

0 commit comments

Comments
 (0)