We should be able to use the test client with user defined headers. This is useful if we need to set custom headers for authentication during tests or in development.
()
| 68 | |
| 69 | |
| 70 | def test_testclient_headers_behavior() -> None: |
| 71 | """ |
| 72 | We should be able to use the test client with user defined headers. |
| 73 | |
| 74 | This is useful if we need to set custom headers for authentication |
| 75 | during tests or in development. |
| 76 | """ |
| 77 | |
| 78 | client = TestClient(mock_service) |
| 79 | assert client.headers.get("user-agent") == "testclient" |
| 80 | |
| 81 | client = TestClient(mock_service, headers={"user-agent": "non-default-agent"}) |
| 82 | assert client.headers.get("user-agent") == "non-default-agent" |
| 83 | |
| 84 | client = TestClient(mock_service, headers={"Authentication": "Bearer 123"}) |
| 85 | assert client.headers.get("user-agent") == "testclient" |
| 86 | assert client.headers.get("Authentication") == "Bearer 123" |
| 87 | |
| 88 | |
| 89 | def test_use_testclient_as_contextmanager(test_client_factory: TestClientFactory, anyio_backend_name: str) -> None: |
nothing calls this directly
no test coverage detected