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 = """ 2018-01-01T00:00:00Z 45.0 -33.0 45.01 -33.01 """ 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'