From 64aaf2a06a211e9bcd04c9d7db9cbf28a3485a1d Mon Sep 17 00:00:00 2001 From: Donkie Date: Wed, 28 Jun 2023 20:44:22 +0200 Subject: [PATCH] 404 error is now more descriptive --- spoolman/api/v1/router.py | 2 +- tests_integration/tests/test_filament.py | 12 ++++++++++++ tests_integration/tests/test_spool.py | 16 ++++++++++++++++ tests_integration/tests/test_vendor.py | 12 ++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/spoolman/api/v1/router.py b/spoolman/api/v1/router.py index 0485292..0d1a898 100644 --- a/spoolman/api/v1/router.py +++ b/spoolman/api/v1/router.py @@ -28,7 +28,7 @@ async def itemnotfounderror_exception_handler(_request: Request, exc: ItemNotFou logger.debug(exc, exc_info=True) return JSONResponse( status_code=404, - content={"message": "Item not found."}, + content={"message": exc.args[0]}, ) diff --git a/tests_integration/tests/test_filament.py b/tests_integration/tests/test_filament.py index 607fcbc..01dc3f3 100644 --- a/tests_integration/tests/test_filament.py +++ b/tests_integration/tests/test_filament.py @@ -168,6 +168,10 @@ def test_get_filament_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "filament" in message + assert "id" in message + assert "123456789" in message def test_find_filaments(random_vendor: dict[str, Any]): @@ -333,6 +337,10 @@ def test_delete_filament_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "filament" in message + assert "id" in message + assert "123456789" in message def test_update_filament(random_vendor: dict[str, Any]): @@ -426,3 +434,7 @@ def test_update_filament_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "filament" in message + assert "id" in message + assert "123456789" in message diff --git a/tests_integration/tests/test_spool.py b/tests_integration/tests/test_spool.py index 17cf882..8272052 100644 --- a/tests_integration/tests/test_spool.py +++ b/tests_integration/tests/test_spool.py @@ -174,6 +174,10 @@ def test_get_spool_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "spool" in message + assert "id" in message + assert "123456789" in message def test_find_spools(random_filament: dict[str, Any]): # noqa: PLR0915 @@ -342,6 +346,10 @@ def test_delete_spool_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "spool" in message + assert "id" in message + assert "123456789" in message def test_update_spool(random_filament: dict[str, Any]): @@ -425,6 +433,10 @@ def test_update_spool_not_found(random_filament: dict[str, Any]): json={"filament_id": random_filament["id"]}, ) assert result.status_code == 404 + message = result.json()["message"].lower() + assert "spool" in message + assert "id" in message + assert "123456789" in message def test_use_spool_weight(random_filament: dict[str, Any]): @@ -526,3 +538,7 @@ def test_use_spool_not_found(): json={"use_weight": 0.05}, ) assert result.status_code == 404 + message = result.json()["message"].lower() + assert "spool" in message + assert "id" in message + assert "123456789" in message diff --git a/tests_integration/tests/test_vendor.py b/tests_integration/tests/test_vendor.py index 2b2706e..967f969 100644 --- a/tests_integration/tests/test_vendor.py +++ b/tests_integration/tests/test_vendor.py @@ -87,6 +87,10 @@ def test_get_vendor_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "vendor" in message + assert "id" in message + assert "123456789" in message def test_find_vendors(): @@ -182,6 +186,10 @@ def test_delete_vendor_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "vendor" in message + assert "id" in message + assert "123456789" in message def test_update_vendor(): @@ -223,3 +231,7 @@ def test_update_vendor_not_found(): # Verify assert result.status_code == 404 + message = result.json()["message"].lower() + assert "vendor" in message + assert "id" in message + assert "123456789" in message