from pytest import fixture, mark from sqlalchemy import text pytestmark = [mark.asyncio, mark.sqlalchemy("1.4"), mark.require_asyncpg] @fixture(autouse=True) def setup(environ): from fastapi_sqla.asyncio_support import startup startup() yield async def test_startup_configure_async_session(): from fastapi_sqla.asyncio_support import _AsyncSession, startup startup() async with _AsyncSession() as session: res = await session.execute(text("SELECT 123")) assert res.scalar() == 123 async def test_open_async_session(): from fastapi_sqla.asyncio_support import open_session async with open_session() as session: res = await session.execute(text("select 123"))
from pytest import fixture, mark from sqlalchemy import text pytestmark = [mark.asyncio, mark.sqlalchemy("1.4")] @fixture(autouse=True) def setup(environ): from fastapi_sqla.asyncio_support import startup startup() yield async def test_startup_configure_async_session(): from fastapi_sqla.asyncio_support import _AsyncSession, startup startup() async with _AsyncSession() as session: res = await session.execute(text("SELECT 123")) assert res.scalar() == 123 async def test_open_async_session(): from fastapi_sqla.asyncio_support import open_session async with open_session() as session: res = await session.execute(text("select 123"))
@fixture async def client(app): async with LifespanManager(app): async with httpx.AsyncClient( app=app, base_url="http://example.local") as client: yield client @mark.asyncio @mark.parametrize( "offset,items_number,path", [ param(0, 10, "/v1/users"), param(10, 10, "/v1/users"), param(40, 2, "/v1/users"), param(0, 10, "/v2/users", marks=mark.sqlalchemy("1.4")), param(10, 10, "/v2/users", marks=mark.sqlalchemy("1.4")), param(40, 2, "/v2/users", marks=mark.sqlalchemy("1.4")), param(0, 10, "/v2/custom/users", marks=mark.sqlalchemy("1.4")), param(10, 10, "/v2/custom/users", marks=mark.sqlalchemy("1.4")), param(40, 2, "/v2/custom/users", marks=mark.sqlalchemy("1.4")), ], ) async def test_functional(client, offset, items_number, path): result = await client.get(path, params={"offset": offset}) assert result.status_code == 200, result.json() users = result.json()["data"] assert len(users) == items_number user_ids = [u["id"] for u in users] assert user_ids == list(range(offset + 1, offset + 1 + items_number))
@fixture async def client(app): async with LifespanManager(app): async with httpx.AsyncClient( app=app, base_url="http://example.local") as client: yield client @mark.asyncio @mark.parametrize( "offset,items_number,path", [ param(0, 10, "/v1/users"), param(10, 10, "/v1/users"), param(40, 2, "/v1/users"), param(0, 10, "/v2/users", marks=mark.sqlalchemy("1.4")), param(10, 10, "/v2/users", marks=mark.sqlalchemy("1.4")), param(40, 2, "/v2/users", marks=mark.sqlalchemy("1.4")), param( 0, 10, "/v2/users-with-notes-count", marks=mark.sqlalchemy("1.4")), param( 10, 10, "/v2/users-with-notes-count", marks=mark.sqlalchemy("1.4")), param( 40, 2, "/v2/users-with-notes-count", marks=mark.sqlalchemy("1.4")), ], ) async def test_functional(client, offset, items_number, path): result = await client.get(path, params={"offset": offset}) assert result.status_code == 200, result.json()