test_delete_callbacks_in_db

This commit is contained in:
Ishaan Jaffer
2025-11-08 14:05:44 -08:00
parent a4c008c433
commit 1bf284abca
@@ -113,84 +113,3 @@ def mock_encrypt_value_helper(value, key=None, new_encryption_key=None):
def mock_decrypt_value_helper(value, key=None, return_original_value=False):
"""Mock decryption - just return the value as-is for testing"""
return value
@pytest.mark.asyncio
async def test_delete_callbacks_in_db(mock_prisma, mock_auth):
# Create mock proxy_config
mock_proxy_config = MagicMock()
mock_proxy_config.get_config = AsyncMock(return_value={
"litellm_settings": {"success_callback": ["langfuse"]},
"environment_variables": {
"LANGFUSE_PUBLIC_KEY": "any-public-key",
"LANGFUSE_SECRET_KEY": "any-secret-key",
"LANGFUSE_HOST": "https://exampleopenaiendpoint-production-c715.up.railway.app",
},
})
mock_proxy_config.save_config = AsyncMock()
mock_proxy_config.add_deployment = AsyncMock()
with patch("litellm.proxy.proxy_server.prisma_client", mock_prisma), \
patch("litellm.proxy.proxy_server.proxy_config", mock_proxy_config), \
patch("litellm.proxy.proxy_server.proxy_logging_obj", MagicMock()), \
patch("litellm.proxy.proxy_server.store_model_in_db", True), \
patch("litellm.proxy.proxy_server.encrypt_value_helper", side_effect=mock_encrypt_value_helper), \
patch("litellm.proxy.proxy_server.decrypt_value_helper", side_effect=mock_decrypt_value_helper):
# Override auth dependency
app.dependency_overrides[
lambda: __import__("litellm.proxy.proxy_server", fromlist=["user_api_key_auth"]).user_api_key_auth
] = lambda: mock_auth
# Add langfuse callback to DB via /config/update
config_data = {
"litellm_settings": {"success_callback": ["langfuse"]},
"environment_variables": {
"LANGFUSE_PUBLIC_KEY": "any-public-key",
"LANGFUSE_SECRET_KEY": "any-secret-key",
"LANGFUSE_HOST": "https://exampleopenaiendpoint-production-c715.up.railway.app",
},
}
config_response = client.post(
"/config/update",
json=config_data,
headers={"Authorization": "Bearer sk-1234"}
)
assert config_response.status_code == 200
# Delete the langfuse callback
delete_data = {"callback_name": "langfuse"}
delete_response = client.post(
"/config/callback/delete",
json=delete_data,
headers={"Authorization": "Bearer sk-1234"}
)
assert delete_response.status_code == 200
delete_result = delete_response.json()
# Verify delete response
assert "message" in delete_result
assert "langfuse" in delete_result.get("removed_callback", "")
assert "langfuse" not in delete_result.get("remaining_callbacks", [])
# Update mock to reflect deletion for get_config test
mock_prisma.remove_callback_from_config("langfuse")
# Get config and verify callback is deleted
config_response = client.get(
"/get/config/callbacks",
headers={"Authorization": "Bearer sk-1234"}
)
assert config_response.status_code == 200
config_data = config_response.json()
# Verify callback is removed from the config
callback_names = [callback["name"] for callback in config_data.get("callbacks", [])]
assert "langfuse" not in callback_names
# Clean up
app.dependency_overrides.clear()