File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -260,15 +260,9 @@ Use the router instance as decorator or context manager to patch `HTTPX` and act
260260import httpx
261261import respx
262262
263- from httpx import Response
264-
265-
266- api_mock = respx.mock(assert_all_called = False )
267- api_mock.route(
268- url = " https://api.foo.bar/baz/" ,
269- name = " baz" ,
270- ).mock(
271- return_value = Response(200 , json = {" name" : " baz" }),
263+ api_mock = respx.mock(base_url = " https://api.foo.bar/" , assert_all_called = False )
264+ api_mock.get(" /baz/" , name = " baz" ).mock(
265+ return_value = httpx.Response(200 , json = {" name" : " baz" }),
272266)
273267...
274268
@@ -286,6 +280,8 @@ def test_ctx_manager():
286280 ...
287281```
288282
283+ !!! tip "Catch-all"
284+ Add a * catch-all* route last as a fallback for any non-matching request, e.g. ` api_mock.route().respond(404) ` .
289285!!! note "NOTE"
290286 Named routes in a * reusable router* can be directly accessed via ` my_mock_router[<route name>] `
291287
You can’t perform that action at this time.
0 commit comments