Skip to content

Commit ba5bdf8

Browse files
committed
docs(aiohttpretty): returned comments removed during refactor
1 parent 32fee41 commit ba5bdf8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
12
* text=auto

aiohttpretty/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def _build_response(
9999
loop = Mock()
100100
loop.get_debug = Mock()
101101
loop.get_debug.return_value = True
102-
102+
# When init `ClientResponse`, the second parameter must be of type `yarl.URL`
103+
# TODO: Integrate a property of this type to `ImmutableFurl`
103104
y_url = URL(uri)
104105
mock_response = ClientResponse(
105106
method,
@@ -121,6 +122,8 @@ def _build_response(
121122
# Build response headers manually
122123
headers = CIMultiDict(response.get('headers', {}))
123124
if response.get('auto_length'):
125+
# Calculate and overwrite the "Content-Length" header on-the-fly if Waterbutler tests
126+
# call `aiohttpretty.register_uri()` with `auto_length=True`
124127
headers.update({'Content-Length': str(content)})
125128
raw_headers = helpers.build_raw_headers(headers)
126129

@@ -133,6 +136,7 @@ def _build_response(
133136
return mock_response
134137

135138
def validate_body(self, options: typing.Mapping[str, typing.Any]):
139+
"""Validate body type to prevent unexpected behavior"""
136140
if body := options.get('body'):
137141
if not isinstance(
138142
body, (str, bytes)
@@ -147,6 +151,7 @@ def register_uri(self, method: METHODS, uri: str, **options: typing.Any):
147151
raise exc.InvalidResponses(
148152
'Cannot specify params in responses, call register multiple times.'
149153
)
154+
# Validates body before registry instead of during call to use the fail-fast principle
150155
self.validate_body(options)
151156
params = options.pop('params', {})
152157
url = types.ImmutableFurl(uri, params=params)

0 commit comments

Comments
 (0)