diff --git a/tests/test_page_inputs.py b/tests/test_page_inputs.py index 038cb285..2621d2c0 100644 --- a/tests/test_page_inputs.py +++ b/tests/test_page_inputs.py @@ -262,7 +262,7 @@ def test_http_response_json(): response = HttpResponse(url, body=b'{"key": "value"}') assert response.json() == {"key": "value"} - response = HttpResponse(url, '{"ключ": "значение"}'.encode("utf8")) + response = HttpResponse(url, body='{"ключ": "значение"}'.encode("utf8")) assert response.json() == {"ключ": "значение"} @@ -274,7 +274,7 @@ def test_http_response_text(): """ text = "œ is a Weird Character" body = HttpResponseBody(b"\x9c is a Weird Character") - response = HttpResponse("http://example.com", body) + response = HttpResponse("http://example.com", body=body) assert response.text == text @@ -293,7 +293,7 @@ def test_http_headers_declared_encoding(headers, encoding): headers = HttpResponseHeaders(headers) assert headers.declared_encoding() == encoding - response = HttpResponse("http://example.com", b'', headers=headers) + response = HttpResponse("http://example.com", body=b'', headers=headers) assert response.encoding == encoding or HttpResponse._DEFAULT_ENCODING @@ -307,14 +307,14 @@ def test_http_response_utf16(): def test_explicit_encoding(): - response = HttpResponse("http://www.example.com", "£".encode('utf-8'), + response = HttpResponse("http://www.example.com", body="£".encode('utf-8'), encoding='utf-8') assert response.encoding == "utf-8" assert response.text == "£" def test_explicit_encoding_invalid(): - response = HttpResponse("http://www.example.com", "£".encode('utf-8'), + response = HttpResponse("http://www.example.com", body="£".encode('utf-8'), encoding='latin1') assert response.encoding == "latin1" assert response.text == "£".encode('utf-8').decode("latin1") diff --git a/tests/test_requests.py b/tests/test_requests.py index c13b21c2..ab1ed5fc 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -19,7 +19,7 @@ def async_mock(): """Workaround since python 3.7 doesn't ship with asyncmock.""" async def async_test(req): - return HttpResponse(req.url, b"") + return HttpResponse(req.url, body=b"") mock.MagicMock.__await__ = lambda x: async_test().__await__() diff --git a/web_poet/page_inputs.py b/web_poet/page_inputs.py index a0ce562e..870d0a02 100644 --- a/web_poet/page_inputs.py +++ b/web_poet/page_inputs.py @@ -157,12 +157,12 @@ class HttpRequest: """ url: str = attrs.field() - method: str = attrs.field(default="GET") + method: str = attrs.field(default="GET", kw_only=True) headers: HttpRequestHeaders = attrs.field( - factory=HttpRequestHeaders, converter=HttpRequestHeaders + factory=HttpRequestHeaders, converter=HttpRequestHeaders, kw_only=True ) body: HttpRequestBody = attrs.field( - factory=HttpRequestBody, converter=HttpRequestBody + factory=HttpRequestBody, converter=HttpRequestBody, kw_only=True ) @@ -190,11 +190,12 @@ class HttpResponse: """ url: str = attrs.field() - body: HttpResponseBody = attrs.field(converter=HttpResponseBody) - status: Optional[int] = attrs.field(default=None) + body: HttpResponseBody = attrs.field(converter=HttpResponseBody, kw_only=True) + status: Optional[int] = attrs.field(default=None, kw_only=True) headers: HttpResponseHeaders = attrs.field(factory=HttpResponseHeaders, - converter=HttpResponseHeaders) - _encoding: Optional[str] = attrs.field(default=None) + converter=HttpResponseHeaders, + kw_only=True) + _encoding: Optional[str] = attrs.field(default=None, kw_only=True) _DEFAULT_ENCODING = 'ascii' _cached_text: Optional[str] = None