Skip to content

Commit 44d216d

Browse files
lesnik512claude
andcommitted
test(story-1.7): cover remaining with_options branches and per-call timeout
Adds tests for the previously-uncovered with_options override paths (base_url, default_headers, default_query, decoder) plus a per-call timeout test that verifies `timeout=` propagates into the Request's extensions dict. Brings src/httpware/client.py to 100% line coverage, addressing the final review's coverage concern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1f43410 commit 44d216d

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_client_methods.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,11 @@ async def test_request_method_uses_first_positional_method_arg() -> None:
161161
await client.request("CUSTOM", "/foo")
162162
assert transport.last_request is not None
163163
assert transport.last_request.method == "CUSTOM"
164+
165+
166+
async def test_per_call_timeout_propagates_to_request_extensions() -> None:
167+
transport = _RecordingTransport()
168+
client = AsyncClient(transport=transport)
169+
await client.get("/foo", timeout=2.5)
170+
assert transport.last_request is not None
171+
assert "timeout" in transport.last_request.extensions

tests/test_client_middleware_wiring.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,37 @@ async def test_view_does_not_own_transport() -> None:
9191
client = AsyncClient()
9292
view = client.with_options(timeout=10)
9393
assert view._owns_transport is False # noqa: SLF001
94+
95+
96+
async def test_with_options_overrides_base_url() -> None:
97+
transport = _RecordingTransport()
98+
client = AsyncClient(transport=transport, base_url="https://api.test/v1")
99+
view = client.with_options(base_url="https://other.test/v2")
100+
assert view._config.base_url == "https://other.test/v2" # noqa: SLF001
101+
102+
103+
async def test_with_options_overrides_default_headers() -> None:
104+
transport = _RecordingTransport()
105+
client = AsyncClient(transport=transport, default_headers={"x-old": "1"})
106+
view = client.with_options(default_headers={"x-new": "2"})
107+
assert view._config.default_headers == {"x-new": "2"} # noqa: SLF001
108+
109+
110+
async def test_with_options_overrides_default_query() -> None:
111+
transport = _RecordingTransport()
112+
client = AsyncClient(transport=transport, default_query={"old": "1"})
113+
view = client.with_options(default_query={"new": "2"})
114+
assert view._config.default_query == {"new": "2"} # noqa: SLF001
115+
116+
117+
async def test_with_options_overrides_decoder() -> None:
118+
transport = _RecordingTransport()
119+
120+
class _NoopDecoder:
121+
def decode(self, content: bytes, model: type) -> object: # pragma: no cover # noqa: ARG002
122+
return content
123+
124+
new_decoder = _NoopDecoder()
125+
client = AsyncClient(transport=transport)
126+
view = client.with_options(decoder=new_decoder)
127+
assert view._config.decoder is new_decoder # noqa: SLF001

0 commit comments

Comments
 (0)