litellm/tests/unit/proxy/test_unit_test_proxy_hooks.py
mrinal-berri cb200a83cc
feat(proxy)!: make Scalar the default API reference and remove ReDoc (#53063)
* feat(proxy): serve Scalar as the default API reference

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): keep Scalar assets on the gateway

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): register the Scalar endpoint explicitly

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): validate the Scalar request root path

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): keep Swagger and ReDoc alongside Scalar

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* style(proxy): format the Swagger renderer

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* feat(proxy): use Scalar for control plane API docs

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): preserve control plane docs tracing exclusions

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(proxy): prioritize API viewer routes over static assets

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(control-plane): skip tracing API reference assets

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(control-plane): trace API requests outside docs asset mounts

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore: mark vendored Scalar bundle as generated

* fix(proxy): serve API viewers from the split backend

* fix(proxy): satisfy docs routing and bundle lint checks

* docs(proxy): explain why FastAPI docs are disabled

* docs(proxy): clarify API viewer registration order

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-23 10:49:54 -08:00

43 lines
1.4 KiB
Python

import asyncio
from unittest.mock import Mock, patch, AsyncMock
import pytest
from fastapi import Request
from datetime import datetime
import litellm
@pytest.mark.asyncio
async def test_disable_spend_logs():
"""
With disable_spend_logs the request is queued only for its charge, flagged so no SpendLogs row is written
"""
# Mock the necessary components
mock_prisma_client = Mock()
mock_prisma_client.spend_log_transactions = []
# Add lock for spend_log_transactions (matches real PrismaClient)
mock_prisma_client._spend_log_transactions_lock = asyncio.Lock()
with (
patch("litellm.proxy.proxy_server.disable_spend_logs", True),
patch("litellm.proxy.proxy_server.prisma_client", mock_prisma_client),
):
from litellm.proxy.db.db_spend_update_writer import DBSpendUpdateWriter
db_spend_update_writer = DBSpendUpdateWriter()
# Call update_database with disable_spend_logs=True
await db_spend_update_writer.update_database(
token="fake-token",
response_cost=0.1,
user_id="user123",
completion_response=None,
start_time=datetime.now(),
end_time=datetime.now(),
end_user_id="end_user_id",
team_id="team_id",
org_id="org_id",
kwargs={},
)
assert [row["accounting_log_disabled"] for row in mock_prisma_client.spend_log_transactions] == [True]