Skip to content

Commit d88a0e5

Browse files
committed
make init params of HttpRequest/HttpResponse kw-only except for url
1 parent 29f84c6 commit d88a0e5

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

tests/test_page_inputs.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_http_response_json():
262262
response = HttpResponse(url, body=b'{"key": "value"}')
263263
assert response.json() == {"key": "value"}
264264

265-
response = HttpResponse(url, '{"ключ": "значение"}'.encode("utf8"))
265+
response = HttpResponse(url, body='{"ключ": "значение"}'.encode("utf8"))
266266
assert response.json() == {"ключ": "значение"}
267267

268268

@@ -274,7 +274,7 @@ def test_http_response_text():
274274
"""
275275
text = "œ is a Weird Character"
276276
body = HttpResponseBody(b"\x9c is a Weird Character")
277-
response = HttpResponse("http://example.com", body)
277+
response = HttpResponse("http://example.com", body=body)
278278

279279
assert response.text == text
280280

@@ -293,7 +293,7 @@ def test_http_headers_declared_encoding(headers, encoding):
293293
headers = HttpResponseHeaders(headers)
294294
assert headers.declared_encoding() == encoding
295295

296-
response = HttpResponse("http://example.com", b'', headers=headers)
296+
response = HttpResponse("http://example.com", body=b'', headers=headers)
297297
assert response.encoding == encoding or HttpResponse._DEFAULT_ENCODING
298298

299299

@@ -307,14 +307,14 @@ def test_http_response_utf16():
307307

308308

309309
def test_explicit_encoding():
310-
response = HttpResponse("http://www.example.com", "£".encode('utf-8'),
310+
response = HttpResponse("http://www.example.com", body="£".encode('utf-8'),
311311
encoding='utf-8')
312312
assert response.encoding == "utf-8"
313313
assert response.text == "£"
314314

315315

316316
def test_explicit_encoding_invalid():
317-
response = HttpResponse("http://www.example.com", "£".encode('utf-8'),
317+
response = HttpResponse("http://www.example.com", body="£".encode('utf-8'),
318318
encoding='latin1')
319319
assert response.encoding == "latin1"
320320
assert response.text == "£".encode('utf-8').decode("latin1")

tests/test_requests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def async_mock():
1919
"""Workaround since python 3.7 doesn't ship with asyncmock."""
2020

2121
async def async_test(req):
22-
return HttpResponse(req.url, b"")
22+
return HttpResponse(req.url, body=b"")
2323

2424
mock.MagicMock.__await__ = lambda x: async_test().__await__()
2525

web_poet/page_inputs.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ class HttpRequest:
157157
"""
158158

159159
url: str = attrs.field()
160-
method: str = attrs.field(default="GET")
160+
method: str = attrs.field(default="GET", kw_only=True)
161161
headers: HttpRequestHeaders = attrs.field(
162-
factory=HttpRequestHeaders, converter=HttpRequestHeaders
162+
factory=HttpRequestHeaders, converter=HttpRequestHeaders, kw_only=True
163163
)
164164
body: HttpRequestBody = attrs.field(
165-
factory=HttpRequestBody, converter=HttpRequestBody
165+
factory=HttpRequestBody, converter=HttpRequestBody, kw_only=True
166166
)
167167

168168

@@ -190,11 +190,12 @@ class HttpResponse:
190190
"""
191191

192192
url: str = attrs.field()
193-
body: HttpResponseBody = attrs.field(converter=HttpResponseBody)
194-
status: Optional[int] = attrs.field(default=None)
193+
body: HttpResponseBody = attrs.field(converter=HttpResponseBody, kw_only=True)
194+
status: Optional[int] = attrs.field(default=None, kw_only=True)
195195
headers: HttpResponseHeaders = attrs.field(factory=HttpResponseHeaders,
196-
converter=HttpResponseHeaders)
197-
_encoding: Optional[str] = attrs.field(default=None)
196+
converter=HttpResponseHeaders,
197+
kw_only=True)
198+
_encoding: Optional[str] = attrs.field(default=None, kw_only=True)
198199

199200
_DEFAULT_ENCODING = 'ascii'
200201
_cached_text: Optional[str] = None

0 commit comments

Comments
 (0)