Skip to content

Commit

Permalink
Refactor of items e2e create tests #347
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Aug 9, 2024
1 parent 4d5b498 commit 670979e
Show file tree
Hide file tree
Showing 6 changed files with 2,047 additions and 2,277 deletions.
18 changes: 9 additions & 9 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ def setup(self, test_client):
self.test_client = test_client
self.unit_value_id_dict = {}

def post_unit(self, unit_post_data: dict) -> None:
"""Posts a unit with the given data and stores the value and ID in a dictionary for lookup later.
:param unit_post_data: Dictionary containing the unit data as would be required for a `UnitPostSchema`.
"""

post_response = self.test_client.post("/v1/units", json=unit_post_data)
self.unit_value_id_dict[unit_post_data["value"]] = post_response.json()["id"]

def add_unit_value_and_id(self, unit_value: str, unit_id: str) -> None:
"""
Stores a unit value and ID inside the `unit_value_id_dict` for tests that need to have a
Expand All @@ -73,6 +64,15 @@ def add_unit_value_and_id(self, unit_value: str, unit_id: str) -> None:

self.unit_value_id_dict[unit_value] = unit_id

def post_unit(self, unit_post_data: dict) -> None:
"""Posts a unit with the given data and stores the value and ID in a dictionary for lookup later.
:param unit_post_data: Dictionary containing the unit data as would be required for a `UnitPostSchema`.
"""

post_response = self.test_client.post("/v1/units", json=unit_post_data)
self.add_unit_value_and_id(unit_post_data["value"], post_response.json()["id"])

def post_catalogue_category(self, catalogue_category_data: dict) -> Optional[str]:
"""
Posts a catalogue category with the given data and returns the ID of the created catalogue category if
Expand Down
19 changes: 8 additions & 11 deletions test/e2e/test_catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def add_ids_to_expected_catalogue_item_get_data(self, expected_catalogue_item_ge
:param expected_catalogue_item_get_data: Dictionary containing the expected catalogue item data returned as
would be required for a `CatalogueItemSchema`. Does not need mandatory
IDs (e.g. manufacturer_id) as they will be added here.
IDs (e.g. `manufacturer_id`) as they will be added here.
"""
# Where there are properties add the property ID, unit ID and unit value
expected_catalogue_item_get_data = E2ETestHelpers.add_property_ids_to_properties(
Expand Down Expand Up @@ -133,8 +133,7 @@ def post_manufacturer(self, manufacturer_post_data: dict) -> Optional[str]:

def post_catalogue_item(self, catalogue_item_data: dict) -> Optional[str]:
"""
Posts a catalogue item with the given data and returns the ID of the created catalogue item if
successful.
Posts a catalogue item with the given data and returns the ID of the created catalogue item if successful.
:param catalogue_item_data: Dictionary containing the basic catalogue item data as would be required
for a `CatalogueItemPostSchema` but with mandatory IDs missing and
Expand Down Expand Up @@ -168,8 +167,8 @@ def post_catalogue_item(self, catalogue_item_data: dict) -> Optional[str]:

def post_catalogue_item_and_prerequisites_no_properties(self, catalogue_item_data: dict) -> Optional[str]:
"""
Utility method that posts a catalogue item with the given data and also its prerequisite manufacturer,
catalogue category and units. Uses CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES for the catalogue
Utility method that posts a catalogue item with the given data and also its prerequisite manufacturer and
catalogue category. Uses CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES for the catalogue
category.
:param catalogue_item_data: Dictionary containing the basic catalogue item data as would be required for a
Expand Down Expand Up @@ -260,9 +259,7 @@ def post_catalogue_item_and_prerequisites_with_allowed_values(
return self.post_catalogue_item(
{
**CATALOGUE_ITEM_DATA_WITH_MANDATORY_PROPERTIES_ONLY,
"properties": [
{"name": "property", "value": property_value},
],
"properties": [{"name": "property", "value": property_value}],
}
)

Expand All @@ -273,7 +270,7 @@ def check_post_catalogue_item_success(self, expected_catalogue_item_get_data: di
:param expected_catalogue_item_get_data: Dictionary containing the expected catalogue item data returned as
would be required for a `CatalogueItemSchema`. Does not need mandatory
IDs (e.g. manufacturer_id) as they will be to check they are as
IDs (e.g. `manufacturer_id`) as they will be to check they are as
expected.
"""

Expand Down Expand Up @@ -375,7 +372,7 @@ def test_create_obsolete_with_invalid_obsolete_replacement_catalogue_item_id(sel
422, "The specified replacement catalogue item does not exist"
)

def test_create_with_all_properties_defined(self):
def test_create_with_all_properties_provided(self):
"""Test creating a catalogue item with all properties within the catalogue category being defined."""

self.post_catalogue_item_and_prerequisites_with_properties(CATALOGUE_ITEM_DATA_WITH_ALL_PROPERTIES)
Expand Down Expand Up @@ -474,7 +471,7 @@ def test_create_with_boolean_property_with_invalid_value_type(self):
self.post_catalogue_item_and_prerequisites_with_given_properties(
catalogue_category_properties_data=[CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY],
catalogue_item_properties_data=[
{"name": CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"], "value": "True"},
{"name": CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"], "value": 0},
],
)

Expand Down
Loading

0 comments on commit 670979e

Please sign in to comment.