Skip to content

Commit

Permalink
Merge pull request #418 from ral-facilities/reword-message-when-editi…
Browse files Browse the repository at this point in the history
…ng-catalogue-item-fields-with-children-#353

Edit exception message when editing certain fields of a catalogue item/category with children
  • Loading branch information
rowan04 authored Nov 21, 2024
2 parents e5f2e8c + 3cdae51 commit c2707d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion inventory_management_system_api/routers/v1/catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CatalogueItemPatchSchema,
CatalogueItemPostSchema,
CatalogueItemSchema,
CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS,
)
from inventory_management_system_api.services.catalogue_item import CatalogueItemService

Expand Down Expand Up @@ -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:
Expand Down
20 changes: 16 additions & 4 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions test/e2e/test_catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c2707d1

Please sign in to comment.