Skip to content

Latest commit

 

History

History
105 lines (78 loc) · 3.07 KB

File metadata and controls

105 lines (78 loc) · 3.07 KB

Testing Guide

Prerequisites

Make sure Docker Compose is running:

docker compose up

The test database (studyclever_test) is created automatically on first run. If it doesn't exist:

docker compose exec postgres psql -U postgres -c "CREATE DATABASE studyclever_test;"

Running Tests

Run all tests

docker compose exec backend pytest tests/ -v

Run a specific test file

docker compose exec backend pytest tests/test_schedule_generator.py -v
docker compose exec backend pytest tests/test_queue_service.py -v
docker compose exec backend pytest tests/test_auth.py -v

Run a specific test class

docker compose exec backend pytest tests/test_schedule_generator.py::TestEasingInDistribution -v

Run a single test

docker compose exec backend pytest tests/test_schedule_generator.py::TestEasingInDistribution::test_sum_matches_total -v

Run with short traceback

docker compose exec backend pytest tests/ -v --tb=short

Run only failing tests (re-run last failures)

docker compose exec backend pytest tests/ --lf

Test Structure

backend/tests/
├── test_auth.py                  # Registration, login, JWT
├── test_modules.py               # Module + lecture CRUD
├── test_schedule_config.py       # Schedule config validation
├── test_schedule_generator.py    # Distribution algorithms, two-phase, progress
├── test_queue_service.py         # Daily queue, answers, timers, study ahead
├── test_familiarization.py       # One-per-slide selection, skip handling
├── test_progress.py              # Progress tracking, streaks
├── test_flags.py                 # Question flagging
├── test_regeneration.py          # Deck system, fam survival
├── test_enrichment.py            # Enrichment service (existing)
├── test_batch_manager.py         # Batch manager (existing)
├── test_e2e_flow.py              # Full end-to-end happy path
└── __init__.py

Shared Fixtures (conftest.py)

Available fixtures in all test files:

Fixture Description
db Transactional database session (rolls back after each test)
client FastAPI TestClient with test DB
test_user A registered user
auth_headers JWT auth headers for test_user
test_module Module with future exam date
test_lectures 3 lectures with 5 slides each
test_questions 4 questions per slide (60 total)
test_schedule_config Default schedule config

Adding New Tests

  1. Create a new file in backend/tests/ named test_<feature>.py
  2. Use fixtures from conftest.py — they're auto-discovered
  3. Group related tests in classes (e.g., class TestMyFeature:)
  4. Each test gets a fresh database transaction that rolls back

Example:

def test_my_feature(db, test_user, test_module, test_questions, test_schedule_config):
    from app.services.my_service import do_something
    result = do_something(test_module.id, test_user.id, db)
    assert result.count > 0