Fix CI test failures in invite-coach tests #27

Merged
forgejo_admin merged 1 commit from fix/25-ci-test-failures into main 2026-03-10 03:59:20 +00:00

Summary

  • Fixes 3 failing tests in tests/test_admin.py added by PR #24 (invite-coach feature)
  • Root cause: the invite-coach auth tests use the bare client fixture (no require_admin override), exposing two bugs the generate-tokens tests never hit

Changes

  • tests/conftest.py: Set app.state.auth_config in the client fixture so pal-e-auth's require_role() can run properly and return clean 401/403 instead of 500 "Auth not configured". The admin_client fixture never hit this because it overrides require_admin entirely; the client fixture lets the real auth dependency run, which needs auth_config on app.state (normally set by the lifespan, which TestClient doesn't trigger outside a context manager).
  • tests/test_admin.py: Fix naive-vs-aware datetime comparison in test_creates_coach_and_returns_invite. The Coach.invite_expires_at column uses DateTime (no timezone), so SQLAlchemy strips tzinfo on storage. The endpoint's .isoformat() returns a naive string, fromisoformat() parses it as naive, but the test compared against datetime.now(timezone.utc) (aware). Fixed by matching tzinfo awareness before comparing.

Test Plan

  • All 70 tests pass in CI (Postgres service container)
  • ruff check + format clean
  • No regressions in existing generate-tokens or coach onboarding tests

Review Checklist

  • Passed automated review-fix loop
  • No secrets committed
  • No unnecessary file changes
  • Commit messages are descriptive
  • Fixes #25
  • plan-2026-03-08-tryout-prep -- CI fix for invite-coach tests blocking deploy
## Summary - Fixes 3 failing tests in `tests/test_admin.py` added by PR #24 (invite-coach feature) - Root cause: the invite-coach auth tests use the bare `client` fixture (no `require_admin` override), exposing two bugs the generate-tokens tests never hit ## Changes - `tests/conftest.py`: Set `app.state.auth_config` in the `client` fixture so pal-e-auth's `require_role()` can run properly and return clean 401/403 instead of 500 "Auth not configured". The `admin_client` fixture never hit this because it overrides `require_admin` entirely; the `client` fixture lets the real auth dependency run, which needs `auth_config` on `app.state` (normally set by the lifespan, which TestClient doesn't trigger outside a context manager). - `tests/test_admin.py`: Fix naive-vs-aware datetime comparison in `test_creates_coach_and_returns_invite`. The `Coach.invite_expires_at` column uses `DateTime` (no timezone), so SQLAlchemy strips tzinfo on storage. The endpoint's `.isoformat()` returns a naive string, `fromisoformat()` parses it as naive, but the test compared against `datetime.now(timezone.utc)` (aware). Fixed by matching tzinfo awareness before comparing. ## Test Plan - [ ] All 70 tests pass in CI (Postgres service container) - [ ] ruff check + format clean - [ ] No regressions in existing generate-tokens or coach onboarding tests ## Review Checklist - [ ] Passed automated review-fix loop - [ ] No secrets committed - [ ] No unnecessary file changes - [ ] Commit messages are descriptive ## Related - Fixes #25 - `plan-2026-03-08-tryout-prep` -- CI fix for invite-coach tests blocking deploy
Fix CI test failures in invite-coach tests
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
3c33250166
1. Timezone comparison: The test compared a naive datetime (from
   fromisoformat on a DB-stored TIMESTAMP without tz) to an aware
   datetime (datetime.now(timezone.utc)). Fixed by matching tzinfo
   awareness before comparing.

2. Auth 500 errors: The `client` fixture didn't set app.state.auth_config,
   so pal-e-auth's require_role() crashed with 500 "Auth not configured"
   instead of returning clean 401/403. Fixed by setting auth_config in
   the client fixture, matching how the lifespan sets it for real requests.

Fixes #25

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
forgejo_admin deleted branch fix/25-ci-test-failures 2026-03-10 03:59:20 +00:00
Sign in to join this conversation.
No description provided.