This commit is contained in:
Jakub Miazek 2024-10-17 16:35:44 +02:00
parent b18f150b6b
commit 750412764a

View File

@ -4,27 +4,32 @@ from httpx import AsyncClient
from inline_snapshot import snapshot
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
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(
{
"id": IsUUID(4),
"name": "motorhead",
"description": "we play rock and roll",
"name": _stuff["name"],
"description": _stuff["description"],
}
)
@ -52,6 +57,9 @@ async def test_get_stuff(client: AsyncClient, payload: dict, status_code: int):
)
@pytest.mark.parametrize(
"payload, status_code",
(