remove part 2

This commit is contained in:
2025-10-30 20:11:38 +01:00
parent 4649cf562d
commit fd76be02fd
8 changed files with 138 additions and 1260 deletions

View File

@@ -1,154 +0,0 @@
"""Integration tests for analytics API endpoints.
Tests analytics API endpoints including download statistics,
series popularity, storage analysis, and performance reports.
"""
from unittest.mock import AsyncMock, patch
import pytest
from httpx import ASGITransport, AsyncClient
from src.server.fastapi_app import app
@pytest.mark.asyncio
async def test_analytics_downloads_endpoint():
"""Test GET /api/analytics/downloads endpoint."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("src.server.api.analytics.get_db_session") as mock_get_db:
mock_db = AsyncMock()
mock_get_db.return_value = mock_db
response = await client.get("/api/analytics/downloads?days=30")
assert response.status_code in [200, 422, 500]
@pytest.mark.asyncio
async def test_analytics_series_popularity_endpoint():
"""Test GET /api/analytics/series-popularity endpoint."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("src.server.api.analytics.get_db_session") as mock_get_db:
mock_db = AsyncMock()
mock_get_db.return_value = mock_db
response = await client.get(
"/api/analytics/series-popularity?limit=10"
)
assert response.status_code in [200, 422, 500]
@pytest.mark.asyncio
async def test_analytics_storage_endpoint():
"""Test GET /api/analytics/storage endpoint."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("psutil.disk_usage") as mock_disk:
mock_disk.return_value = {
"total": 1024 * 1024 * 1024,
"used": 512 * 1024 * 1024,
"free": 512 * 1024 * 1024,
"percent": 50.0,
}
response = await client.get("/api/analytics/storage")
assert response.status_code in [200, 401, 500]
@pytest.mark.asyncio
async def test_analytics_performance_endpoint():
"""Test GET /api/analytics/performance endpoint."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("src.server.api.analytics.get_db_session") as mock_get_db:
mock_db = AsyncMock()
mock_get_db.return_value = mock_db
response = await client.get(
"/api/analytics/performance?hours=24"
)
assert response.status_code in [200, 422, 500]
@pytest.mark.asyncio
async def test_analytics_summary_endpoint():
"""Test GET /api/analytics/summary endpoint."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("src.server.api.analytics.get_db_session") as mock_get_db:
mock_db = AsyncMock()
mock_get_db.return_value = mock_db
response = await client.get("/api/analytics/summary")
assert response.status_code in [200, 500]
@pytest.mark.asyncio
async def test_analytics_downloads_with_query_params():
"""Test /api/analytics/downloads with different query params."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("src.server.api.analytics.get_db_session") as mock_get_db:
mock_db = AsyncMock()
mock_get_db.return_value = mock_db
response = await client.get("/api/analytics/downloads?days=7")
assert response.status_code in [200, 422, 500]
@pytest.mark.asyncio
async def test_analytics_series_with_different_limits():
"""Test /api/analytics/series-popularity with different limits."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("src.server.api.analytics.get_db_session") as mock_get_db:
mock_db = AsyncMock()
mock_get_db.return_value = mock_db
for limit in [5, 10, 20]:
response = await client.get(
f"/api/analytics/series-popularity?limit={limit}"
)
assert response.status_code in [200, 422, 500]
@pytest.mark.asyncio
async def test_analytics_performance_with_different_hours():
"""Test /api/analytics/performance with different hour ranges."""
transport = ASGITransport(app=app)
async with AsyncClient(
transport=transport, base_url="http://test"
) as client:
with patch("src.server.api.analytics.get_db_session") as mock_get_db:
mock_db = AsyncMock()
mock_get_db.return_value = mock_db
for hours in [1, 12, 24, 72]:
response = await client.get(
f"/api/analytics/performance?hours={hours}"
)
assert response.status_code in [200, 422, 500]