Skip to content

Conversation

@naasanov
Copy link
Collaborator

@naasanov naasanov commented Dec 27, 2025

Refactored tests to use utils instead of hardcoding values. Reduced test line count by half (10k -> 5k)

Changes:

  • Made util classes for all resources to consolidate repeated logic
    • Added from_model and to_model as required functions for default impl of utils.
    • This required adding/moving functions to some entities missing them
      • Moved hash_ and verify_ password to a utils file instead of part of police service for police entity
  • Other utilities
    • http/assertions.py
      • Configurable assertions for response success, failure, validation failure, and pagination
    • http/test_templates.py
      • Test template for route authentication tests, checking that allowed roles can access, disallowed roles are forbidden, and unauthed gets unauthorized
      • geo.py
        • Utils for converting miles to latitude and staying consistent with the set search radius env var
  • Changes to conftest
    • Shared client fixtures
    • Shared service fixtures
    • Shared util fixtures
  • Fixed issues unearthed by test refactor
    • Police mock authentication was not returning right in some cases
    • Several dates missing timezone information
    • Place details did not add unit information
    • Party update did not update contact two correctly
    • Party router create did not have 201 status
    • Exception handler did not persist HTTPException headers

Extras:

  • Made all entities derive from MappedAsDataclass to have better constructor typing
    • Required a fix in reset_dev to satisfy constructor
  • QOL dev changes
    • Small formatting change to increase line length
    • npm i instead of npm ci in post_create.sh to not have to install from clean every container rebuild

Closes #118

@naasanov naasanov changed the title Test refactor Backend Test Refactor Dec 27, 2025
@github-actions
Copy link

github-actions bot commented Dec 27, 2025

Test Results Summary

286 tests   - 61   286 ✅  - 61   9s ⏱️ -1s
  1 suites ± 0     0 💤 ± 0 
  1 files   ± 0     0 ❌ ± 0 

Results for commit 57e94c3. ± Comparison against base commit 4b50976.

This pull request removes 347 and adds 286 tests. Note that renamed tests count towards both.
test.modules.account.account_router_test ‑ test_create_account_admin
test.modules.account.account_router_test ‑ test_create_account_duplicate_email
test.modules.account.account_router_test ‑ test_create_account_invalid_email
test.modules.account.account_router_test ‑ test_create_account_invalid_pid_non_numeric
test.modules.account.account_router_test ‑ test_create_account_invalid_pid_too_long
test.modules.account.account_router_test ‑ test_create_account_invalid_pid_too_short
test.modules.account.account_router_test ‑ test_create_account_staff
test.modules.account.account_router_test ‑ test_create_account_student
test.modules.account.account_router_test ‑ test_create_account_unauthenticated
test.modules.account.account_router_test ‑ test_delete_account
…
test.modules.account.account_router_test ‑ test_account_authentication[allowed_roles0-GET-/api/accounts-None]
test.modules.account.account_router_test ‑ test_account_authentication[allowed_roles1-POST-/api/accounts-body1]
test.modules.account.account_router_test ‑ test_account_authentication[allowed_roles2-PUT-/api/accounts/12345-body2]
test.modules.account.account_router_test ‑ test_account_authentication[allowed_roles3-DELETE-/api/accounts/12345-None]
test.modules.account.account_router_test ‑ test_account_authentication[allowed_roles4-GET-/api/accounts/police-None]
test.modules.account.account_router_test ‑ test_account_authentication[allowed_roles5-PUT-/api/accounts/police-body5]
test.modules.account.account_router_test.TestAccountRouter ‑ test_create_account[AccountRole.ADMIN]
test.modules.account.account_router_test.TestAccountRouter ‑ test_create_account[AccountRole.STAFF]
test.modules.account.account_router_test.TestAccountRouter ‑ test_create_account[AccountRole.STUDENT]
test.modules.account.account_router_test.TestAccountRouter ‑ test_create_account_duplicate_email
…

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@manyuagashe manyuagashe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback was conducted in detail over certain logical issues and typing problems over Slack. No more feedback for PR, LGTM, approved.

@manyuagashe manyuagashe merged commit e23a979 into main Jan 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend Test Refactor

3 participants