add simple exception handlers tests

This commit is contained in:
grillazz 2025-08-24 09:41:55 +02:00
parent 7d122f7062
commit 71d90aa1e3
2 changed files with 6 additions and 0 deletions

View File

View File

@ -25,9 +25,15 @@ async def test_add_stuff(client: AsyncClient):
"description": stuff["description"], "description": stuff["description"],
} }
) )
response = await client.post("/stuff", json=stuff)
assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
assert response.json() == snapshot({'message':'A database error occurred. Please try again later.'})
async def test_get_stuff(client: AsyncClient): async def test_get_stuff(client: AsyncClient):
response = await client.get(f"/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") stuff = StuffFactory.build(factory_use_constructors=True).model_dump(mode="json")
await client.post("/stuff", json=stuff) await client.post("/stuff", json=stuff)
name = stuff["name"] name = stuff["name"]