Skip to content

Backend Testing ## Business Purpose Ensure backend reliability through unit and integration tests covering CRUD operations, authentication, and authorization. ## Current Behaviors - Fixtures: conftest.py:16-39 provides db, client, superuser_token_headers, normal_user_token_headers fixtures.

  • CRUD Tests: test_user.py (10 tests) covers user creation, authentication, hashing upgrades.
  • API Route Tests: test_login.py (9 tests), test_items.py (11 tests), test_users.py (27 tests), test_private.py (1 test).
  • Script Tests: test_backend_pre_start.py and test_test_pre_start.py test database connection initialization.
  • Pytest Configuration: Uses pytest.fixture decorator for DB session and client. ## Technical Implementation - Test Framework: pytest with conftest.py for shared fixtures.
  • Test Database: In-memory SQLite or test PostgreSQL via engine from backend_pre_start.py:22.
  • Fixtures: db fixture provides a session scoped per function; client fixture uses TestClient.
  • Authentication: Tokens generated via superuser_token_headers using security utilities.
  • Code Coverage: Tests cover success and failure paths for each endpoint. ## Definition of Done - All backend tests pass (pytest exit code 0).
  • Each CRUD operation has at least one happy path and one error path test.
  • Authentication tests include correct and incorrect password scenarios.
  • Permission tests ensure normal users cannot modify items or manage users.
  • Hashing algorithm upgrade from bcrypt to Argon2 is verified test_user.py:96.