40 lines
1,023 B
Python
40 lines
1,023 B
Python
"""Shared fixtures for m2-ledger tests: isolated sqlite conn + TestClient."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from m2_ledger import auth, models
|
|
from m2_ledger.api import app
|
|
|
|
SERVICE_KEY = "test-service-key"
|
|
ADMIN_KEY = "test-admin-key"
|
|
|
|
|
|
@pytest.fixture
|
|
def conn(tmp_path):
|
|
connection = models.init_db(str(tmp_path / "ledger.sqlite3"))
|
|
yield connection
|
|
connection.close()
|
|
|
|
|
|
@pytest.fixture
|
|
def client(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("LEDGER_DB_PATH", str(tmp_path / "ledger_api.sqlite3"))
|
|
monkeypatch.setenv("LEDGER_SERVICE_KEYS", SERVICE_KEY)
|
|
monkeypatch.setenv("LEDGER_ADMIN_KEYS", ADMIN_KEY)
|
|
auth._service_keys.cache_clear()
|
|
auth._admin_keys.cache_clear()
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
auth._service_keys.cache_clear()
|
|
auth._admin_keys.cache_clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def service_headers():
|
|
return {"X-API-Key": SERVICE_KEY}
|
|
|
|
|
|
@pytest.fixture
|
|
def admin_headers():
|
|
return {"X-API-Key": ADMIN_KEY}
|