Skip to content

Commit

Permalink
fix e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Agustín Ramiro Díaz <[email protected]>
  • Loading branch information
AgustinRamiroDiaz committed Nov 6, 2024
1 parent b7bf073 commit 8814540
Showing 1 changed file with 30 additions and 46 deletions.
76 changes: 30 additions & 46 deletions tests/integration/test_llm_providers_registry.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
from tests.common.request import payload, post_request_localhost
from tests.common.response import has_success_status

# provider, model, plugin


def test_llm_providers():
providers_and_models_response = post_request_localhost(
payload("sim_getProvidersAndModels")
).json()
assert has_success_status(providers_and_models_response)
providers_and_models = providers_and_models_response["result"]

gpt4o_provider_id = next(
(
provider["id"]
for provider in providers_and_models
if provider["model"] == "gpt-4o"
and provider["provider"] == "openai"
and provider["plugin"] == "openai"
),
None,
)

# Delete it
response = post_request_localhost(
payload("sim_deleteProvider", gpt4o_provider_id)
).json()
assert has_success_status(response)

# Create it again
provider = {
"provider": "openai",
"model": "gpt-4",
"model": "gpt-4o",
"config": {},
"plugin": "openai",
"plugin_config": {"api_key_env_var": "OPENAIKEY", "api_url": None},
}
# Create a new provider
response = post_request_localhost(payload("sim_addProvider", provider)).json()
assert has_success_status(response)

Expand All @@ -23,56 +48,15 @@ def test_llm_providers():
"plugin": "openai",
"plugin_config": {"api_key_env_var": "OPENAIKEY", "api_url": None},
}
# Uodate it

# Update it
response = post_request_localhost(
payload("sim_updateProvider", provider_id, updated_provider)
).json()
assert has_success_status(response)

# Delete it
response = post_request_localhost(payload("sim_deleteProvider", provider_id)).json()
assert has_success_status(response)


def test_llm_providers_behavior():
"""
Test the behavior of LLM providers endpoints by performing the following steps:
1. Reset the default LLM providers.
2. Retrieve the list of providers and models.
3. Extract the first default provider and the ID of the last provider.
4. Add a new provider using the first default provider's data.
5. Update the last provider using the first default provider's data.
6. Delete the newly added provider.
"""
# Reset it
reset_result = post_request_localhost(
payload("sim_resetDefaultsLlmProviders")
).json()
assert has_success_status(reset_result)

response = post_request_localhost(payload("sim_getProvidersAndModels")).json()
assert has_success_status(response)

default_providers = response["result"]
first_default_provider: dict = default_providers[0]
del first_default_provider["id"]
last_provider_id = default_providers[-1]["id"]

# Create a new provider
response = post_request_localhost(
payload("sim_addProvider", first_default_provider)
).json()
assert has_success_status(response)

provider_id = response["result"]

# Uodate it
response = post_request_localhost(
payload("sim_updateProvider", last_provider_id, first_default_provider)
).json()
assert has_success_status(response)

# Delete it
response = post_request_localhost(payload("sim_deleteProvider", provider_id)).json()
assert has_success_status(response)

0 comments on commit 8814540

Please sign in to comment.