TestClient does not support auth param #2336
Answered
by
Kludex
mshober
asked this question in
Potential Issue
-
Related to #1914.
from starlette.testclient import TestClient
import httpx
class ApiClient:
_client_class: type[httpx.Client] = httpx.Client
def __init__(self) -> None:
self._client = self._client_class(auth=self._auth_flow)
@property
def _credentials(self) -> str:
return "REAL_CREDENTIALS"
def _auth_flow(self, request: httpx.Request) -> httpx.Request:
request.headers["Authorization"] = self._credentials
return request
...
class FakeApiClient(ApiClient):
_client_class = TestClient
@property
def _credentials(self) -> str:
return "FAKE_CREDENTIALS"
fake_client = FakeApiClient() # TypeError: TestClient.__init__() got an unexpected keyword argument 'auth' Any reason why that can't be added to |
Beta Was this translation helpful? Give feedback.
Answered by
Kludex
Jan 14, 2024
Replies: 2 comments 1 reply
-
This can be done with the |
Beta Was this translation helpful? Give feedback.
1 reply
-
PR welcome. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PR welcome.