From c3aa74736a94ad5150a31765942f39d941858e7f Mon Sep 17 00:00:00 2001 From: rowan04 Date: Wed, 13 Nov 2024 16:47:35 +0000 Subject: [PATCH 1/5] Edit exception message when editing certain fields of a catalogue item with children #353 --- inventory_management_system_api/routers/v1/catalogue_item.py | 2 +- test/e2e/test_catalogue_item.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inventory_management_system_api/routers/v1/catalogue_item.py b/inventory_management_system_api/routers/v1/catalogue_item.py index 624b54de..60a58b7a 100644 --- a/inventory_management_system_api/routers/v1/catalogue_item.py +++ b/inventory_management_system_api/routers/v1/catalogue_item.py @@ -161,7 +161,7 @@ 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 manufacturer_id and properties fields cannot be updated" 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_item.py b/test/e2e/test_catalogue_item.py index f02652ee..93279941 100644 --- a/test/e2e/test_catalogue_item.py +++ b/test/e2e/test_catalogue_item.py @@ -1184,7 +1184,7 @@ 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 manufacturer_id and properties fields cannot be updated" ) def test_partial_update_manufacturer_id_with_non_existent_id(self): @@ -1459,7 +1459,7 @@ 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 manufacturer_id and properties fields cannot be updated" ) def test_partial_update_obsolete_replacement_catalogue_item_id(self): From f8912eb147e4b95014ac661990cce3ebd8d2d289 Mon Sep 17 00:00:00 2001 From: rowan04 Date: Tue, 19 Nov 2024 15:35:13 +0000 Subject: [PATCH 2/5] use variable so exception message is kept up to date #353 - with changes to pass tests --- .../routers/v1/catalogue_item.py | 4 +++- test/e2e/test_catalogue_item.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/inventory_management_system_api/routers/v1/catalogue_item.py b/inventory_management_system_api/routers/v1/catalogue_item.py index 60a58b7a..7605fcc2 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,8 @@ 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, so the manufacturer_id and properties fields 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_item.py b/test/e2e/test_catalogue_item.py index 93279941..a4b95ba1 100644 --- a/test/e2e/test_catalogue_item.py +++ b/test/e2e/test_catalogue_item.py @@ -1184,7 +1184,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, so the manufacturer_id and properties fields cannot be updated" + 409, + "Catalogue item has child elements, so the following fields cannot be updated: " + + "manufacturer_id, properties" ) def test_partial_update_manufacturer_id_with_non_existent_id(self): @@ -1459,7 +1461,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, so the manufacturer_id and properties fields cannot be updated" + 409, + "Catalogue item has child elements, so the following fields cannot be updated: " + + "manufacturer_id, properties" ) def test_partial_update_obsolete_replacement_catalogue_item_id(self): From 220d45a3f344b7a9cdf6bd20b06ef5e777fe886c Mon Sep 17 00:00:00 2001 From: rowan04 Date: Wed, 20 Nov 2024 10:47:40 +0000 Subject: [PATCH 3/5] edit exception message when editing catalogue category with children #353 - and test changes to pass --- .../routers/v1/catalogue_category.py | 4 +++- test/e2e/test_catalogue_category.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/inventory_management_system_api/routers/v1/catalogue_category.py b/inventory_management_system_api/routers/v1/catalogue_category.py index a829287e..8031311d 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,8 @@ 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/test/e2e/test_catalogue_category.py b/test/e2e/test_catalogue_category.py index e7fd4c15..9bfa4a5b 100644 --- a/test/e2e/test_catalogue_category.py +++ b/test/e2e/test_catalogue_category.py @@ -987,7 +987,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: " + + "is_leaf, properties" ) def test_partial_update_leaf_all_valid_values_when_no_children(self): @@ -1032,7 +1034,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: " + + "is_leaf, properties" ) def test_partial_update_leaf_properties_when_has_child_catalogue_item(self): @@ -1044,7 +1048,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: " + + "is_leaf, properties" ) def test_partial_update_leaf_to_non_leaf_with_properties(self): @@ -1087,7 +1093,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: " + + "is_leaf, properties" ) def test_partial_update_leaf_properties(self): From bdb3785af5e4b4d73404bbb780d33e01de5ff652 Mon Sep 17 00:00:00 2001 From: rowan04 Date: Wed, 20 Nov 2024 12:17:01 +0000 Subject: [PATCH 4/5] change hardcode to use variable #353 --- test/e2e/test_catalogue_category.py | 12 ++++++++---- test/e2e/test_catalogue_item.py | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/e2e/test_catalogue_category.py b/test/e2e/test_catalogue_category.py index 9bfa4a5b..55b397c5 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.""" @@ -989,7 +993,7 @@ def test_partial_update_non_leaf_to_leaf_when_has_child_catalogue_category(self) self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + "is_leaf, properties" + + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS) ) def test_partial_update_leaf_all_valid_values_when_no_children(self): @@ -1036,7 +1040,7 @@ def test_partial_update_leaf_to_non_leaf_when_has_child_catalogue_item(self): self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + "is_leaf, properties" + + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS) ) def test_partial_update_leaf_properties_when_has_child_catalogue_item(self): @@ -1050,7 +1054,7 @@ def test_partial_update_leaf_properties_when_has_child_catalogue_item(self): self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + "is_leaf, properties" + + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS) ) def test_partial_update_leaf_to_non_leaf_with_properties(self): @@ -1095,7 +1099,7 @@ def test_partial_update_is_leaf_with_child_catalogue_category(self): self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + "is_leaf, properties" + + ', '.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 a4b95ba1..4246ef1b 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.""" @@ -1186,7 +1188,7 @@ def test_partial_update_manufacturer_id_with_children(self): self.check_patch_catalogue_item_failed_with_detail( 409, "Catalogue item has child elements, so the following fields cannot be updated: " - + "manufacturer_id, properties" + + ', '.join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS) ) def test_partial_update_manufacturer_id_with_non_existent_id(self): @@ -1463,7 +1465,7 @@ def test_partial_update_properties_with_children(self): self.check_patch_catalogue_item_failed_with_detail( 409, "Catalogue item has child elements, so the following fields cannot be updated: " - + "manufacturer_id, properties" + + ', '.join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS) ) def test_partial_update_obsolete_replacement_catalogue_item_id(self): From 3cdae514232f8731e1ef42aacf928d52be458b8a Mon Sep 17 00:00:00 2001 From: rowan04 Date: Thu, 21 Nov 2024 10:24:32 +0000 Subject: [PATCH 5/5] black line-length linting changes #353 --- .../routers/v1/catalogue_category.py | 5 +++-- .../routers/v1/catalogue_item.py | 5 +++-- test/e2e/test_catalogue_category.py | 8 ++++---- test/e2e/test_catalogue_item.py | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/inventory_management_system_api/routers/v1/catalogue_category.py b/inventory_management_system_api/routers/v1/catalogue_category.py index 8031311d..a42ab867 100644 --- a/inventory_management_system_api/routers/v1/catalogue_category.py +++ b/inventory_management_system_api/routers/v1/catalogue_category.py @@ -186,8 +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, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS)) + 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 7605fcc2..31d0f752 100644 --- a/inventory_management_system_api/routers/v1/catalogue_item.py +++ b/inventory_management_system_api/routers/v1/catalogue_item.py @@ -162,8 +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, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS)) + 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 55b397c5..a57177cd 100644 --- a/test/e2e/test_catalogue_category.py +++ b/test/e2e/test_catalogue_category.py @@ -993,7 +993,7 @@ def test_partial_update_non_leaf_to_leaf_when_has_child_catalogue_category(self) self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS) + + ", ".join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_leaf_all_valid_values_when_no_children(self): @@ -1040,7 +1040,7 @@ def test_partial_update_leaf_to_non_leaf_when_has_child_catalogue_item(self): self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS) + + ", ".join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_leaf_properties_when_has_child_catalogue_item(self): @@ -1054,7 +1054,7 @@ def test_partial_update_leaf_properties_when_has_child_catalogue_item(self): self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS) + + ", ".join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_leaf_to_non_leaf_with_properties(self): @@ -1099,7 +1099,7 @@ def test_partial_update_is_leaf_with_child_catalogue_category(self): self.check_patch_catalogue_category_failed_with_detail( 409, "Catalogue category has child elements, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS) + + ", ".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 4246ef1b..1816d945 100644 --- a/test/e2e/test_catalogue_item.py +++ b/test/e2e/test_catalogue_item.py @@ -1188,7 +1188,7 @@ def test_partial_update_manufacturer_id_with_children(self): self.check_patch_catalogue_item_failed_with_detail( 409, "Catalogue item has child elements, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS) + + ", ".join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_manufacturer_id_with_non_existent_id(self): @@ -1465,7 +1465,7 @@ def test_partial_update_properties_with_children(self): self.check_patch_catalogue_item_failed_with_detail( 409, "Catalogue item has child elements, so the following fields cannot be updated: " - + ', '.join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS) + + ", ".join(CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS), ) def test_partial_update_obsolete_replacement_catalogue_item_id(self):