diff --git a/tests/mockserver/http_resources.py b/tests/mockserver/http_resources.py index 969e29a8c..23494a6bb 100644 --- a/tests/mockserver/http_resources.py +++ b/tests/mockserver/http_resources.py @@ -413,11 +413,13 @@ class UriResource(BaseResource): class ResponseHeadersResource(BaseResource): - """Return a response with headers set from the JSON request body""" + """Return a response with headers set from the JSON request body, and the + status code set from the *n* URL parameter, 200 by default.""" def render(self, request: Request) -> bytes: assert request.content body = json.loads(request.content.read().decode()) + request.setResponseCode(getarg(request, b"n", 200, type_=int)) for header_name, header_value in body.items(): request.responseHeaders.setRawHeaders(header_name, [header_value]) return json.dumps(body).encode("utf-8") diff --git a/tests/utils/bases/download_handlers_http.py b/tests/utils/bases/download_handlers_http.py index abf153817..eea2352a8 100644 --- a/tests/utils/bases/download_handlers_http.py +++ b/tests/utils/bases/download_handlers_http.py @@ -295,6 +295,20 @@ class TestHttpBase(ABC): header_value.encode(encoding="utf-8") ] + @coroutine_test + async def test_download_has_correct_response_status_and_headers( + self, mockserver: MockServer + ) -> None: + request = Request( + mockserver.url("/response-headers?n=302", is_secure=self.is_secure), + headers={"content-type": "application/json"}, + body=json.dumps({"Set-Cookie": "status=302"}), + ) + async with self.get_dh() as download_handler: + response = await download_handler.download_request(request) + assert response.status == 302 + assert response.headers.getlist("Set-Cookie") == [b"status=302"] + @coroutine_test async def test_download_no_extra_response_headers( self, mockserver: MockServer