refactor: update test fixtures and remove unused environment variables

This commit is contained in:
grillazz
2026-01-03 19:04:07 +01:00
parent 88a66b1d92
commit e9ea2c627a
5 changed files with 42 additions and 15 deletions

View File

@@ -4,8 +4,10 @@ from fastapi import status
from httpx import AsyncClient
from inline_snapshot import snapshot
from polyfactory.factories.pydantic_factory import ModelFactory
from sqlalchemy.ext.asyncio import AsyncSession
from app.schemas.stuff import StuffSchema
from app.models import Stuff
pytestmark = pytest.mark.anyio
@@ -14,7 +16,7 @@ class StuffFactory(ModelFactory[StuffSchema]):
__model__ = StuffSchema
async def test_add_stuff(client: AsyncClient):
async def test_add_stuff(client: AsyncClient, db_session: AsyncSession):
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
@@ -32,22 +34,27 @@ async def test_add_stuff(client: AsyncClient):
)
async def test_get_stuff(client: AsyncClient):
async def test_get_stuff(client: AsyncClient, db_session: AsyncSession):
response = await client.get("/stuff/nonexistent")
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.json() == snapshot(
{"no_response": "The requested resource was not found"}
)
stuff = StuffFactory.build(factory_use_constructors=True).model_dump(mode="json")
await client.post("/stuff", json=stuff)
name = stuff["name"]
# await client.post("/stuff", json=stuff)
# name = stuff["name"]
stuff = Stuff(**stuff)
name = stuff.name
db_session.add(stuff)
await db_session.commit()
response = await client.get(f"/stuff/{name}")
assert response.status_code == status.HTTP_200_OK
assert response.json() == snapshot(
{
"id": IsUUID(4),
"name": stuff["name"],
"description": stuff["description"],
"name": stuff.name,
"description": stuff.description,
}
)