From c8519507014c03e711bb7815c20cf251ac6396ff Mon Sep 17 00:00:00 2001 From: Donkie Date: Thu, 23 May 2024 20:13:51 +0200 Subject: [PATCH] Tests fully pass again --- spoolman/api/v1/field.py | 5 ++++- spoolman/api/v1/vendor.py | 2 +- tests_integration/tests/conftest.py | 6 ++++++ tests_integration/tests/fields/test_utilize.py | 5 ++--- tests_integration/tests/setting/test_set.py | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spoolman/api/v1/field.py b/spoolman/api/v1/field.py index 9efcba7..cbb393a 100644 --- a/spoolman/api/v1/field.py +++ b/spoolman/api/v1/field.py @@ -59,7 +59,10 @@ async def update( key: Annotated[str, Path(min_length=1, max_length=64, regex="^[a-z0-9_]+$")], body: ExtraFieldParameters, ) -> Union[list[ExtraField], JSONResponse]: - body_with_key = ExtraField.parse_obj(body.copy(update={"key": key, "entity_type": entity_type})) + dict_body = body.model_dump() + dict_body["key"] = key + dict_body["entity_type"] = entity_type + body_with_key = ExtraField.model_validate(dict_body) try: await add_or_update_extra_field(db, entity_type, body_with_key) diff --git a/spoolman/api/v1/vendor.py b/spoolman/api/v1/vendor.py index 890b4e2..01233e8 100644 --- a/spoolman/api/v1/vendor.py +++ b/spoolman/api/v1/vendor.py @@ -209,7 +209,7 @@ async def create( # noqa: ANN201 try: validate_extra_field_dict(all_fields, body.extra) except ValueError as e: - return JSONResponse(status_code=400, content=Message(message=str(e)).dict()) + return JSONResponse(status_code=400, content=Message(message=str(e)).model_dump()) db_item = await vendor.create( db=db, diff --git a/tests_integration/tests/conftest.py b/tests_integration/tests/conftest.py index b4d5432..e3ba574 100644 --- a/tests_integration/tests/conftest.py +++ b/tests_integration/tests/conftest.py @@ -297,3 +297,9 @@ def assert_httpx_success(response: httpx.Response) -> None: """Assert that a response is successful.""" if not response.is_success: pytest.fail(f"Request failed: {response.status_code} {response.text}") + + +def assert_httpx_code(response: httpx.Response, code: int) -> None: + """Assert that a response has the expected status code.""" + if response.status_code != code: + pytest.fail(f"Request failed: {response.status_code} {response.text}") diff --git a/tests_integration/tests/fields/test_utilize.py b/tests_integration/tests/fields/test_utilize.py index 43124b4..2736a5a 100644 --- a/tests_integration/tests/fields/test_utilize.py +++ b/tests_integration/tests/fields/test_utilize.py @@ -4,7 +4,7 @@ import json import httpx -from ..conftest import URL, assert_httpx_success +from ..conftest import URL, assert_httpx_code, assert_httpx_success def test_add_vendor_with_extra_field(): @@ -56,8 +56,7 @@ def test_add_vendor_with_invalid_extra_field(): }, }, ) - assert result.status_code == 400 - assert "somefield" in result.json()["message"].lower() + assert_httpx_code(result, 422) def test_add_vendor_with_extra_field_then_delete(): diff --git a/tests_integration/tests/setting/test_set.py b/tests_integration/tests/setting/test_set.py index 5d97acf..d491c42 100644 --- a/tests_integration/tests/setting/test_set.py +++ b/tests_integration/tests/setting/test_set.py @@ -82,7 +82,7 @@ def test_set_currency_wrong_type(): f"{URL}/api/v1/setting/currency", json=123, ) - assert result.status_code == 400 + assert result.status_code == 422 def test_set_big_value():