- C1: drop module-level app singleton in app/main.py so importing the package no longer validates Settings or creates DATA_DIR; run uvicorn with --factory in the Dockerfile. pytest now collects and passes with no ambient env vars. - I2: add missing app/auth, app/security, app/web __init__.py so setuptools discovers all five packages. - I3: resolve the Jinja2 template directory relative to __file__ instead of the process CWD. - I4: add .gitignore covering .env, data/, .venv/, caches and build artifacts so example deployment secrets cannot be committed. - I5: assert UserRepository.list_enabled() excludes disabled users. - M6: encode both operands before hmac.compare_digest in validate_csrf so a non-ASCII token yields 403 instead of an unhandled 500. - M9: remove unused relationship / HealthState imports. - M11: make session cookie https_only configurable via SESSION_HTTPS_ONLY (default unchanged: false). - M13: dispose SQLAlchemy engines in the db_session and client fixtures. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
from app.db.models import ActivityStatus, HealthState
|
|
|
|
|
|
def test_create_two_independent_users(db_session, user_repository) -> None:
|
|
first = user_repository.create(
|
|
name="Max",
|
|
enabled=True,
|
|
health_state=HealthState.HEALTHY,
|
|
mywhoosh_email_enc="mw-1",
|
|
mywhoosh_password_enc="mw-pw-1",
|
|
garmin_email_enc="g-1",
|
|
garmin_password_enc="g-pw-1",
|
|
)
|
|
second = user_repository.create(
|
|
name="Anna",
|
|
enabled=True,
|
|
health_state=HealthState.HEALTHY,
|
|
mywhoosh_email_enc="mw-2",
|
|
mywhoosh_password_enc="mw-pw-2",
|
|
garmin_email_enc="g-2",
|
|
garmin_password_enc="g-pw-2",
|
|
)
|
|
|
|
disabled = user_repository.create(
|
|
name="Paused",
|
|
enabled=False,
|
|
health_state=HealthState.DISABLED,
|
|
mywhoosh_email_enc="mw-3",
|
|
mywhoosh_password_enc="mw-pw-3",
|
|
garmin_email_enc="g-3",
|
|
garmin_password_enc="g-pw-3",
|
|
)
|
|
|
|
assert first.id != second.id
|
|
assert {u.name for u in user_repository.list_enabled()} == {"Max", "Anna"}
|
|
assert disabled.id not in {u.id for u in user_repository.list_enabled()}
|
|
assert {u.name for u in user_repository.list_all()} == {"Max", "Anna", "Paused"}
|
|
|
|
|
|
def test_activity_external_id_is_unique_per_user(user_repository, activity_repository) -> None:
|
|
user = user_repository.create(
|
|
name="Max",
|
|
enabled=True,
|
|
health_state=HealthState.HEALTHY,
|
|
mywhoosh_email_enc="a",
|
|
mywhoosh_password_enc="b",
|
|
garmin_email_enc="c",
|
|
garmin_password_enc="d",
|
|
)
|
|
created, inserted = activity_repository.get_or_create_discovered(
|
|
user_id=user.id,
|
|
mywhoosh_activity_id="mw-123",
|
|
activity_name="Morning Ride",
|
|
activity_timestamp=None,
|
|
)
|
|
same, inserted_again = activity_repository.get_or_create_discovered(
|
|
user_id=user.id,
|
|
mywhoosh_activity_id="mw-123",
|
|
activity_name="Morning Ride",
|
|
activity_timestamp=None,
|
|
)
|
|
|
|
assert inserted is True
|
|
assert inserted_again is False
|
|
assert created.id == same.id
|
|
assert same.status == ActivityStatus.DISCOVERED
|