Skip to content

Commit 0da78f8

Browse files
committed
fix: address Copilot and Greptile review feedback
- Add test for non-standard HTTPStatus fallback branch (codecov coverage) - Assert Allow header in 405 test per RFC 9110 (Greptile feedback)
1 parent 9ec17c5 commit 0da78f8

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/unit/api/test_exception_handlers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ async def handler() -> str:
255255
body = resp.json()
256256
assert body["success"] is False
257257
assert body["error"] == "Method Not Allowed"
258+
assert "POST" in resp.headers.get("allow", "")
258259

259260
def test_http_exception_5xx_returns_scrubbed_message(self) -> None:
260261
"""5xx HTTPException scrubs detail to prevent info leakage."""
@@ -285,3 +286,22 @@ async def handler() -> None:
285286
assert resp.status_code == 429
286287
body = resp.json()
287288
assert body["error"] == "Too Many Requests"
289+
290+
def test_http_exception_nonstandard_status_uses_fallback(self) -> None:
291+
"""Non-standard status code falls back to generic message."""
292+
from unittest.mock import MagicMock
293+
294+
from ai_company.api.exception_handlers import handle_http_exception
295+
296+
exc = MagicMock(spec=HTTPException)
297+
exc.status_code = 499
298+
exc.detail = ""
299+
exc.headers = None
300+
301+
request = MagicMock()
302+
request.method = "GET"
303+
request.url.path = "/test"
304+
305+
resp = handle_http_exception(request, exc)
306+
assert resp.status_code == 499
307+
assert resp.content.error == "Request error" # type: ignore[union-attr]

0 commit comments

Comments
 (0)