many updates
This commit is contained in:
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