- 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)
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
import pytest
|
|
from src.models.activity import Activity
|
|
from src.services.parsers import extract_activity_data
|
|
import os
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_discovery_returns_file_type_when_db_type_missing(db_session, client, tmp_path):
|
|
"""
|
|
Verify that the discovery API returns the activity type parsed from the file
|
|
even if the database record has activity_type=None.
|
|
"""
|
|
# 1. Create dummy FIT file content (minimal valid header/data or mock)
|
|
# Using a real file is better, or mocking extract_activity_data.
|
|
# Let's mock extract_activity_data to avoid needing a complex binary file.
|
|
|
|
from unittest.mock import patch
|
|
|
|
# Mock return value mimics a running activity
|
|
mock_parsed_data = {
|
|
'type': 'running',
|
|
'points': [[-122.4, 37.8], [-122.41, 37.81]], # Dummy points
|
|
'timestamps': []
|
|
}
|
|
|
|
with patch('src.api.discovery.extract_activity_data', return_value=mock_parsed_data) as mock_extract:
|
|
# 2. Create Activity in DB with type=None
|
|
activity = Activity(
|
|
activity_name="Test Activity",
|
|
garmin_activity_id="99999",
|
|
start_time="2023-01-01T10:00:00",
|
|
activity_type=None, # <--- MISSING TYPE
|
|
file_type="fit",
|
|
file_content=b"dummy_bytes"
|
|
)
|
|
db_session.add(activity)
|
|
db_session.commit()
|
|
db_session.refresh(activity)
|
|
|
|
# 3. Call Discovery Single API
|
|
payload = {
|
|
"activity_id": activity.id,
|
|
"pause_threshold": 10,
|
|
"rdp_epsilon": 10,
|
|
"turn_threshold": 60,
|
|
"min_length": 100
|
|
}
|
|
|
|
response = client.post("/api/discovery/single", json=payload)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
|
|
# 4. Assert analyzed_activity_type is 'running'
|
|
assert data['analyzed_activity_type'] == 'running'
|
|
print("Success: API returned inferred type 'running'")
|