Skip to content

Commit

Permalink
Initial refactor of ItemService create tests #346
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Aug 8, 2024
1 parent 08671d9 commit b8e93c9
Show file tree
Hide file tree
Showing 5 changed files with 1,463 additions and 1,257 deletions.
16 changes: 8 additions & 8 deletions inventory_management_system_api/services/catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ def create(self, catalogue_item: CatalogueItemPostSchema) -> CatalogueItemOut:
)
)

def delete(self, catalogue_item_id: str) -> None:
"""
Delete a catalogue item by its ID.
:param catalogue_item_id: The ID of the catalogue item to delete.
"""
return self._catalogue_item_repository.delete(catalogue_item_id)

def get(self, catalogue_item_id: str) -> Optional[CatalogueItemOut]:
"""
Retrieve a catalogue item by its ID.
Expand Down Expand Up @@ -219,3 +211,11 @@ def update(self, catalogue_item_id: str, catalogue_item: CatalogueItemPatchSchem
catalogue_item_id,
CatalogueItemIn(**{**stored_catalogue_item.model_dump(), **update_data}),
)

def delete(self, catalogue_item_id: str) -> None:
"""
Delete a catalogue item by its ID.
:param catalogue_item_id: The ID of the catalogue item to delete.
"""
return self._catalogue_item_repository.delete(catalogue_item_id)
2 changes: 1 addition & 1 deletion inventory_management_system_api/services/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _merge_missing_properties(
self, properties: List[PropertyOut], supplied_properties: List[PropertyPostSchema]
) -> List[PropertyPostSchema]:
"""
Merges the properties defined in a catalogue item with those that should be overriden for an item in
Merges the properties defined in a catalogue item with those that should be overridden for an item in
the order they are defined in the catalogue item.
:param properties: The list of property objects from the catalogue item.
Expand Down
44 changes: 42 additions & 2 deletions test/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@

UNIT_IN_DATA_MM = {**UNIT_POST_DATA_MM, "code": "mm"}

# --------------------------------- USAGE STATUSES ---------------------------------

USAGE_STATUS_DATA_IN_USE = {"value": "In Use"}

USAGE_STATUS_IN_DATA_IN_USE = {**USAGE_STATUS_DATA_IN_USE, "code": "in-use"}

# --------------------------------- CATALOGUE CATEGORY PROPERTIES ---------------------------------

# Boolean, Mandatory, No unit
Expand Down Expand Up @@ -240,10 +246,16 @@

# --------------------------------- PROPERTIES ---------------------------------

# Boolean, Mandatory, False
PROPERTY_DATA_BOOLEAN_MANDATORY_FALSE = {
"name": CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"],
"value": False,
}

# Boolean, Mandatory, True

PROPERTY_DATA_BOOLEAN_MANDATORY_TRUE = {
"name": CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"],
**PROPERTY_DATA_BOOLEAN_MANDATORY_FALSE,
"value": True,
}

Expand All @@ -262,10 +274,17 @@
**PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_1
}

# Number, Non Mandatory, 1

PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT_1 = {
"name": CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT["name"],
"value": 1,
}

# Number, Non Mandatory, 42

PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT_42 = {
"name": CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT["name"],
**PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT_1,
"value": 42,
}

Expand Down Expand Up @@ -297,6 +316,12 @@
**PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_VALUE1
}

# String, Non Mandatory, Allowed Values List, value2
PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_VALUE2 = {
**PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_VALUE1,
"value": "value2",
}

# String, Non Mandatory, Allowed Values List, None

PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_NONE = {
Expand Down Expand Up @@ -435,6 +460,10 @@

# ------------------------------------- ITEMS -------------------------------------

# This is the base catalogue item to be used in tests with properties
BASE_CATALOGUE_ITEM_DATA_WITH_PROPERTIES = CATALOGUE_ITEM_DATA_WITH_ALL_PROPERTIES


ITEM_DATA_REQUIRED_VALUES_ONLY = {
"is_defective": False,
"usage_status": "In Use",
Expand All @@ -447,6 +476,17 @@
"usage_status_id": str(ObjectId()),
}

# All properties

ITEM_DATA_WITH_ALL_PROPERTIES = {
**ITEM_DATA_REQUIRED_VALUES_ONLY,
"properties": [
PROPERTY_DATA_BOOLEAN_MANDATORY_FALSE,
PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT_1,
PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_VALUE2,
],
}

# pylint:disable=fixme
# TODO: Replace in later item's PR when have a suitable name for one
ITEM_IN_DATA_A = {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/services/test_catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ def setup(
def construct_properties_in_and_post_with_ids(
self,
catalogue_category_properties_in: list[CatalogueCategoryPropertyIn],
catalogue_items_properties_data: list[dict],
properties_data: list[dict],
) -> tuple[list[PropertyIn], list[PropertyPostSchema]]:
"""
Returns a list of property post schemas and expected property in models by adding
in unit IDs. It also assigns `unit_value_id_dict` for looking up these IDs.
:param catalogue_category_properties_in: List of `CatalogueCategoryPropertyIn`'s as would be found in the
catalogue category.
:param catalogue_items_properties_data: List of dictionaries containing the data for each property as would
be required for a `PropertyPostSchema` but without any `id`'s.
:param properties_data: List of dictionaries containing the data for each property as would be required for a
`PropertyPostSchema` but without any `id`'s.
:returns: Tuple of lists. The first contains the expected `PropertyIn` models and the second the
`PropertyPostSchema` schema's that should be posted in order to obtain them.
"""
Expand All @@ -109,7 +109,7 @@ def construct_properties_in_and_post_with_ids(

self.property_name_id_dict = {}

for prop in catalogue_items_properties_data:
for prop in properties_data:
prop_id = None
prop_without_name = prop.copy()

Expand Down
Loading

0 comments on commit b8e93c9

Please sign in to comment.