Skip to content

Commit

Permalink
Merge pull request #359 from ral-facilities/refactor-item-e2e-tests-#347
Browse files Browse the repository at this point in the history
Refactor item e2e tests #347
  • Loading branch information
joelvdavies authored Sep 5, 2024
2 parents 6adc501 + 8c2c069 commit 4ae1855
Show file tree
Hide file tree
Showing 11 changed files with 1,370 additions and 2,388 deletions.
62 changes: 4 additions & 58 deletions test/e2e/mock_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,13 @@

# Leaf with allowed values in properties

from unittest.mock import ANY

CREATED_MODIFIED_VALUES_EXPECTED = {"created_time": ANY, "modified_time": ANY}

# pylint: disable=duplicate-code
CATALOGUE_CATEGORY_POST_ALLOWED_VALUES = {
"name": "Category Allowed Values",
"is_leaf": True,
"properties": [
{
"name": "Property A",
"type": "number",
"unit": "mm",
"mandatory": False,
"allowed_values": {"type": "list", "values": [2, 4, 6]},
},
{
"name": "Property B",
"type": "string",
"unit": None,
"mandatory": True,
"allowed_values": {"type": "list", "values": ["red", "green"]},
},
],
}

# To be posted on CATALOGUE_CATEGORY_POST_ALLOWED_VALUES
CATALOGUE_ITEM_POST_ALLOWED_VALUES = {
"name": "Catalogue Item D",
"description": "This is Catalogue Item D",
"cost_gbp": 300.00,
"cost_to_rework_gbp": 120.99,
"days_to_replace": 1.5,
"days_to_rework": 3.0,
"drawing_number": "789xyz",
"is_obsolete": False,
"properties": [{"name": "Property A", "value": 4}, {"name": "Property B", "value": "red"}],
}
# pylint: disable=fixme
# TODO: Remove this file - replace by mock_data.py

ITEM_POST_ALLOWED_VALUES = {
"is_defective": False,
"warranty_end_date": "2015-11-15T23:59:59Z",
"serial_number": "xyz123",
"delivered_date": "2012-12-05T12:00:00Z",
"notes": "Test notes",
"properties": [{"name": "Property A", "value": 6}, {"name": "Property B", "value": "green"}],
}
from unittest.mock import ANY

ITEM_POST_ALLOWED_VALUES_EXPECTED = {
**ITEM_POST_ALLOWED_VALUES,
**CREATED_MODIFIED_VALUES_EXPECTED,
"id": ANY,
"purchase_order_number": None,
"usage_status": "New",
"usage_status_id": ANY,
"asset_number": None,
"properties": [
{"name": "Property A", "unit": "mm", "value": 6},
{"name": "Property B", "value": "green", "unit": None},
],
}
CREATED_MODIFIED_VALUES_EXPECTED = {"created_time": ANY, "modified_time": ANY}

SYSTEM_POST_A = {
"name": "System A",
Expand Down
39 changes: 20 additions & 19 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# pylint: disable=too-many-lines
"""
End-to-End tests for the catalogue category router.
"""

# Expect some duplicate code inside tests as the tests for the different entities can be very similar
# pylint: disable=too-many-lines
# pylint: disable=duplicate-code
# pylint: disable=too-many-public-methods

Expand Down 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 Expand Up @@ -406,9 +406,10 @@ 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 `CatalogueCategorySchema`. Does not need unit IDs
as they will be added automatically to check they are as expected.
:param expected_catalogue_category_get_data: Dictionary containing the expected catalogue category data returned
as would be required for a `CatalogueCategorySchema`. Does not need
unit IDs as they will be added automatically to check they are as
expected.
"""

assert self._get_response_catalogue_category.status_code == 200
Expand Down Expand Up @@ -596,7 +597,7 @@ class ListDSL(GetBreadcrumbsDSL):

def get_catalogue_categories(self, filters: dict) -> None:
"""
Gets a list catalogue categories with the given filters.
Gets a list of catalogue categories with the given filters.
:param filters: Filters to use in the request.
"""
Expand Down Expand Up @@ -627,8 +628,8 @@ def check_get_catalogue_categories_success(self, expected_catalogue_categories_g
Checks that a prior call to `get_catalogue_categories` gave a successful response with the expected data
returned.
:param expected_catalogue_categories_get_data: List of dictionaries containing the expected system data
returned as would be required for `CatalogueCategorySchema`'s.
:param expected_catalogue_categories_get_data: List of dictionaries containing the expected catalogue category
data returned as would be required for `CatalogueCategorySchema`'s.
"""

assert self._get_response_catalogue_category.status_code == 200
Expand Down Expand Up @@ -777,9 +778,9 @@ def check_patch_catalogue_category_response_success(self, expected_catalogue_cat
Checks that a prior call to `patch_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 `CatalogueCategorySchema`. Does not need unit IDs
as they will be added automatically to check they are as expected.
:param expected_catalogue_category_get_data: Dictionary containing the expected catalogue category data returned
as would be required for a `CatalogueCategorySchema`. Does not need unit IDs
as they will be added automatically to check they are as expected.
"""

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

0 comments on commit 4ae1855

Please sign in to comment.