"""Test fixtures.""" from __future__ import annotations import json import pytest from fastapi.testclient import TestClient from app.config import Settings from app.main import create_app CANONICAL_SID = "main" @pytest.fixture def sample_pool(): return { "title": "Sample Quiz", "score_fn": "linear_decay", "time_limit_default": 2, "session_id": CANONICAL_SID, "questions": [ { "id": "q1", "text": "First question?", "options": {"A": "Alpha", "B": "Beta", "C": "Gamma", "D": "Delta"}, "correct": "B", "time_limit": 2, "explanation": "B is correct.", }, { "id": "q2", "text": "Second question?", "options": {"A": "One", "B": "Two", "C": "Three", "D": "Four"}, "correct": "C", "time_limit": 2, }, { "id": "q3", "text": "Third question?", "options": {"A": "Red", "B": "Blue", "C": "Green", "D": "Gold"}, "correct": "A", "time_limit": 2, }, { "id": "q4", "text": "Fourth question?", "options": {"A": "North", "B": "South", "C": "East", "D": "West"}, "correct": "D", "time_limit": 2, }, { "id": "q5", "text": "Fifth question?", "options": {"A": "Fetch", "B": "Decode", "C": "Execute", "D": "Write"}, "correct": "A", "time_limit": 1, }, ], } @pytest.fixture def client(tmp_path, sample_pool): pool_path = tmp_path / "pool.json" pool_path.write_text(json.dumps(sample_pool)) settings = Settings( db_path=str(tmp_path / "quiz.db"), secret_key="test-secret", admin_password="admin-pass", public_url="http://testserver", pool_path=str(pool_path), default_session_id=CANONICAL_SID, ) app = create_app(settings) with TestClient(app) as test_client: yield test_client @pytest.fixture def sid() -> str: return CANONICAL_SID def admin_login(client: TestClient) -> None: response = client.post("/admin/login", json={"password": "admin-pass"}) assert response.status_code == 200, response.text def join_student(client: TestClient, sid: str, student_id: str = "s1", name: str = "Student One") -> dict: response = client.post(f"/api/session/{sid}/join", json={"student_id": student_id, "name": name}) assert response.status_code == 200, response.text return response.json()