From 750412764a3aafb3517ef71919f02d459e917614 Mon Sep 17 00:00:00 2001 From: Jakub Miazek Date: Thu, 17 Oct 2024 16:35:44 +0200 Subject: [PATCH] wip --- tests/api/test_stuff.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/api/test_stuff.py b/tests/api/test_stuff.py index 2e66ab8..da6c028 100644 --- a/tests/api/test_stuff.py +++ b/tests/api/test_stuff.py @@ -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", (