MCPcopy
hub / github.com/openai/openai-python / test_basic_auth

Function test_basic_auth

tests/test_auth.py:20–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18
19@respx.mock
20def test_basic_auth():
21 respx.post("https://auth.openai.com/oauth/token").mock(
22 return_value=httpx.Response(
23 200,
24 json={
25 "access_token": "fake_access_token",
26 "issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
27 "token_type": "Bearer",
28 "expires_in": 3600,
29 },
30 )
31 )
32
33 respx.get("https://api.openai.com/v1/models").mock(
34 return_value=httpx.Response(200, json={"data": [], "object": "list"})
35 )
36
37 client = OpenAI(
38 workload_identity={
39 "identity_provider_id": "idp_123",
40 "service_account_id": "sa_123",
41 "provider": {
42 "get_token": lambda: "fake_subject_token",
43 "token_type": "jwt",
44 },
45 },
46 )
47
48 client.models.list()
49
50 assert len(respx.calls) == 2
51 token_call = cast(Call, respx.calls[0])
52 api_call = cast(Call, respx.calls[1])
53
54 assert token_call.request.url == "https://auth.openai.com/oauth/token"
55 assert api_call.request.headers.get("Authorization") == "Bearer fake_access_token"
56
57
58@respx.mock

Callers

nothing calls this directly

Calls 4

OpenAIClass · 0.90
postMethod · 0.45
getMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected