This commit is contained in:
willbird1936-dev 2026-09-29 00:31:22 +01:00 • committed by GitHub
commit 87287aac09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 125 additions and 1 deletions

View file

@ -345,6 +345,8 @@ async def new_tag(
"message": f"Tag {tag.name} created successfully",
"tag": tag_config,
}
except HTTPException:
raise
except Exception as e:
verbose_proxy_logger.exception("Error creating tag: %s", e)
raise HTTPException(status_code=500, detail=str(e))
@ -478,6 +480,8 @@ async def update_tag(
"message": f"Tag {tag.name} updated successfully",
"tag": tag_config,
}
except HTTPException:
raise
except Exception as e:
verbose_proxy_logger.exception("Error updating tag: %s", e)
raise HTTPException(status_code=500, detail=str(e))
@ -544,6 +548,8 @@ async def info_tag(
requested_tags[tag_record.tag_name] = tag_dict
return requested_tags
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@ -715,6 +721,8 @@ async def delete_tag(
await _evict_tag_cache_keys((tag_cache_key(data.name), tag_registry_cache_key()))
return {"message": f"Tag {data.name} deleted successfully"}
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

View file

@ -16,7 +16,12 @@ from unittest.mock import AsyncMock, Mock, patch
import litellm
from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth
from litellm.proxy.proxy_server import app
from litellm.types.tag_management import TagDeleteRequest, TagInfoRequest, TagNewRequest
from litellm.types.tag_management import (
TagDeleteRequest,
TagInfoRequest,
TagNewRequest,
TagUpdateRequest,
)
client = TestClient(app)
@ -638,6 +643,117 @@ async def test_delete_tag_invalidates_tag_and_registry_caches():
app.dependency_overrides.clear()
@pytest.mark.asyncio
async def test_new_tag_duplicate_returns_400_not_500():
from unittest.mock import AsyncMock, Mock
from litellm.proxy.management_endpoints.tag_management_endpoints import new_tag
mock_user_auth = UserAPIKeyAuth(
user_id="test-user-123",
user_role=LitellmUserRoles.PROXY_ADMIN,
)
with (
patch("litellm.proxy.proxy_server.prisma_client") as mock_prisma,
patch("litellm.proxy.proxy_server.llm_router", Mock()),
):
mock_db = Mock()
mock_prisma.db = mock_db
mock_db.litellm_tagtable.find_unique = AsyncMock(return_value=Mock())
with pytest.raises(HTTPException) as exc_info:
await new_tag(
tag=TagNewRequest(name="existing-tag"),
user_api_key_dict=mock_user_auth,
)
assert exc_info.value.status_code == 400
assert "already exists" in exc_info.value.detail
@pytest.mark.asyncio
async def test_update_tag_missing_returns_404_not_500():
from unittest.mock import AsyncMock, Mock
from litellm.proxy.management_endpoints.tag_management_endpoints import (
update_tag,
)
mock_user_auth = UserAPIKeyAuth(
user_id="test-user-123",
user_role=LitellmUserRoles.PROXY_ADMIN,
)
with patch("litellm.proxy.proxy_server.prisma_client") as mock_prisma:
mock_db = Mock()
mock_prisma.db = mock_db
mock_db.litellm_tagtable.find_unique = AsyncMock(return_value=None)
with pytest.raises(HTTPException) as exc_info:
await update_tag(
tag=TagUpdateRequest(name="missing-tag"),
user_api_key_dict=mock_user_auth,
)
assert exc_info.value.status_code == 404
assert "not found" in exc_info.value.detail
@pytest.mark.asyncio
async def test_info_tag_missing_returns_404_not_500():
from unittest.mock import AsyncMock, Mock
from litellm.proxy.management_endpoints.tag_management_endpoints import info_tag
mock_user_auth = UserAPIKeyAuth(
user_id="test-user-123",
user_role=LitellmUserRoles.PROXY_ADMIN,
)
with patch("litellm.proxy.proxy_server.prisma_client") as mock_prisma:
mock_db = Mock()
mock_prisma.db = mock_db
mock_db.litellm_tagtable.find_many = AsyncMock(return_value=[])
with pytest.raises(HTTPException) as exc_info:
await info_tag(
data=TagInfoRequest(names=["missing-tag"]),
user_api_key_dict=mock_user_auth,
)
assert exc_info.value.status_code == 404
assert "not found" in exc_info.value.detail
@pytest.mark.asyncio
async def test_delete_tag_missing_returns_404_not_500():
from unittest.mock import AsyncMock, Mock
from litellm.proxy.management_endpoints.tag_management_endpoints import (
delete_tag,
)
mock_user_auth = UserAPIKeyAuth(
user_id="test-user-123",
user_role=LitellmUserRoles.PROXY_ADMIN,
)
with patch("litellm.proxy.proxy_server.prisma_client") as mock_prisma:
mock_db = Mock()
mock_prisma.db = mock_db
mock_db.litellm_tagtable.find_unique = AsyncMock(return_value=None)
with pytest.raises(HTTPException) as exc_info:
await delete_tag(
data=TagDeleteRequest(name="missing-tag"),
user_api_key_dict=mock_user_auth,
)
assert exc_info.value.status_code == 404
assert "not found" in exc_info.value.detail
@pytest.mark.asyncio
async def test_list_tags_with_dynamic_tags():
"""