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,72 @@
|
||||
|
||||
from src.models.activity import Activity
|
||||
import pytest
|
||||
|
||||
def test_repro_segment_wrong_type(client, db_session):
|
||||
"""
|
||||
Reproduction: Create a segment from a 'running' activity and verify it is not saved as 'cycling'.
|
||||
"""
|
||||
# 1. Setup a fake running activity in DB
|
||||
act_id = 999999999
|
||||
|
||||
# Dummy TCX
|
||||
dummy_tcx = """
|
||||
<TrainingCenterDatabase>
|
||||
<Activities>
|
||||
<Activity Sport="Running">
|
||||
<Id>2018-01-01T00:00:00Z</Id>
|
||||
<Lap StartTime="2018-01-01T00:00:00Z">
|
||||
<Track>
|
||||
<Trackpoint>
|
||||
<Time>2018-01-01T00:00:00Z</Time>
|
||||
<Position>
|
||||
<LatitudeDegrees>45.0</LatitudeDegrees>
|
||||
<LongitudeDegrees>-33.0</LongitudeDegrees>
|
||||
</Position>
|
||||
</Trackpoint>
|
||||
<Trackpoint>
|
||||
<Time>2018-01-01T00:00:10Z</Time>
|
||||
<Position>
|
||||
<LatitudeDegrees>45.01</LatitudeDegrees>
|
||||
<LongitudeDegrees>-33.01</LongitudeDegrees>
|
||||
</Position>
|
||||
</Trackpoint>
|
||||
</Track>
|
||||
</Lap>
|
||||
</Activity>
|
||||
</Activities>
|
||||
</TrainingCenterDatabase>
|
||||
"""
|
||||
|
||||
act = Activity(
|
||||
id=act_id,
|
||||
garmin_activity_id=str(act_id),
|
||||
activity_name="Test Run",
|
||||
activity_type="running", # Correct Type in DB
|
||||
file_content=dummy_tcx.encode('utf-8'),
|
||||
file_type="tcx"
|
||||
)
|
||||
db_session.add(act)
|
||||
db_session.commit()
|
||||
|
||||
# 2. Call Create Segment Endpoint
|
||||
payload = {
|
||||
"activity_id": act_id,
|
||||
"name": "Test Segment",
|
||||
"start_index": 0,
|
||||
"end_index": 1,
|
||||
"activity_type": "cycling" # Simulate Frontend forcing 'cycling'
|
||||
}
|
||||
|
||||
response = client.post("/api/segments/create", json=payload)
|
||||
assert response.status_code == 200, f"Response: {response.text}"
|
||||
|
||||
data = response.json()
|
||||
seg_id = data['id']
|
||||
from src.models.segment import Segment
|
||||
segment = db_session.query(Segment).filter(Segment.id == seg_id).first()
|
||||
|
||||
print(f"Created Segment Type: {segment.activity_type}")
|
||||
|
||||
# Assert it is running
|
||||
assert segment.activity_type == 'running'
|
||||
Reference in New Issue
Block a user