From 6a785a1eb8cbfb111840bfef43c360d6f62233f7 Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Fri, 5 Jul 2024 08:58:10 +0000 Subject: [PATCH] Reorganise mock_data file #314 --- test/e2e/test_catalogue_category.py | 72 ++--- test/mock_data.py | 268 ++++++++++-------- test/unit/services/test_catalogue_category.py | 8 +- 3 files changed, 183 insertions(+), 165 deletions(-) diff --git a/test/e2e/test_catalogue_category.py b/test/e2e/test_catalogue_category.py index 1fd66353..5bad8b11 100644 --- a/test/e2e/test_catalogue_category.py +++ b/test/e2e/test_catalogue_category.py @@ -9,10 +9,10 @@ from test.e2e.conftest import E2ETestHelpers from test.mock_data import ( - CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, + CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_NO_PROPERTIES, + CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, CATALOGUE_CATEGORY_GET_DATA_LEAF_REQUIRED_VALUES_ONLY, - CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B, CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, @@ -21,12 +21,11 @@ CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B, CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, - CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY, CATALOGUE_CATEGORY_PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, - UNIT_POST_DATA_MM, -) + UNIT_POST_DATA_MM) from typing import Optional import pytest @@ -34,7 +33,8 @@ from fastapi.testclient import TestClient from httpx import Response -from inventory_management_system_api.core.consts import BREADCRUMBS_TRAIL_MAX_LENGTH +from inventory_management_system_api.core.consts import \ + BREADCRUMBS_TRAIL_MAX_LENGTH class CreateDSL: @@ -142,7 +142,7 @@ def test_create_non_leaf_with_properties(self): self.post_catalogue_category( { **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, - "properties": [CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT], + "properties": [CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY], } ) self.check_post_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_REQUIRED_VALUES_ONLY) @@ -216,21 +216,21 @@ def test_create_leaf_with_properties(self): """Test creating a leaf catalogue category with some properties provided""" self.post_unit(UNIT_POST_DATA_MM) - self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) - self.check_post_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) + self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) + self.check_post_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) def test_create_leaf_with_properties_with_non_existent_unit_id(self): """Test creating a leaf catalogue category with a property with a non-existent unit id provided""" self.add_unit_value_and_id("mm", str(ObjectId())) - self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) + self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) self.check_post_catalogue_category_failed_with_message(422, "The specified unit does not exist") def test_create_leaf_with_properties_with_invalid_unit_id(self): """Test creating a leaf catalogue category with a property with an invalid unit id provided""" self.add_unit_value_and_id("mm", "invalid-id") - self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) + self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) self.check_post_catalogue_category_failed_with_message(422, "The specified unit does not exist") def test_create_leaf_with_duplicate_properties(self): @@ -238,15 +238,15 @@ def test_create_leaf_with_duplicate_properties(self): self.post_catalogue_category( { - **CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, + **CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, "properties": [ - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, ], } ) self.check_post_catalogue_category_failed_with_message( - 422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT["name"]}" + 422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"]}" ) def test_create_leaf_with_property_with_invalid_type(self): @@ -254,9 +254,9 @@ def test_create_leaf_with_property_with_invalid_type(self): self.post_catalogue_category( { - **CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, + **CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, "properties": [ - {**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "type": "invalid-type"} + {**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "type": "invalid-type"} ], } ) @@ -270,14 +270,14 @@ def test_create_leaf_with_boolean_property_with_unit(self): self.post_unit(UNIT_POST_DATA_MM) self.post_catalogue_category( { - **CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, - "properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "unit": "mm"}], + **CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, + "properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "unit": "mm"}], } ) self.check_post_catalogue_category_failed_with_validation_message( 422, "Value error, Unit not allowed for boolean property " - f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT['name']}'", + f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY['name']}'", ) def test_create_leaf_property_with_invalid_allowed_values_type(self): @@ -385,9 +385,9 @@ def test_get(self): """Test getting a catalogue category""" self.post_unit(UNIT_POST_DATA_MM) - catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) + catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) self.get_catalogue_category(catalogue_category_id) - self.check_get_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) + self.check_get_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) def test_get_with_non_existent_id(self): """Test getting a catalogue category with a non-existent id""" @@ -848,11 +848,11 @@ def test_partial_update_non_leaf_all_valid_values_when_no_children(self): self.patch_catalogue_category( catalogue_category_id, - {**CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, "parent_id": new_parent_id}, + {**CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, "parent_id": new_parent_id}, ) self.check_patch_catalogue_category_response_success( - {**CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, "parent_id": new_parent_id} + {**CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, "parent_id": new_parent_id} ) def test_partial_update_non_leaf_to_leaf_without_properties(self): @@ -900,7 +900,7 @@ def test_partial_update_leaf_all_valid_values_when_no_children(self): self.post_unit(UNIT_POST_DATA_MM) new_parent_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A) - catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) + catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) # Properties not supplied, here, but they should have been removed in the end as going from leaf to non-leaf self.patch_catalogue_category( @@ -958,14 +958,14 @@ def test_partial_update_leaf_to_non_leaf_with_properties(self): self.post_unit(UNIT_POST_DATA_MM) new_parent_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A) - catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM) + catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM) self.patch_catalogue_category( catalogue_category_id, { **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, "parent_id": new_parent_id, - "properties": CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM["properties"], + "properties": CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM["properties"], }, ) @@ -1004,7 +1004,7 @@ def test_partial_update_leaf_properties(self): catalogue_category_id, { "properties": [ - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, ] }, @@ -1014,7 +1014,7 @@ def test_partial_update_leaf_properties(self): { **CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_NO_PROPERTIES, "properties": [ - CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY, CATALOGUE_CATEGORY_PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, ], } @@ -1048,13 +1048,13 @@ def test_partial_update_leaf_with_duplicate_properties(self): catalogue_category_id, { "properties": [ - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, ], }, ) self.check_patch_catalogue_category_failed_with_message( - 422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT["name"]}" + 422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"]}" ) def test_partial_update_leaf_with_property_with_invalid_type(self): @@ -1065,7 +1065,7 @@ def test_partial_update_leaf_with_property_with_invalid_type(self): catalogue_category_id, { "properties": [ - {**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "type": "invalid-type"} + {**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "type": "invalid-type"} ], }, ) @@ -1081,13 +1081,13 @@ def test_partial_update_leaf_with_boolean_property_with_unit(self): self.patch_catalogue_category( catalogue_category_id, { - "properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, "unit": "mm"}], + "properties": [{**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "unit": "mm"}], }, ) self.check_patch_catalogue_category_failed_with_validation_message( 422, "Value error, Unit not allowed for boolean property " - f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT['name']}'", + f"'{CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY['name']}'", ) def test_partial_update_leaf_property_with_invalid_allowed_values_type(self): diff --git a/test/mock_data.py b/test/mock_data.py index c7482163..f41099f7 100644 --- a/test/mock_data.py +++ b/test/mock_data.py @@ -27,58 +27,27 @@ UNIT_IN_DATA_MM = {**UNIT_POST_DATA_MM, "code": "mm"} -# --------------------------------- CATALOGUE CATEGORIES --------------------------------- +# --------------------------------- CATALOGUE CATEGORY PROPERTIES --------------------------------- -CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A = { - "name": "Category A", - "is_leaf": False, - "parent_id": None, -} +# Boolean, No unit -CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B = { - "name": "Category B", - "is_leaf": False, - "parent_id": None, -} - -CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A = { - **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, - "code": "category-a", -} - -CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B = { - **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B, - "code": "category-b", +CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY = { + "name": "Mandatory Boolean Property Without Unit", + "type": "boolean", + "mandatory": True, } -CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A = { - **CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, - **CREATED_MODIFIED_GET_DATA_EXPECTED, - "id": ANY, - "properties": [], -} +CATALOGUE_CATEGORY_PROPERTY_IN_DATA_BOOLEAN_MANDATORY = {**CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY} -CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B = { - **CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B, - **CREATED_MODIFIED_GET_DATA_EXPECTED, +CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY = { + **CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, "id": ANY, - "properties": [], -} - -CATALOGUE_CATEGORY_IN_DATA_LEAF_NO_PARENT_NO_PROPERTIES = { - "name": "Leaf Category No Parent No Properties", - "code": "leaf-category-no-parent-no-properties", - "is_leaf": True, - "parent_id": None, - "properties": [], + "unit_id": ANY, + "unit": None, + "allowed_values": None, } - -CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT = { - "name": "Mandatory Boolean Property Without Unit", - "type": "boolean", - "mandatory": True, -} +# Number, mm unit CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT = { "name": "Non Mandatory Number Property With Unit", @@ -87,30 +56,11 @@ "mandatory": False, } -CATALOGUE_CATEGORY_PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST = { - "name": "Non Mandatory String Property With Allowed Values", - "type": "string", - "mandatory": False, - "allowed_values": {"type": "list", "values": ["value1", "value2", "value3"]}, -} - -CATALOGUE_CATEGORY_PROPERTY_IN_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT = { - **CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT -} - CATALOGUE_CATEGORY_PROPERTY_IN_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT = { **CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, "unit_id": str(ObjectId()), } -CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT = { - **CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, - "id": ANY, - "unit_id": ANY, - "unit": None, - "allowed_values": None, -} - CATALOGUE_CATEGORY_PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT = { **CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, "id": ANY, @@ -118,6 +68,20 @@ "allowed_values": None, } +# String, Allowed values list + +CATALOGUE_CATEGORY_PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST = { + "name": "Non Mandatory String Property With Allowed Values", + "type": "string", + "mandatory": False, + "allowed_values": {"type": "list", "values": ["value1", "value2", "value3"]}, +} + +CATALOGUE_CATEGORY_PROPERTY_IN_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST = { + **CATALOGUE_CATEGORY_PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST, + "unit_id": str(ObjectId()), +} + CATALOGUE_CATEGORY_PROPERTY_GET_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST = { **CATALOGUE_CATEGORY_PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST, "id": ANY, @@ -125,56 +89,90 @@ "unit": None, } -# Put _MM at end to signify what units this data would require -CATALOGUE_CATEGORY_IN_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM = { - "name": "Leaf Category No Parent With Properties", - "code": "leaf-category-no-parent-with-properties", - "is_leaf": True, +# --------------------------------- CATALOGUE CATEGORIES --------------------------------- + +# Non leaf, Required values only + +CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY = { + "name": "Non Leaf Catalogue Category Required Values Only", + "is_leaf": False, +} + +CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_REQUIRED_VALUES_ONLY = { + **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, + **CREATED_MODIFIED_GET_DATA_EXPECTED, + "id": ANY, "parent_id": None, - "properties": [ - CATALOGUE_CATEGORY_PROPERTY_IN_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, - CATALOGUE_CATEGORY_PROPERTY_IN_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, - ], + "code": "non-leaf-catalogue-category-required-values-only", + "properties": [], } -CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES = { - "name": "Leaf Category No Parent No Properties", - "is_leaf": True, +# Non leaf, No parent, No properties + +CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A = { + "name": "Category A", + "is_leaf": False, "parent_id": None, +} + +CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A = { + **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, + "code": "category-a", +} + +CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A = { + **CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, + **CREATED_MODIFIED_GET_DATA_EXPECTED, + "id": ANY, "properties": [], } -CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_NO_PROPERTIES = { - **CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES, + +CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B = { + "name": "Category B", + "is_leaf": False, + "parent_id": None, +} + +CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B = { + **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B, + "code": "category-b", +} + +CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B = { + **CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B, **CREATED_MODIFIED_GET_DATA_EXPECTED, "id": ANY, - "code": "leaf-category-no-parent-no-properties", + "properties": [], } -CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM = { - "name": "Leaf Category No Parent With Properties", +# Leaf, No parent, No properties + +CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES = { + "name": "Leaf Category No Parent No Properties", "is_leaf": True, "parent_id": None, - "properties": [ - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, - CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, - ], } -CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY = { - "name": "Non Leaf Catalogue Category Required Values Only", - "is_leaf": False, + +CATALOGUE_CATEGORY_IN_DATA_LEAF_NO_PARENT_NO_PROPERTIES = { + **CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES, + "code": "leaf-category-no-parent-no-properties", + "properties": [], } -CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_REQUIRED_VALUES_ONLY = { - **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, +CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_NO_PROPERTIES = { + **CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES, **CREATED_MODIFIED_GET_DATA_EXPECTED, "id": ANY, - "parent_id": None, - "code": "non-leaf-catalogue-category-required-values-only", + "code": "leaf-category-no-parent-no-properties", "properties": [], } +# --------------------------------- Properties --------------------------------- + +# Leaf, Required values only + CATALOGUE_CATEGORY_POST_DATA_LEAF_REQUIRED_VALUES_ONLY = { "name": "Leaf Catalogue Category Required Values Only", "is_leaf": True, @@ -189,25 +187,39 @@ "properties": [], } -CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM = { - "name": "Catalogue Category With Properties", +# Leaf, No parent, Properties - with mm unit + +# Put _MM at end to signify what units this data would require +CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM = { + "name": "Leaf Category No Parent With Properties", "is_leaf": True, "parent_id": None, "properties": [ - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, CATALOGUE_CATEGORY_PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST, ], } -CATALOGUE_CATEGORY_GET_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM = { - **CATALOGUE_CATEGORY_DATA_LEAF_WITH_PROPERTIES_NO_PARENT_MM, +CATALOGUE_CATEGORY_IN_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM = { + **CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, + "code": "leaf-category-no-parent-with-properties", + "properties": [ + CATALOGUE_CATEGORY_PROPERTY_IN_DATA_BOOLEAN_MANDATORY, + CATALOGUE_CATEGORY_PROPERTY_IN_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, + CATALOGUE_CATEGORY_PROPERTY_IN_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST, + ], +} + + +CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM = { + **CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, **CREATED_MODIFIED_GET_DATA_EXPECTED, "id": ANY, "parent_id": None, - "code": "catalogue-category-with-properties", + "code": "leaf-category-no-parent-with-properties", "properties": [ - CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_GET_DATA_BOOLEAN_MANDATORY, CATALOGUE_CATEGORY_PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, CATALOGUE_CATEGORY_PROPERTY_GET_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST, ], @@ -216,33 +228,7 @@ # --------------------------------- SYSTEMS --------------------------------- -SYSTEM_POST_DATA_NO_PARENT_A = { - "parent_id": None, - "name": "Test name A", - "description": "Test description A", - "location": "Test location A", - "owner": "Test owner A", - "importance": "low", -} - -SYSTEM_POST_DATA_NO_PARENT_B = { - "parent_id": None, - "name": "Test name B", - "description": "Test description B", - "location": "Test location B", - "owner": "Test owner B", - "importance": "low", -} - -SYSTEM_IN_DATA_NO_PARENT_A = { - **SYSTEM_POST_DATA_NO_PARENT_A, - "code": "test-name-a", -} - -SYSTEM_IN_DATA_NO_PARENT_B = { - **SYSTEM_POST_DATA_NO_PARENT_B, - "code": "test-name-b", -} +# No parent, Required values only SYSTEM_POST_DATA_REQUIRED_VALUES_ONLY = { "name": "System Test Required Values Only", @@ -260,6 +246,8 @@ "code": "system-test-required-values-only", } +# No parent, All values + SYSTEM_POST_DATA_ALL_VALUES_NO_PARENT = { **SYSTEM_POST_DATA_REQUIRED_VALUES_ONLY, "name": "System Test All Values", @@ -276,3 +264,33 @@ "parent_id": None, "code": "system-test-all-values", } + +# No parent + +SYSTEM_POST_DATA_NO_PARENT_A = { + "parent_id": None, + "name": "Test name A", + "description": "Test description A", + "location": "Test location A", + "owner": "Test owner A", + "importance": "low", +} + +SYSTEM_IN_DATA_NO_PARENT_A = { + **SYSTEM_POST_DATA_NO_PARENT_A, + "code": "test-name-a", +} + +SYSTEM_POST_DATA_NO_PARENT_B = { + "parent_id": None, + "name": "Test name B", + "description": "Test description B", + "location": "Test location B", + "owner": "Test owner B", + "importance": "low", +} + +SYSTEM_IN_DATA_NO_PARENT_B = { + **SYSTEM_POST_DATA_NO_PARENT_B, + "code": "test-name-b", +} diff --git a/test/unit/services/test_catalogue_category.py b/test/unit/services/test_catalogue_category.py index f9640489..618bb9f0 100644 --- a/test/unit/services/test_catalogue_category.py +++ b/test/unit/services/test_catalogue_category.py @@ -13,7 +13,7 @@ CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES, CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B, - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT, UNIT_IN_DATA_MM, ) @@ -288,14 +288,14 @@ def test_create_with_duplicate_properties(self): { **CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A, "properties": [ - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, - CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, + CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY, ], }, ) self.call_create_expecting_error(DuplicateCatalogueCategoryPropertyNameError) self.check_create_failed_with_exception( - f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY_WITHOUT_UNIT['name']}" + f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY['name']}" ) def test_create_with_properties_with_non_existent_unit_id(self):