mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
wip
This commit is contained in:
parent
b18f150b6b
commit
750412764a
@ -4,27 +4,32 @@ from httpx import AsyncClient
|
|||||||
from inline_snapshot import snapshot
|
from inline_snapshot import snapshot
|
||||||
from dirty_equals import IsUUID
|
from dirty_equals import IsUUID
|
||||||
|
|
||||||
|
from polyfactory.factories.pydantic_factory import ModelFactory
|
||||||
|
from polyfactory.pytest_plugin import register_fixture
|
||||||
|
|
||||||
|
from app.schemas.stuff import StuffSchema
|
||||||
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.anyio
|
pytestmark = pytest.mark.anyio
|
||||||
|
|
||||||
|
class StuffFactory(ModelFactory[StuffSchema]):
|
||||||
|
__model__ = StuffSchema
|
||||||
|
|
||||||
|
|
||||||
|
async def test_add_stuff(client: AsyncClient):
|
||||||
|
|
||||||
|
_stuff = StuffFactory.build(factory_use_constructors=True).model_dump(mode="json")[0],
|
||||||
|
|
||||||
|
response = await client.post("/stuff", json=_stuff)
|
||||||
|
print(response.json())
|
||||||
|
assert response.status_code == status.HTTP_201_CREATED
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"payload, status_code",
|
|
||||||
(
|
|
||||||
(
|
|
||||||
{"name": "motorhead", "description": "we play rock and roll"},
|
|
||||||
status.HTTP_201_CREATED,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
async def test_add_stuff(client: AsyncClient, payload: dict, status_code: int):
|
|
||||||
response = await client.post("/stuff", json=payload)
|
|
||||||
assert response.status_code == status_code
|
|
||||||
assert response.json() == snapshot(
|
assert response.json() == snapshot(
|
||||||
{
|
{
|
||||||
"id": IsUUID(4),
|
"id": IsUUID(4),
|
||||||
"name": "motorhead",
|
"name": _stuff["name"],
|
||||||
"description": "we play rock and roll",
|
"description": _stuff["description"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,6 +57,9 @@ async def test_get_stuff(client: AsyncClient, payload: dict, status_code: int):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"payload, status_code",
|
"payload, status_code",
|
||||||
(
|
(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user