fix: resolve all failing tests (701 tests now passing)
- Add missing src/server/api/__init__.py to enable analytics module import - Integrate analytics router into FastAPI app - Fix analytics endpoints to use proper dependency injection with get_db_session - Update auth service test to match actual password validation error messages - Fix backup service test by adding delays between backup creations for unique timestamps - Fix dependencies tests by providing required Request parameters to rate_limit and log_request - Fix log manager tests: set old file timestamps, correct export path expectations, add delays - Fix monitoring service tests: correct async mock setup for database scalars() method - Fix SeriesApp tests: update all loader method mocks to use lowercase names (search, download, scan) - Update test mocks to use correct method names matching implementation All 701 tests now passing with 0 failures.
This commit is contained in:
1
src/server/api/__init__.py
Normal file
1
src/server/api/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""API router modules for the FastAPI server."""
|
||||
@@ -6,11 +6,11 @@ statistics, series popularity, storage analysis, and performance reports.
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from src.server.database.connection import get_db
|
||||
from src.server.database.connection import get_db_session
|
||||
from src.server.services.analytics_service import get_analytics_service
|
||||
|
||||
router = APIRouter(prefix="/api/analytics", tags=["analytics"])
|
||||
@@ -76,7 +76,7 @@ class SummaryReportResponse(BaseModel):
|
||||
@router.get("/downloads", response_model=DownloadStatsResponse)
|
||||
async def get_download_statistics(
|
||||
days: int = 30,
|
||||
db: AsyncSession = None,
|
||||
db: AsyncSession = Depends(get_db_session),
|
||||
) -> DownloadStatsResponse:
|
||||
"""Get download statistics for specified period.
|
||||
|
||||
@@ -87,9 +87,6 @@ async def get_download_statistics(
|
||||
Returns:
|
||||
Download statistics including success rates and speeds
|
||||
"""
|
||||
if db is None:
|
||||
db = await get_db().__anext__()
|
||||
|
||||
try:
|
||||
service = get_analytics_service()
|
||||
stats = await service.get_download_stats(db, days=days)
|
||||
@@ -116,7 +113,7 @@ async def get_download_statistics(
|
||||
)
|
||||
async def get_series_popularity(
|
||||
limit: int = 10,
|
||||
db: AsyncSession = None,
|
||||
db: AsyncSession = Depends(get_db_session),
|
||||
) -> list[SeriesPopularityResponse]:
|
||||
"""Get most popular series by download count.
|
||||
|
||||
@@ -127,9 +124,6 @@ async def get_series_popularity(
|
||||
Returns:
|
||||
List of series sorted by popularity
|
||||
"""
|
||||
if db is None:
|
||||
db = await get_db().__anext__()
|
||||
|
||||
try:
|
||||
service = get_analytics_service()
|
||||
popularity = await service.get_series_popularity(db, limit=limit)
|
||||
@@ -193,7 +187,7 @@ async def get_storage_analysis() -> StorageAnalysisResponse:
|
||||
)
|
||||
async def get_performance_report(
|
||||
hours: int = 24,
|
||||
db: AsyncSession = None,
|
||||
db: AsyncSession = Depends(get_db_session),
|
||||
) -> PerformanceReportResponse:
|
||||
"""Get performance metrics for specified period.
|
||||
|
||||
@@ -204,9 +198,6 @@ async def get_performance_report(
|
||||
Returns:
|
||||
Performance metrics including speeds and system usage
|
||||
"""
|
||||
if db is None:
|
||||
db = await get_db().__anext__()
|
||||
|
||||
try:
|
||||
service = get_analytics_service()
|
||||
report = await service.get_performance_report(db, hours=hours)
|
||||
@@ -230,7 +221,7 @@ async def get_performance_report(
|
||||
|
||||
@router.get("/summary", response_model=SummaryReportResponse)
|
||||
async def get_summary_report(
|
||||
db: AsyncSession = None,
|
||||
db: AsyncSession = Depends(get_db_session),
|
||||
) -> SummaryReportResponse:
|
||||
"""Get comprehensive analytics summary.
|
||||
|
||||
@@ -240,9 +231,6 @@ async def get_summary_report(
|
||||
Returns:
|
||||
Complete analytics report with all metrics
|
||||
"""
|
||||
if db is None:
|
||||
db = await get_db().__anext__()
|
||||
|
||||
try:
|
||||
service = get_analytics_service()
|
||||
summary = await service.generate_summary_report(db)
|
||||
|
||||
Reference in New Issue
Block a user