feat: implement Fitbit OAuth, Garmin MFA, and optimize segment discovery
- 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)
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
from src.models.activity import Activity
|
||||
import os
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_discovery_by_garmin_id(db_session, client, tmp_path):
|
||||
"""
|
||||
Verify that the discovery API correctly finds an activity when passed its
|
||||
Garmin Activity ID (as an int/string) instead of the internal DB ID.
|
||||
"""
|
||||
# 1. Create Activity with a specific Garmin ID
|
||||
garmin_id = "9876543210" # Large ID
|
||||
activity = Activity(
|
||||
activity_name="Garmin Test Activity",
|
||||
garmin_activity_id=garmin_id,
|
||||
start_time="2023-05-20T10:00:00",
|
||||
activity_type="hiking",
|
||||
file_type="fit",
|
||||
file_content=b"dummy"
|
||||
)
|
||||
db_session.add(activity)
|
||||
db_session.commit()
|
||||
db_session.refresh(activity)
|
||||
|
||||
# Internal ID should be small (e.g. 1)
|
||||
print(f"DEBUG: Created Activity Internal ID: {activity.id}, Garmin ID: {activity.garmin_activity_id}")
|
||||
|
||||
# 2. Call Discovery Single API with the GARMIN ID
|
||||
payload = {
|
||||
"activity_id": int(garmin_id), # Passing the large ID
|
||||
"pause_threshold": 10,
|
||||
"rdp_epsilon": 10,
|
||||
"turn_threshold": 60,
|
||||
"min_length": 100
|
||||
}
|
||||
|
||||
response = client.post("/api/discovery/single", json=payload)
|
||||
|
||||
# Needs to be 200 OK
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
# 3. Assert analyzed_activity_type is 'hiking' (retrieved from DB via Garmin ID lookup)
|
||||
assert data['analyzed_activity_type'] == 'hiking'
|
||||
print("Success: API found activity via Garmin ID and returned type 'hiking'")
|
||||
Reference in New Issue
Block a user