import json import os import sys from pathlib import Path import pytest ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) os.environ["ATLAS_OWNER_PASSWORD"] = "owner-pass" @pytest.fixture() def client(tmp_path, monkeypatch): from fastapi.testclient import TestClient from server import db monkeypatch.setattr(db, "DB_PATH", tmp_path / "test.db") db._local.__dict__.clear() from server import app as app_module app_module._hits.clear() with TestClient(app_module.app) as c: yield c db._local.__dict__.clear() @pytest.fixture() def admin(client): r = client.post("/api/admin/login", json={"username": "professor", "password": "owner-pass"}) assert r.status_code == 200 return client @pytest.fixture(scope="session") def atlas(): return json.loads((ROOT / "data" / "atlas.json").read_text()) @pytest.fixture() def owner(client): r = client.post("/api/admin/login", json={"username": "professor", "password": "owner-pass"}) assert r.status_code == 200 and r.json()["role"] == "owner" return client