zenith-backend / tests /unit /test_analytics_performance.py
teoat's picture
Upload folder using huggingface_hub
4ae946d verified
from unittest.mock import MagicMock
import pytest
from sqlalchemy.orm import Session
from app.modules.analytics.router import get_temporal_flow
@pytest.mark.asyncio
async def test_get_temporal_flow_limit():
# Mock DB session
mock_db = MagicMock(spec=Session)
# Mock result proxy
mock_result = MagicMock()
mock_result.__iter__.return_value = []
mock_db.execute.return_value = mock_result
# Call the function
await get_temporal_flow(days=30, limit=5000, db=mock_db)
# Verify db.execute was called
args, kwargs = mock_db.execute.call_args
query_obj = args[0]
query_params = args[1]
query_str = str(query_obj)
print(f"Executed query: {query_str}")
print(f"Query params: {query_params}")
# Assert LIMIT clause is present
assert "LIMIT :limit" in query_str, "Query should contain LIMIT clause"
# Assert parameters
assert query_params["limit"] == 5000, "Limit parameter should be passed correctly"
assert "cutoff_date" in query_params