mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-03 07:23:33 +00:00
test(integration): repair agent reads and bulk deletion setup (#49719)
(cherry picked from commit 0ea7e96a66)
This commit is contained in:
parent
5352ed94fb
commit
835a3fa12e
2 changed files with 12 additions and 15 deletions
|
|
@ -5,12 +5,14 @@ from typing import Final
|
|||
from integration._support.client import Gateway, Scenario
|
||||
from integration._support.database import read_rows
|
||||
from integration._support.wire import Reply, Request, wire_server
|
||||
from pydantic import BaseModel, JsonValue
|
||||
from pydantic import BaseModel, ConfigDict, JsonValue
|
||||
|
||||
_REDACTED: Final = "REDACTED_BY_LITELM"
|
||||
|
||||
|
||||
class _AgentRead(BaseModel):
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
||||
agent_id: str
|
||||
agent_name: str
|
||||
litellm_params: dict[str, JsonValue] | None
|
||||
|
|
@ -84,7 +86,8 @@ def test_agent_reads_redact_credentials_filter_by_key_permission_and_keep_the_st
|
|||
visible: Final = _register_agent(gateway, scenario, marker + "-visible", wire.url, secret)
|
||||
hidden: Final = _register_agent(gateway, scenario, marker + "-hidden", wire.url, secret)
|
||||
restricted: Final = scenario.key(object_permission={"agents": [visible]})
|
||||
redacted_params: Final = {"api_key": _REDACTED, "cost_per_query": 0.1, "is_public": False}
|
||||
stored_params: Final = {"api_key": _REDACTED, "cost_per_query": 0.1}
|
||||
redacted_params: Final = {**stored_params, "is_public": False}
|
||||
|
||||
listed: Final = gateway.client.get("/v1/agents", headers={"Authorization": f"Bearer {restricted}"})
|
||||
assert listed.status_code == 200, listed.text
|
||||
|
|
@ -98,9 +101,8 @@ def test_agent_reads_redact_credentials_filter_by_key_permission_and_keep_the_st
|
|||
assert fetched.status_code == 200, fetched.text
|
||||
assert secret not in fetched.text, fetched.text
|
||||
read: Final = _AgentRead.model_validate_json(fetched.content)
|
||||
assert (read.agent_id, read.litellm_params, read.static_headers) == (visible, redacted_params, None), (
|
||||
fetched.text
|
||||
)
|
||||
assert (read.agent_id, read.static_headers) == (visible, None), fetched.text
|
||||
assert read.litellm_params in (stored_params, redacted_params), fetched.text
|
||||
|
||||
refused: Final = gateway.client.get(f"/v1/agents/{hidden}", headers={"Authorization": f"Bearer {restricted}"})
|
||||
assert (refused.status_code, refused.json()) == (
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import yaml
|
|||
from pydantic import JsonValue
|
||||
from redis import Redis
|
||||
|
||||
from litellm.constants import TEAM_DELETE_TRANSACTION_TIMEOUT_SECONDS
|
||||
from tests.integration._support.client import (
|
||||
Gateway,
|
||||
Scenario,
|
||||
|
|
@ -159,19 +160,11 @@ def _remove_team_by_sql(team_id: str) -> None:
|
|||
assert _team_rows(team_id) == []
|
||||
|
||||
|
||||
def _remove_team_if_present(gateway: Gateway, team_id: str) -> None:
|
||||
"""Cleanup for teams the test deletes itself: the API delete first, SQL for anything it leaves."""
|
||||
if not _team_rows(team_id):
|
||||
return
|
||||
gateway.request("POST", "/team/delete", {"team_ids": [team_id]})
|
||||
_remove_team_by_sql(team_id)
|
||||
|
||||
|
||||
def _create_team(scenario: Scenario, **fields: JsonValue) -> str:
|
||||
"""A team the test deletes itself; cleanup only removes it if the test left it behind."""
|
||||
created: Final = scenario.gateway.post("/team/new", {"team_alias": f"integration-{uuid.uuid4().hex}", **fields})
|
||||
team_id: Final = string_value(created["team_id"])
|
||||
scenario.cleanups.callback(_remove_team_if_present, scenario.gateway, team_id)
|
||||
scenario.cleanups.callback(_remove_team_by_sql, team_id)
|
||||
return team_id
|
||||
|
||||
|
||||
|
|
@ -741,7 +734,9 @@ def test_deleting_a_team_with_more_keys_than_the_publish_cap_revokes_every_key_o
|
|||
keys: Final = _seeded_team_keys(team, KEYS_WELL_PAST_THE_PUBLISH_CAP)
|
||||
assert _statuses(peer, keys) == {200: len(keys)}
|
||||
|
||||
response: Final = _delete_teams(gateway, [team])
|
||||
response: Final = _post_with_timeout(
|
||||
gateway, "/team/delete", {"team_ids": [team]}, timeout=2 * TEAM_DELETE_TRANSACTION_TIMEOUT_SECONDS
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
assert read_rows('SELECT token FROM "LiteLLM_VerificationToken" WHERE team_id = %s', (team,)) == []
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue