- Add Fitbit authentication flow (save credentials, OAuth callback handling) - Implement Garmin MFA support with successful session/cookie handling - Optimize segment discovery with new sampling and activity query services - Refactor database session management in discovery API for better testability - Enhance activity data parsing for charts and analysis - Update tests to use testcontainers and proper dependency injection - Clean up repository by ignoring and removing tracked transient files (.pyc, .db)
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from fastapi.testclient import TestClient
|
|
from main import app
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
def test_single_discovery_endpoint(client):
|
|
# Mock the service
|
|
with patch('src.api.discovery.SegmentDiscoveryService') as MockService:
|
|
instance = MockService.return_value
|
|
|
|
# Mock analyze_single_activity return value
|
|
mock_cand = MagicMock()
|
|
mock_cand.points = [[10.0, 50.0], [10.1, 50.1]]
|
|
mock_cand.frequency = 1
|
|
mock_cand.distance = 1000.0
|
|
mock_cand.activity_ids = [123]
|
|
|
|
instance.analyze_single_activity.return_value = [mock_cand]
|
|
|
|
response = client.post("/api/discovery/single", json={
|
|
"activity_id": 123
|
|
})
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "candidates" in data
|
|
assert len(data["candidates"]) == 1
|
|
assert data["candidates"][0]["frequency"] == 1
|
|
assert data["candidates"][0]["distance"] == 1000.0
|
|
|
|
def test_single_discovery_not_found(client):
|
|
with patch('src.api.discovery.SegmentDiscoveryService') as MockService:
|
|
instance = MockService.return_value
|
|
instance.analyze_single_activity.return_value = []
|
|
|
|
response = client.post("/api/discovery/single", json={
|
|
"activity_id": 999
|
|
})
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert len(data["candidates"]) == 0
|