Skip to content

Commit

Permalink
add missing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
  • Loading branch information
provinzkraut committed Sep 16, 2023
1 parent 1ab0150 commit 65737cd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions litestar/response/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ def __init__(

@property
@deprecated("3.0", kind="property", alternative="encode_headers()")
def encoded_headers(self) -> tuple[tuple[bytes, bytes], ...]:
def encoded_headers(self) -> list[tuple[bytes, bytes]]:
return self.encode_headers()

def encode_headers(self) -> tuple[tuple[bytes, bytes], ...]:
return *self.headers.headers, *self._encoded_cookies
def encode_headers(self) -> list[tuple[bytes, bytes]]:
return [*self.headers.headers, *self._encoded_cookies]

async def after_response(self) -> None:
"""Execute after the response is sent.
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_response/test_base_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,8 @@ class FooResponse(Response):
def test_head_response_doesnt_support_content() -> None:
with pytest.raises(ImproperlyConfiguredException):
ASGIResponse(body=b"hello world", media_type=MediaType.TEXT, is_head_response=True)


def test_asgi_response_encoded_headers() -> None:
response = ASGIResponse(encoded_headers=[(b"foo", b"bar")])
assert response.encode_headers() == [(b"foo", b"bar")]
9 changes: 9 additions & 0 deletions tests/unit/test_response/test_file_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,12 @@ def handler() -> File:
response = client.get("/")
assert response.status_code == HTTP_200_OK
assert [h.lower() for h in response.headers.get_list("last-modified")] == ["foo"]


def test_asgi_response_encoded_headers(file: Path) -> None:
response = ASGIFileResponse(encoded_headers=[(b"foo", b"bar")], file_path=file)
assert response.encode_headers() == [
(b"foo", b"bar"),
(b"content-type", b"application/octet-stream"),
(b"content-disposition", b'attachment; filename=""'),
]
5 changes: 5 additions & 0 deletions tests/unit/test_response/test_streaming_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,8 @@ def numbers(minimum: int, maximum: int) -> Iterator[str]:
assert sse.data == "1\n, \n2\n, \n3\n, \n4\n, \n5"
assert sse.id == "123"
assert sse.retry == 1000


def test_asgi_response_encoded_headers() -> None:
response = ASGIStreamingResponse(encoded_headers=[(b"foo", b"bar")], iterator="")
assert response.encode_headers() == [(b"foo", b"bar"), (b"content-type", b"application/json")]

0 comments on commit 65737cd

Please sign in to comment.