feat: publish CodexPi contest snapshot
Some checks are pending
Qualité / tests (push) Waiting to run
Some checks are pending
Qualité / tests (push) Waiting to run
This commit is contained in:
51
tests/conftest.py
Normal file
51
tests/conftest.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "backend"))
|
||||
|
||||
from codexpi.config import Settings
|
||||
from codexpi.main import create_app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app_env(tmp_path: Path):
|
||||
projects = tmp_path / "projects"
|
||||
projects.mkdir()
|
||||
forbidden = projects / "forbidden"
|
||||
forbidden.mkdir()
|
||||
data = tmp_path / "data"
|
||||
data.mkdir()
|
||||
settings = Settings(
|
||||
base_dir=ROOT,
|
||||
data_dir=data,
|
||||
database_path=data / "test.db",
|
||||
host="127.0.0.1",
|
||||
port=8765,
|
||||
cookie_name="codexpi_test",
|
||||
cookie_secure=False,
|
||||
session_hours=1,
|
||||
allowed_roots=(projects,),
|
||||
forbidden_roots=(forbidden,),
|
||||
codex_bin="definitely-missing-codex",
|
||||
frontend_dist=tmp_path / "missing-dist",
|
||||
trusted_origins=("http://testserver",),
|
||||
)
|
||||
app = create_app(settings)
|
||||
with TestClient(app) as client:
|
||||
app.state.auth.create_user("admin", "a-very-long-test-password")
|
||||
yield client, app, projects, forbidden
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logged_in(app_env):
|
||||
client, app, projects, forbidden = app_env
|
||||
response = client.post("/api/auth/login", json={"username": "admin", "password": "a-very-long-test-password"})
|
||||
assert response.status_code == 200
|
||||
csrf = response.json()["csrf_token"]
|
||||
return client, app, projects, forbidden, {"X-CSRF-Token": csrf}
|
||||
Reference in New Issue
Block a user