We should be able to use the test client within applications. This is useful if we need to mock out other services, during tests or in development.
(test_client_factory: TestClientFactory)
| 48 | |
| 49 | |
| 50 | def test_use_testclient_in_endpoint(test_client_factory: TestClientFactory) -> None: |
| 51 | """ |
| 52 | We should be able to use the test client within applications. |
| 53 | |
| 54 | This is useful if we need to mock out other services, |
| 55 | during tests or in development. |
| 56 | """ |
| 57 | |
| 58 | def homepage(request: Request) -> JSONResponse: |
| 59 | client = test_client_factory(mock_service) |
| 60 | response = client.get("/") |
| 61 | return JSONResponse(response.json()) |
| 62 | |
| 63 | app = Starlette(routes=[Route("/", endpoint=homepage)]) |
| 64 | |
| 65 | client = test_client_factory(app) |
| 66 | response = client.get("/") |
| 67 | assert response.json() == {"mock": "example"} |
| 68 | |
| 69 | |
| 70 | def test_testclient_headers_behavior() -> None: |
nothing calls this directly
no test coverage detected