Testing
See issue 81 for more examples.
test_example.py
import pytest
from httpx import AsyncClient
from demo_project.api.dependencies import azure_scheme
from fastapi import Request
from fastapi_azure_auth.user import User
from demo_project.main import app as fastapi_app
@pytest.fixture
async def normal_user_client():
async def mock_normal_user(request: Request):
user = User(
claims={},
preferred_username="NormalUser",
roles=["role1"],
aud="aud",
tid="tid",
access_token="123",
is_guest=False,
iat=1537231048,
nbf=1537231048,
exp=1537234948,
iss="iss",
aio="aio",
sub="sub",
oid="oid",
uti="uti",
rh="rh",
ver="2.0",
)
request.state.user = user
return user
fastapi_app.dependency_overrides[azure_scheme] = mock_normal_user
async with AsyncClient(app=fastapi_app, base_url='http://test') as ac:
yield ac