mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
add uni tests for user auth
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from httpx import AsyncClient
|
||||
|
||||
from app.database import engine
|
||||
from app.main import app
|
||||
from app.models.base import Base
|
||||
from app.redis import get_redis
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
scope="session",
|
||||
params=[
|
||||
pytest.param(("asyncio", {"use_uvloop": True}), id="asyncio+uvloop"),
|
||||
]
|
||||
@@ -16,6 +17,7 @@ def anyio_backend(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
async def start_db():
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
@@ -25,15 +27,12 @@ async def start_db():
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def client() -> AsyncClient:
|
||||
@pytest.fixture(scope="session")
|
||||
async def client(start_db) -> AsyncClient:
|
||||
async with AsyncClient(
|
||||
app=app,
|
||||
base_url="http://testserver/v1",
|
||||
headers={"Content-Type": "application/json"},
|
||||
) as client:
|
||||
await start_db()
|
||||
yield client
|
||||
# for AsyncEngine created in function scope, close and
|
||||
# clean-up pooled connections
|
||||
await engine.dispose()
|
||||
) as test_client:
|
||||
app.state.redis = await get_redis()
|
||||
yield test_client
|
||||
|
||||
Reference in New Issue
Block a user