Skip to content

Commit

Permalink
Initial refactoring and tweaks to existing tests #342
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Aug 5, 2024
1 parent 5282d50 commit ed9e525
Show file tree
Hide file tree
Showing 6 changed files with 2,310 additions and 2,174 deletions.
23 changes: 21 additions & 2 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def replace_unit_values_with_ids_in_properties(properties_without_ids: list[dict
unchanged.
:param properties_without_ids: The list of properties without IDs. Each property is a dictionary
that may contain a 'unit' key with a unit value that needs to be
that may contain a `unit` key with a unit value that needs to be
replaced by the unit ID.
:param units: The list of units. Each unit is a dictionary containing 'id' and 'value' keys, where
ID is the unique identifier for the unit and 'value' is the unit value to match
Expand Down Expand Up @@ -111,7 +111,7 @@ def replace_unit_values_with_ids_in_properties(data: dict, unit_value_id_dict: d
"""Inserts unit IDs into some data that may have a 'properties' list within it
:param data: Dictionary of data that could have a 'properties' value within it
:param unit_value_id_dict: Dictionary of unit value and id pairs for unit id lookups
:param unit_value_id_dict: Dictionary of unit value and ID pairs for unit ID lookups
:return: The data with any needed unit IDs inserted
"""

Expand All @@ -128,3 +128,22 @@ def replace_unit_values_with_ids_in_properties(data: dict, unit_value_id_dict: d
new_properties.append(new_property)
return {**data, "properties": new_properties}
return data

@staticmethod
def replace_property_names_with_ids_in_properties(data: dict, property_name_id_dict: dict[str, str]) -> dict:
"""Inserts property IDs into some data that may have a 'properties' list within it
:param data: Dictionary of data that could have a 'properties' value within it
:param property_name_id_dict: Dictionary of property name and ID pairs for property ID lookups
:return: The data with any needed property IDs inserted
"""

if "properties" in data and data["properties"]:
new_properties = []
for prop in data["properties"]:
new_property = {**prop}
new_property["id"] = property_name_id_dict[prop["name"]]
del new_property["name"]
new_properties.append(new_property)
return {**data, "properties": new_properties}
return data
16 changes: 8 additions & 8 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def post_catalogue_category(self, catalogue_category_data: dict) -> Optional[str
:param catalogue_category_data: Dictionary containing the basic catalogue category data as would be required
for a `CatalogueCategoryPostSchema` but with any `unit_id`'s replaced by the
'unit' value in its properties as the IDs will be added automatically.
`unit` value in its properties as the IDs will be added automatically.
:return: ID of the created catalogue category (or `None` if not successful).
"""

Expand Down Expand Up @@ -122,8 +122,8 @@ def check_post_catalogue_category_success(self, expected_catalogue_category_get_
Checks that a prior call to `post_catalogue_category` gave a successful response with the expected data
returned.
:param expected_catalogue_category_get_data: Dictionary containing the expected system data returned as would
be required for a `CatalogueCategoryGetSchema`.
:param expected_catalogue_category_get_data: Dictionary containing the expected catalogue category data returned
as would be required for a `CatalogueCategorySchema`.
"""

assert self._post_response.status_code == 201
Expand Down Expand Up @@ -393,7 +393,7 @@ def check_get_catalogue_category_success(self, expected_catalogue_category_get_d
Checks that a prior call to `get_catalogue_category` gave a successful response with the expected data returned.
:param expected_catalogue_category_get_data: Dictionary containing the expected system data returned as would
be required for a `CatalogueCategoryGetSchema`.
be required for a `CatalogueCategorySchema`.
"""

assert self._get_response.status_code == 200
Expand Down Expand Up @@ -590,7 +590,7 @@ def post_test_catalogue_category_with_child(self) -> list[dict]:
list endpoint.
:return: List of dictionaries containing the expected catalogue category data returned from a get endpoint in
the form of a `CatalogueCategoryGetSchema`.
the form of a `CatalogueCategorySchema`.
"""

parent_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY)
Expand All @@ -609,7 +609,7 @@ def check_get_catalogue_categories_success(self, expected_catalogue_categories_g
returned.
:param expected_catalogue_categories_get_data: List of dictionaries containing the expected system data
returned as would be required for `CatalogueCategoryGetSchema`'s.
returned as would be required for `CatalogueCategorySchema`'s.
"""

assert self._get_response.status_code == 200
Expand Down Expand Up @@ -681,7 +681,7 @@ def patch_catalogue_category(self, catalogue_category_id: str, catalogue_categor
:param catalogue_category_id: ID of the catalogue category to patch.
:param catalogue_category_update_data: Dictionary containing the basic patch data as would be required for a
`CatalogueCategoryPatchSchema` but with any unit_id's replaced by the
'unit' value in its properties as the ids will be added automatically.
`unit` value in its properties as the ids will be added automatically.
"""

# Replace any unit values with unit ids
Expand Down Expand Up @@ -779,7 +779,7 @@ def check_patch_catalogue_category_response_success(self, expected_catalogue_cat
returned.
:param expected_catalogue_category_get_data: Dictionary containing the expected system data returned as would
be required for a `CatalogueCategoryGetSchema`.
be required for a `CatalogueCategorySchema`.
"""

assert self._patch_response.status_code == 200
Expand Down
Loading

0 comments on commit ed9e525

Please sign in to comment.