MCPcopy
hub / github.com/encode/starlette / test_testclient_headers_behavior

Function test_testclient_headers_behavior

tests/test_testclient.py:70–86  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

68
69
70def 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
89def test_use_testclient_as_contextmanager(test_client_factory: TestClientFactory, anyio_backend_name: str) -> None:

Callers

nothing calls this directly

Calls 2

TestClientClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected