diff --git a/inventory_management_system_api/routers/v1/catalogue_category.py b/inventory_management_system_api/routers/v1/catalogue_category.py index a829287e..a42ab867 100644 --- a/inventory_management_system_api/routers/v1/catalogue_category.py +++ b/inventory_management_system_api/routers/v1/catalogue_category.py @@ -26,6 +26,7 @@ CatalogueCategoryPropertyPostSchema, CatalogueCategoryPropertySchema, CatalogueCategorySchema, + CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS, ) from inventory_management_system_api.services.catalogue_category import CatalogueCategoryService from inventory_management_system_api.services.catalogue_category_property import CatalogueCategoryPropertyService @@ -185,7 +186,9 @@ def partial_update_catalogue_category( logger.exception(message) raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=message) from exc except ChildElementsExistError as exc: - message = "Catalogue category has child elements and cannot be updated" + message = "Catalogue category has child elements, so the following fields cannot be updated: " + ", ".join( + CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS + ) logger.exception(message) raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=message) from exc except DuplicateRecordError as exc: diff --git a/inventory_management_system_api/routers/v1/catalogue_item.py b/inventory_management_system_api/routers/v1/catalogue_item.py index 624b54de..31d0f752 100644 --- a/inventory_management_system_api/routers/v1/catalogue_item.py +++ b/inventory_management_system_api/routers/v1/catalogue_item.py @@ -21,6 +21,7 @@ CatalogueItemPatchSchema, CatalogueItemPostSchema, CatalogueItemSchema, + CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS, ) from inventory_management_system_api.services.catalogue_item import CatalogueItemService @@ -161,7 +162,9 @@ def partial_update_catalogue_item( logger.exception(message) raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=message) from exc except ChildElementsExistError as exc: - message = "Catalogue item has child elements and cannot be updated" + message = "Catalogue item has child elements, so the following fields cannot be updated: " + ", ".join( + CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS + ) logger.exception(message) raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=message) from exc except InvalidActionError as exc: diff --git a/test/e2e/test_catalogue_category.py b/test/e2e/test_catalogue_category.py index e7fd4c15..a57177cd 100644 --- a/test/e2e/test_catalogue_category.py +++ b/test/e2e/test_catalogue_category.py @@ -36,6 +36,10 @@ from inventory_management_system_api.core.consts import BREADCRUMBS_TRAIL_MAX_LENGTH +from inventory_management_system_api.schemas.catalogue_category import ( + CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS, +) + class CreateDSL: """Base class for create tests.""" @@ -987,7 +991,9 @@ def test_partial_update_non_leaf_to_leaf_when_has_child_catalogue_category(self) self.patch_catalogue_category(catalogue_category_id, {"is_leaf": True}) self.check_patch_catalogue_category_failed_with_detail( - 409, "Catalogue category has child elements and cannot be updated" + 409, + "Catalogue category has child elements, so the following fields cannot be updated: " + + ", ".join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_leaf_all_valid_values_when_no_children(self): @@ -1032,7 +1038,9 @@ def test_partial_update_leaf_to_non_leaf_when_has_child_catalogue_item(self): self.patch_catalogue_category(catalogue_category_id, {"is_leaf": False}) self.check_patch_catalogue_category_failed_with_detail( - 409, "Catalogue category has child elements and cannot be updated" + 409, + "Catalogue category has child elements, so the following fields cannot be updated: " + + ", ".join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_leaf_properties_when_has_child_catalogue_item(self): @@ -1044,7 +1052,9 @@ def test_partial_update_leaf_properties_when_has_child_catalogue_item(self): self.patch_catalogue_category(catalogue_category_id, {"properties": []}) self.check_patch_catalogue_category_failed_with_detail( - 409, "Catalogue category has child elements and cannot be updated" + 409, + "Catalogue category has child elements, so the following fields cannot be updated: " + + ", ".join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_leaf_to_non_leaf_with_properties(self): @@ -1087,7 +1097,9 @@ def test_partial_update_is_leaf_with_child_catalogue_category(self): self.patch_catalogue_category(catalogue_category_id, {"is_leaf": True}) self.check_patch_catalogue_category_failed_with_detail( - 409, "Catalogue category has child elements and cannot be updated" + 409, + "Catalogue category has child elements, so the following fields cannot be updated: " + + ", ".join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_leaf_properties(self): diff --git a/test/e2e/test_catalogue_item.py b/test/e2e/test_catalogue_item.py index f02652ee..1816d945 100644 --- a/test/e2e/test_catalogue_item.py +++ b/test/e2e/test_catalogue_item.py @@ -53,6 +53,8 @@ from bson import ObjectId from httpx import Response +from inventory_management_system_api.schemas.catalogue_item import CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS + class CreateDSL(CatalogueCategoryCreateDSL, ManufacturerCreateDSL): """Base class for create tests.""" @@ -1184,7 +1186,9 @@ def test_partial_update_manufacturer_id_with_children(self): self.patch_catalogue_item(catalogue_item_id, {"manufacturer_id": new_manufacturer_id}) self.check_patch_catalogue_item_failed_with_detail( - 409, "Catalogue item has child elements and cannot be updated" + 409, + "Catalogue item has child elements, so the following fields cannot be updated: " + + ", ".join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_manufacturer_id_with_non_existent_id(self): @@ -1459,7 +1463,9 @@ def test_partial_update_properties_with_children(self): self.patch_catalogue_item(catalogue_item_id, {"properties": []}) self.check_patch_catalogue_item_failed_with_detail( - 409, "Catalogue item has child elements and cannot be updated" + 409, + "Catalogue item has child elements, so the following fields cannot be updated: " + + ", ".join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_obsolete_replacement_catalogue_item_id(self):