mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-18 06:42:51 +08:00

* WIP: add rbac authorization * Perform pre-commit fixes * add rbac route whitelist * add init test data user role associations * Restore database table id naming to fix generic crud base * Add database section value uniqueness settings * Update the test directory to tests * Update route_name file name to health_check * Split user auth and user action interfaces * Fix conflict between merge and current branch * Add pymysql dependencies * Fix RBAC authentication method * Add the select serialisation tool * Fix missing return messages due to global exception handler slicing * Update the user interface with associated relationships * Add items to be completed * Perform pre-commit fixes * Add pre-made routers * Paging data return structure optimisation * Split user auth and user interface tests * Fix user register test data structure error * Fix duplicate named test classes
32 lines
981 B
Python
32 lines
981 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import sys
|
|
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
sys.path.append('../../')
|
|
|
|
from backend.app.common.redis import redis_client # noqa: E402
|
|
from backend.app.core.conf import settings # noqa: E402
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
def anyio_backend():
|
|
return 'asyncio'
|
|
|
|
|
|
@pytest.fixture(scope='package', autouse=True)
|
|
async def function_fixture(anyio_backend):
|
|
auth_data = {
|
|
'url': f'http://{settings.UVICORN_HOST}:{settings.UVICORN_PORT}/v1/auth/users/login',
|
|
'headers': {'accept': 'application/json', 'Content-Type': 'application/json'},
|
|
'json': {'username': 'test', 'password': 'test'},
|
|
}
|
|
async with AsyncClient() as client:
|
|
response = await client.post(**auth_data)
|
|
token = response.json()['data']['access_token']
|
|
test_token = await redis_client.get('test_token')
|
|
if not test_token:
|
|
await redis_client.set('test_token', token, ex=86400)
|