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:
2026-01-16 15:35:26 -08:00
parent 45dbc32295
commit d1cfd0fd8e
217 changed files with 1795 additions and 922 deletions

View File

@@ -8,41 +8,7 @@ mock_scheduler_module = MagicMock()
mock_scheduler_module.scheduler = mock_scheduler
sys.modules["src.services.scheduler"] = mock_scheduler_module
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from src.models import Base, BikeSetup
from main import app
from src.utils.config import config
from src.api.bike_setups import get_db
# Use a separate test database or the existing test.db
SQLALCHEMY_DATABASE_URL = "sqlite:///./test_bike_setups.db"
engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def override_get_db():
try:
db = TestingSessionLocal()
yield db
finally:
db.close()
app.dependency_overrides[get_db] = override_get_db
@pytest.fixture(scope="module")
def test_db():
Base.metadata.create_all(bind=engine)
yield
Base.metadata.drop_all(bind=engine)
@pytest.fixture(scope="module")
def client(test_db):
with TestClient(app) as c:
yield c
# The client fixture is automatically imported from conftest.py
def test_create_bike_setup(client):
response = client.post(
@@ -56,16 +22,32 @@ def test_create_bike_setup(client):
assert "id" in data
def test_read_bike_setups(client):
# Create one first to ensure it exists (needed due to function scope isolation)
client.post(
"/api/bike-setups/",
json={"frame": "Read Test", "chainring": 50, "rear_cog": 11, "name": "Read Me"}
)
response = client.get("/api/bike-setups/")
assert response.status_code == 200
data = response.json()
# Depending on test isolation, checking >=1 is safe
assert len(data) >= 1
assert data[0]["frame"] == "Trek Emonda"
# We might need to filter to find the one we just made if parallel tests run,
# but for now sequential is fine.
found = False
for setup in data:
if setup.get("frame") == "Read Test":
found = True
break
assert found
def test_update_bike_setup(client):
# First get id
response = client.get("/api/bike-setups/")
setup_id = response.json()[0]["id"]
# Create one first to ensure it exists
setup = client.post(
"/api/bike-setups/",
json={"frame": "Update Target", "chainring": 50, "rear_cog": 11, "name": "To Update"}
).json()
setup_id = setup["id"]
response = client.put(
f"/api/bike-setups/{setup_id}",
@@ -74,12 +56,15 @@ def test_update_bike_setup(client):
assert response.status_code == 200
data = response.json()
assert data["chainring"] == 52
assert data["frame"] == "Trek Emonda"
assert data["frame"] == "Update Target"
def test_delete_bike_setup(client):
# First get id
response = client.get("/api/bike-setups/")
setup_id = response.json()[0]["id"]
# Create one to delete
setup = client.post(
"/api/bike-setups/",
json={"frame": "Delete Target", "chainring": 50, "rear_cog": 11, "name": "To Delete"}
).json()
setup_id = setup["id"]
response = client.delete(f"/api/bike-setups/{setup_id}")
assert response.status_code == 204