Skip to content

Commit f47b003

Browse files
committed
test: parametrize the Allow header check to keep 100% branch coverage
The strict ``fail-under=100`` coverage gate on this repository counts branch coverage, and the previous ``if expected_status == 405:`` guard inside the parametrized test added an untaken branch on the 400 rows (which coverage reports as ``477->exit`` = 99.99% total). Fold the header check into the parametrize rows via a new ``expected_allow_header`` column and assert unconditionally: the 405 rows expect ``"GET, POST, DELETE"``, the 400 rows expect the header to be absent (``None``). Same coverage of the manager code, no dead branch inside the test.
1 parent be9c118 commit f47b003

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

tests/server/test_streamable_http_manager.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,18 @@ async def capture_send(message: Message):
385385

386386
@pytest.mark.anyio
387387
@pytest.mark.parametrize(
388-
("method", "expected_status", "expected_message_substring"),
388+
("method", "expected_status", "expected_message_substring", "expected_allow_header"),
389389
[
390-
("GET", 400, "Missing session ID"),
391-
("DELETE", 400, "Missing session ID"),
392-
("PUT", 405, "Method Not Allowed"),
393-
("PATCH", 405, "Method Not Allowed"),
394-
("OPTIONS", 405, "Method Not Allowed"),
395-
("HEAD", 405, "Method Not Allowed"),
390+
("GET", 400, "Missing session ID", None),
391+
("DELETE", 400, "Missing session ID", None),
392+
("PUT", 405, "Method Not Allowed", "GET, POST, DELETE"),
393+
("PATCH", 405, "Method Not Allowed", "GET, POST, DELETE"),
394+
("OPTIONS", 405, "Method Not Allowed", "GET, POST, DELETE"),
395+
("HEAD", 405, "Method Not Allowed", "GET, POST, DELETE"),
396396
],
397397
)
398398
async def test_non_post_without_session_id_does_not_allocate_session(
399-
method: str, expected_status: int, expected_message_substring: str
399+
method: str, expected_status: int, expected_message_substring: str, expected_allow_header: str | None
400400
):
401401
"""Regression test: no non-POST method without a session-id may allocate a
402402
session or spawn a background task.
@@ -473,14 +473,13 @@ async def mock_receive(): # pragma: no cover
473473
# ``Allow`` header. The manager's 405 mirrors the transport's shape
474474
# (``Allow: GET, POST, DELETE``) exactly so downstream clients get
475475
# identical metadata whether the rejection happens here or one layer
476-
# deeper.
477-
if expected_status == 405:
478-
response_headers = {
479-
name.decode().lower(): value.decode() for name, value in response_start.get("headers", [])
480-
}
481-
assert response_headers.get("allow") == "GET, POST, DELETE", (
482-
f"405 response must include RFC 7231 Allow header — got headers={response_headers}"
483-
)
476+
# deeper. 400 responses do not carry the header (they are not about
477+
# method mismatch), which is what ``expected_allow_header=None`` asserts.
478+
response_headers = {name.decode().lower(): value.decode() for name, value in response_start.get("headers", [])}
479+
assert response_headers.get("allow") == expected_allow_header, (
480+
f"Unexpected Allow header for {method}/{expected_status}: got {response_headers.get('allow')!r}, "
481+
f"expected {expected_allow_header!r}"
482+
)
484483

485484

486485
@pytest.mark.anyio

0 commit comments

Comments
 (0)