diff --git a/app/utils/decorators.py b/app/utils/decorators.py index f3a6f59..dd37bb5 100644 --- a/app/utils/decorators.py +++ b/app/utils/decorators.py @@ -1,5 +1,4 @@ from sqlalchemy.dialects import postgresql -from sqlalchemy.ext.asyncio import AsyncSession from functools import wraps diff --git a/tests/api/test_stuff.py b/tests/api/test_stuff.py index da6c028..577eb26 100644 --- a/tests/api/test_stuff.py +++ b/tests/api/test_stuff.py @@ -5,118 +5,73 @@ 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()) + stuff = StuffFactory.build(factory_use_constructors=True).model_dump(mode="json") + response = await client.post("/stuff", json=stuff) assert response.status_code == status.HTTP_201_CREATED - - assert response.json() == snapshot( { "id": IsUUID(4), - "name": _stuff["name"], - "description": _stuff["description"], + "name": stuff["name"], + "description": stuff["description"], } ) -@pytest.mark.parametrize( - "payload, status_code", - ( - ( - {"name": "motorhead-0", "description": "we play rock and roll"}, - status.HTTP_200_OK, - ), - ), -) -async def test_get_stuff(client: AsyncClient, payload: dict, status_code: int): - await client.post("/stuff", json=payload) - name = payload["name"] +async def test_get_stuff(client: AsyncClient): + stuff = StuffFactory.build(factory_use_constructors=True).model_dump(mode="json") + await client.post("/stuff", json=stuff) + name = stuff["name"] response = await client.get(f"/stuff/{name}") - assert response.status_code == status_code + assert response.status_code == status.HTTP_200_OK assert response.json() == snapshot( { "id": IsUUID(4), - "name": "motorhead-0", - "description": "we play rock and roll", + "name": stuff["name"], + "description": stuff["description"], } ) - - - -@pytest.mark.parametrize( - "payload, status_code", - ( - ( - {"name": "motorhead-1", "description": "we play rock and roll"}, - status.HTTP_200_OK, - ), - ), -) -async def test_delete_stuff(client: AsyncClient, payload: dict, status_code: int): - response = await client.post("/stuff", json=payload) - name = response.json()["name"] +async def test_delete_stuff(client: AsyncClient): + stuff = StuffFactory.build(factory_use_constructors=True).model_dump(mode="json") + await client.post("/stuff", json=stuff) + name = stuff["name"] response = await client.delete(f"/stuff/{name}") - assert response.status_code == status_code + assert response.status_code == status.HTTP_200_OK assert response.json() == snapshot(True) -@pytest.mark.parametrize( - "payload, status_code", - ( - ( - {"name": "motorhead-2", "description": "we play rock and roll"}, - status.HTTP_200_OK, - ), - ), -) -@pytest.mark.parametrize( - "patch_payload, patch_status_code", - ( - ( - {"name": "motorhead-2", "description": "we play loud"}, - status.HTTP_200_OK, - ), - ), -) -async def test_update_stuff( - client: AsyncClient, - payload: dict, - status_code: int, - patch_payload: dict, - patch_status_code: int, -): - response = await client.post("/stuff", json=payload) +async def test_update_stuff(client: AsyncClient): + stuff = StuffFactory.build(factory_use_constructors=True).model_dump(mode="json") + response = await client.post("/stuff", json=stuff) assert response.json() == snapshot( { "id": IsUUID(4), - "name": "motorhead-2", - "description": "we play rock and roll", + "name": stuff["name"], + "description": stuff["description"], } ) - name = payload["name"] - response = await client.patch(f"/stuff/{name}", json=patch_payload) + name = stuff["name"] + response = await client.patch( + f"/stuff/{name}", + json={"name": stuff["name"], "description": "we play rock and roll"}, + ) assert response.json() == snapshot( { "id": IsUUID(4), - "name": "motorhead-2", - "description": "we play loud", + "name": stuff["name"], + "description": "we play rock and roll", } ) - assert response.status_code == patch_status_code + assert response.status_code == status.HTTP_200_OK