many updates
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
31
FitnessSync/backend/tests/api/test_discovery.py
Normal file
31
FitnessSync/backend/tests/api/test_discovery.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_discovery_endpoint():
|
||||
# Mock the service to avoid DB calls
|
||||
with patch('src.api.discovery.SegmentDiscoveryService') as MockService:
|
||||
instance = MockService.return_value
|
||||
instance.discover_segments.return_value = ([], []) # Empty candidates, empty debug paths
|
||||
|
||||
|
||||
response = client.post("/api/discovery/segments", json={
|
||||
"activity_type": "cycling",
|
||||
"start_date": "2025-01-01T00:00:00"
|
||||
})
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "candidates" in data
|
||||
assert isinstance(data["candidates"], list)
|
||||
assert "debug_paths" in data
|
||||
assert isinstance(data["debug_paths"], list)
|
||||
|
||||
|
||||
def test_discovery_page_render():
|
||||
response = client.get("/discovery")
|
||||
assert response.status_code == 200
|
||||
assert "Segment Discovery" in response.text
|
||||
12
FitnessSync/backend/tests/api/test_frontend_assets.py
Normal file
12
FitnessSync/backend/tests/api/test_frontend_assets.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_discovery_page_assets():
|
||||
response = client.get("/discovery")
|
||||
assert response.status_code == 200
|
||||
assert "leaflet.js" in response.text
|
||||
assert "leaflet.css" in response.text
|
||||
assert "map" in response.text
|
||||
43
FitnessSync/backend/tests/api/test_single_discovery.py
Normal file
43
FitnessSync/backend/tests/api/test_single_discovery.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_single_discovery_endpoint():
|
||||
# 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():
|
||||
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
|
||||
Reference in New Issue
Block a user