Skip to content

Commit 4d59e5e

Browse files
🧪 Add test verifying check_error reads response body
Addresses PR feedback by adding `test_check_error_reads_body` which verifies that `response.aread()` is called when `response.is_success` is False, ensuring the body is completely read for streamed responses. Also fixed PEP8 import order. Co-authored-by: rnovatorov <[email protected]>
1 parent 729bdf2 commit 4d59e5e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎tests/unit/test_http/test_api/test_errors.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest.mock import AsyncMock
2+
13
import httpx
24
import pytest
35

@@ -80,3 +82,18 @@ def test_multi_error_from_dto_empty_list():
8082
"""Test MultiError.from_dto raises ValueError on empty error list."""
8183
with pytest.raises(ValueError, match="empty error list"):
8284
MultiError.from_dto({"errors": []})
85+
86+
87+
@pytest.mark.asyncio
88+
async def test_check_error_reads_body():
89+
"""Test that check_error reads the response body."""
90+
response = httpx.Response(
91+
status_code=500,
92+
content=b"Internal Server Error",
93+
request=httpx.Request("GET", "https://example.com"),
94+
)
95+
response.aread = AsyncMock()
96+
with pytest.raises(httpx.HTTPStatusError):
97+
await check_error(response)
98+
99+
response.aread.assert_awaited_once()

0 commit comments

Comments
 (0)