Files
allmende-payment-system/test/conftest.py
2025-10-23 11:41:52 +02:00

31 lines
860 B
Python

import pytest
from fastapi import Request
from fastapi.testclient import TestClient
from allmende_payment_system.app import create_app
@pytest.fixture(scope="session")
def client():
app = create_app()
async def add_ynh_headers(request: Request, call_next):
username = request.headers.get("APS-TEST-username", "test")
# This seems to work although headers are immutable
# If this ever turns out to be a problem, we can use request.state instead,
# but will have to modify app.get_user
request.headers._list.append((b"ynh_user", username.encode("utf-8")))
response = await call_next(request)
return response
app.middleware("http")(add_ynh_headers)
return TestClient(app)
@pytest.fixture(scope="session")
def unauthorized_client():
app = create_app()
return TestClient(app)