Tests fully pass again
This commit is contained in:
@@ -59,7 +59,10 @@ async def update(
|
|||||||
key: Annotated[str, Path(min_length=1, max_length=64, regex="^[a-z0-9_]+$")],
|
key: Annotated[str, Path(min_length=1, max_length=64, regex="^[a-z0-9_]+$")],
|
||||||
body: ExtraFieldParameters,
|
body: ExtraFieldParameters,
|
||||||
) -> Union[list[ExtraField], JSONResponse]:
|
) -> 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:
|
try:
|
||||||
await add_or_update_extra_field(db, entity_type, body_with_key)
|
await add_or_update_extra_field(db, entity_type, body_with_key)
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ async def create( # noqa: ANN201
|
|||||||
try:
|
try:
|
||||||
validate_extra_field_dict(all_fields, body.extra)
|
validate_extra_field_dict(all_fields, body.extra)
|
||||||
except ValueError as e:
|
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_item = await vendor.create(
|
||||||
db=db,
|
db=db,
|
||||||
|
|||||||
@@ -297,3 +297,9 @@ def assert_httpx_success(response: httpx.Response) -> None:
|
|||||||
"""Assert that a response is successful."""
|
"""Assert that a response is successful."""
|
||||||
if not response.is_success:
|
if not response.is_success:
|
||||||
pytest.fail(f"Request failed: {response.status_code} {response.text}")
|
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}")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import json
|
|||||||
|
|
||||||
import httpx
|
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():
|
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_httpx_code(result, 422)
|
||||||
assert "somefield" in result.json()["message"].lower()
|
|
||||||
|
|
||||||
|
|
||||||
def test_add_vendor_with_extra_field_then_delete():
|
def test_add_vendor_with_extra_field_then_delete():
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ def test_set_currency_wrong_type():
|
|||||||
f"{URL}/api/v1/setting/currency",
|
f"{URL}/api/v1/setting/currency",
|
||||||
json=123,
|
json=123,
|
||||||
)
|
)
|
||||||
assert result.status_code == 400
|
assert result.status_code == 422
|
||||||
|
|
||||||
|
|
||||||
def test_set_big_value():
|
def test_set_big_value():
|
||||||
|
|||||||
Reference in New Issue
Block a user