mirror of
https://github.com/sstent/FitTrack_ReportGenerator.git
synced 2026-01-26 17:12:28 +00:00
sync
This commit is contained in:
Binary file not shown.
Binary file not shown.
66
tests/integration/test_centraldb_integration.py
Normal file
66
tests/integration/test_centraldb_integration.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import pytest
|
||||
import httpx
|
||||
from fastapi.testclient import TestClient
|
||||
from unittest.mock import patch, AsyncMock
|
||||
from api.main import app
|
||||
from uuid import uuid4
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_summary_new_analysis():
|
||||
activity_id = uuid4()
|
||||
|
||||
with patch("src.clients.centraldb_client.CentralDBClient") as MockCentralDBClient:
|
||||
mock_client = MockCentralDBClient.return_value
|
||||
# Mock the case where the artifact is not in CentralDB
|
||||
mock_client.get_analysis_artifact = AsyncMock(
|
||||
side_effect=httpx.HTTPStatusError(
|
||||
"", request=None, response=httpx.Response(status_code=404)
|
||||
)
|
||||
)
|
||||
mock_client.download_fit_file = AsyncMock(return_value=b"fit file content")
|
||||
mock_client.create_analysis_artifact = AsyncMock(
|
||||
return_value={
|
||||
"id": 1,
|
||||
"activity_id": str(activity_id),
|
||||
"data": {"summary": "metrics"},
|
||||
}
|
||||
)
|
||||
|
||||
with patch("src.core.file_parser.FitParser.parse") as mock_parse:
|
||||
# Mock the workout data object that the parser would return
|
||||
mock_workout_data = "mock workout data"
|
||||
mock_parse.return_value = mock_workout_data
|
||||
|
||||
with patch(
|
||||
"src.core.workout_analyzer.WorkoutAnalyzer"
|
||||
) as MockWorkoutAnalyzer:
|
||||
mock_analyzer = MockWorkoutAnalyzer.return_value
|
||||
summary_metrics = {
|
||||
"average_power": 200,
|
||||
"normalized_power": 220,
|
||||
"intensity_factor": 0.8,
|
||||
"training_stress_score": 50,
|
||||
"average_heart_rate": 150,
|
||||
"max_heart_rate": 180,
|
||||
"average_speed": 25,
|
||||
"max_speed": 50,
|
||||
"total_ascent": 100,
|
||||
"total_descent": 50,
|
||||
}
|
||||
mock_analyzer.calculate_summary_metrics.return_value = summary_metrics
|
||||
|
||||
response = client.get(f"/api/analysis/{activity_id}/summary")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json() == summary_metrics
|
||||
|
||||
# Verify that the client methods were called as expected
|
||||
mock_client.get_analysis_artifact.assert_called_once_with(str(activity_id))
|
||||
mock_client.download_fit_file.assert_called_once_with(str(activity_id))
|
||||
mock_client.create_analysis_artifact.assert_called_once_with(
|
||||
str(activity_id), data=summary_metrics
|
||||
)
|
||||
MockWorkoutAnalyzer.assert_called_once_with(mock_workout_data)
|
||||
Reference in New Issue
Block a user