Skip to content

Commit

Permalink
test(OpenAIClient): add tests for ensure_client_credentials & endpoin…
Browse files Browse the repository at this point in the history
…t_manager
  • Loading branch information
atomiechen committed Sep 16, 2024
1 parent b9a83fe commit 05a18d6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def test_ensure_client_credentials():
client.chat(messages=[], api_key="should_not_be_used").api_key == "client_key"
)


def test_ensure_client_credentials2():
client2 = OpenAIClient(ensure_client_credentials=True, api_key="client_key")
assert (
client2.chat(messages=[], api_key="should_not_be_used").api_key == "client_key"
Expand All @@ -162,3 +164,36 @@ def test_ensure_client_credentials():
assert (
client2.chat(messages=[], api_key="should_be_used").api_key == "should_be_used"
)


def test_ensure_client_credentials3():
client3 = OpenAIClient(
ensure_client_credentials=True,
endpoints=[
{
"api_key": "client_key1",
},
{
"api_key": "client_key2",
},
{
"api_key": "client_key3",
},
],
)
assert (
client3.chat(messages=[], api_key="should_not_be_used").api_key == "client_key1"
)
assert (
client3.chat(messages=[], api_key="should_not_be_used").api_key == "client_key2"
)
assert (
client3.chat(messages=[], api_key="should_not_be_used").api_key == "client_key3"
)
assert (
client3.chat(messages=[], api_key="should_not_be_used").api_key == "client_key1"
)
client3.ensure_client_credentials = False
assert (
client3.chat(messages=[], api_key="should_be_used").api_key == "should_be_used"
)

0 comments on commit 05a18d6

Please sign in to comment.