35 lines
904 B
Python
35 lines
904 B
Python
from collections.abc import Iterator
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from memrelay.app import create_app
|
|
from memrelay.config import Settings
|
|
|
|
|
|
@pytest.fixture
|
|
def client(tmp_path) -> Iterator[TestClient]:
|
|
settings = Settings(
|
|
data_dir=tmp_path / "data",
|
|
public_url="http://testserver",
|
|
initial_admin_username=None,
|
|
initial_admin_password=None,
|
|
)
|
|
app = create_app(settings)
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
|
|
|
|
@pytest.fixture
|
|
def initialized_client(client: TestClient) -> TestClient:
|
|
response = client.post(
|
|
"/api/v1/auth/initialize",
|
|
json={"username": "admin", "password": "strong-test-password"},
|
|
)
|
|
assert response.status_code == 201
|
|
return client
|
|
|
|
|
|
def csrf_headers(client: TestClient) -> dict[str, str]:
|
|
return {"X-CSRF-Token": client.cookies["memrelay_csrf"]}
|