Skip to content

Commit

Permalink
Rename failed_with_message to failed_with_detail to match check #314
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Jul 9, 2024
1 parent 0420f58 commit c3c20db
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 60 deletions.
72 changes: 36 additions & 36 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def check_post_catalogue_category_success(self, expected_catalogue_category_get_
assert self._post_response.status_code == 201
assert self._post_response.json() == expected_catalogue_category_get_data

def check_post_catalogue_category_failed_with_message(self, status_code: int, detail: str) -> None:
def check_post_catalogue_category_failed_with_detail(self, status_code: int, detail: str) -> None:
"""
Checks that a prior call to `post_catalogue_category` gave a failed response with the expected code and
error message.
Expand Down Expand Up @@ -194,7 +194,7 @@ def test_create_with_non_leaf_parent(self):
self.post_catalogue_category(
{**CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, "parent_id": parent_id}
)
self.check_post_catalogue_category_failed_with_message(
self.check_post_catalogue_category_failed_with_detail(
409, "Adding a catalogue category to a leaf parent catalogue category is not allowed"
)

Expand All @@ -204,7 +204,7 @@ def test_create_with_non_existent_parent_id(self):
self.post_catalogue_category(
{**CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, "parent_id": str(ObjectId())}
)
self.check_post_catalogue_category_failed_with_message(
self.check_post_catalogue_category_failed_with_detail(
422, "The specified parent catalogue category does not exist"
)

Expand All @@ -214,7 +214,7 @@ def test_create_with_invalid_parent_id(self):
self.post_catalogue_category(
{**CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, "parent_id": "invalid-id"}
)
self.check_post_catalogue_category_failed_with_message(
self.check_post_catalogue_category_failed_with_detail(
422, "The specified parent catalogue category does not exist"
)

Expand All @@ -229,7 +229,7 @@ def test_create_with_duplicate_name_within_parent(self):
self.post_catalogue_category(
{**CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, "parent_id": parent_id}
)
self.check_post_catalogue_category_failed_with_message(
self.check_post_catalogue_category_failed_with_detail(
409, "A catalogue category with the same name already exists within the parent catalogue category"
)

Expand All @@ -251,14 +251,14 @@ def test_create_leaf_with_properties_with_non_existent_unit_id(self):

self.add_unit_value_and_id("mm", str(ObjectId()))
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")
self.check_post_catalogue_category_failed_with_detail(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_NO_PARENT_WITH_PROPERTIES_MM)
self.check_post_catalogue_category_failed_with_message(422, "The specified unit does not exist")
self.check_post_catalogue_category_failed_with_detail(422, "The specified unit does not exist")

def test_create_leaf_with_duplicate_properties(self):
"""Test creating a leaf catalogue category with duplicate properties provided."""
Expand All @@ -268,7 +268,7 @@ def test_create_leaf_with_duplicate_properties(self):
self.post_catalogue_category(
{**CATALOGUE_CATEGORY_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM, "properties": [property_data, property_data]}
)
self.check_post_catalogue_category_failed_with_message(
self.check_post_catalogue_category_failed_with_detail(
422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"]}"
)

Expand Down Expand Up @@ -400,7 +400,7 @@ def check_get_catalogue_category_success(self, expected_catalogue_category_get_d
assert self._get_response.status_code == 200
assert self._get_response.json() == expected_catalogue_category_get_data

def check_get_catalogue_category_failed_with_message(self, status_code: int, detail: str) -> None:
def check_get_catalogue_category_failed_with_detail(self, status_code: int, detail: str) -> None:
"""
Checks that a prior call to `get_catalogue_category` gave a failed response with the expected code and error
message.
Expand Down Expand Up @@ -428,13 +428,13 @@ def test_get_with_non_existent_id(self):
"""Test getting a catalogue category with a non-existent id."""

self.get_catalogue_category(str(ObjectId()))
self.check_get_catalogue_category_failed_with_message(404, "Catalogue category not found")
self.check_get_catalogue_category_failed_with_detail(404, "Catalogue category not found")

def test_get_with_invalid_id(self):
"""Test getting a catalogue category with an invalid id."""

self.get_catalogue_category("invalid-id")
self.check_get_catalogue_category_failed_with_message(404, "Catalogue category not found")
self.check_get_catalogue_category_failed_with_detail(404, "Catalogue category not found")


class GetBreadcrumbsDSL(GetDSL):
Expand Down Expand Up @@ -509,7 +509,7 @@ def check_get_catalogue_categories_breadcrumbs_success(
"full_trail": expected_full_trail,
}

def check_get_catalogue_categories_breadcrumbs_failed_with_message(self, status_code: int, detail: str) -> None:
def check_get_catalogue_categories_breadcrumbs_failed_with_detail(self, status_code: int, detail: str) -> None:
"""Checks that a prior call to `get_catalogue_category_breadcrumbs` gave a failed response with the expected
code and error message.
Expand Down Expand Up @@ -564,13 +564,13 @@ def test_get_breadcrumbs_with_non_existent_id(self):
"""Test getting a system's breadcrumbs when given a non-existent system id."""

self.get_catalogue_category_breadcrumbs(str(ObjectId()))
self.check_get_catalogue_categories_breadcrumbs_failed_with_message(404, "Catalogue category not found")
self.check_get_catalogue_categories_breadcrumbs_failed_with_detail(404, "Catalogue category not found")

def test_get_breadcrumbs_with_invalid_id(self):
"""Test getting a system's breadcrumbs when given an invalid system id."""

self.get_catalogue_category_breadcrumbs("invalid_id")
self.check_get_catalogue_categories_breadcrumbs_failed_with_message(404, "Catalogue category not found")
self.check_get_catalogue_categories_breadcrumbs_failed_with_detail(404, "Catalogue category not found")


class ListDSL(GetBreadcrumbsDSL):
Expand Down Expand Up @@ -788,7 +788,7 @@ def check_patch_catalogue_category_response_success(self, expected_catalogue_cat

E2ETestHelpers.check_created_and_modified_times_updated_correctly(self._post_response, self._patch_response)

def check_patch_catalogue_category_failed_with_message(self, status_code: int, detail: str) -> None:
def check_patch_catalogue_category_failed_with_detail(self, status_code: int, detail: str) -> None:
"""
Checks that a prior call to `patch_catalogue_category` gave a failed response with the expected code and
error message.
Expand Down Expand Up @@ -857,7 +857,7 @@ def test_partial_update_parent_id_to_one_with_a_duplicate_name(self):
)

self.patch_catalogue_category(catalogue_category_id, {"parent_id": parent_id})
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
409, "A catalogue category with the same name already exists within the parent catalogue category"
)

Expand All @@ -866,7 +866,7 @@ def test_partial_update_parent_id_to_child_of_self(self):

catalogue_category_ids = self.post_nested_catalogue_categories(2)
self.patch_catalogue_category(catalogue_category_ids[0], {"parent_id": catalogue_category_ids[1]})
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
422, "Cannot move a catalogue category to one of its own children"
)

Expand All @@ -877,7 +877,7 @@ def test_partial_update_parent_id_to_leaf(self):
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_LEAF_REQUIRED_VALUES_ONLY)

self.patch_catalogue_category(catalogue_category_id, {"parent_id": parent_id})
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
409, "Adding a catalogue category to a leaf parent catalogue category is not allowed"
)

Expand All @@ -886,7 +886,7 @@ def test_partial_update_parent_id_to_non_existent(self):

catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY)
self.patch_catalogue_category(catalogue_category_id, {"parent_id": str(ObjectId())})
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
422, "The specified parent catalogue category does not exist"
)

Expand All @@ -895,7 +895,7 @@ def test_partial_update_parent_id_to_invalid_id(self):

catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY)
self.patch_catalogue_category(catalogue_category_id, {"parent_id": "invalid-id"})
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
422, "The specified parent catalogue category does not exist"
)

Expand All @@ -909,7 +909,7 @@ def test_partial_update_name_to_duplicate(self):
self.patch_catalogue_category(
catalogue_category_id, {"name": CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A["name"]}
)
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
409, "A catalogue category with the same name already exists within the parent catalogue category"
)

Expand Down Expand Up @@ -982,7 +982,7 @@ def test_partial_update_non_leaf_to_leaf_when_has_child_catalogue_category(self)

self.patch_catalogue_category(catalogue_category_id, {"is_leaf": True})

self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
409, "Catalogue category has child elements and cannot be updated"
)

Expand Down Expand Up @@ -1027,7 +1027,7 @@ def test_partial_update_leaf_to_non_leaf_when_has_child_catalogue_item(self):

self.patch_catalogue_category(catalogue_category_id, {"is_leaf": False})

self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
409, "Catalogue category has child elements and cannot be updated"
)

Expand All @@ -1039,7 +1039,7 @@ def test_partial_update_leaf_properties_when_has_child_catalogue_item(self):

self.patch_catalogue_category(catalogue_category_id, {"properties": []})

self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
409, "Catalogue category has child elements and cannot be updated"
)

Expand Down Expand Up @@ -1082,7 +1082,7 @@ def test_partial_update_is_leaf_with_child_catalogue_category(self):
)

self.patch_catalogue_category(catalogue_category_id, {"is_leaf": True})
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
409, "Catalogue category has child elements and cannot be updated"
)

Expand Down Expand Up @@ -1111,7 +1111,7 @@ def test_partial_update_leaf_with_properties_with_non_existent_unit_id(self):
self.patch_catalogue_category(
catalogue_category_id, {"properties": [CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT]}
)
self.check_patch_catalogue_category_failed_with_message(422, "The specified unit does not exist")
self.check_patch_catalogue_category_failed_with_detail(422, "The specified unit does not exist")

def test_partial_update_leaf_with_properties_with_invalid_unit_id(self):
"""Test updating a leaf catalogue category's properties to have a property with an invalid unit id provided."""
Expand All @@ -1121,7 +1121,7 @@ def test_partial_update_leaf_with_properties_with_invalid_unit_id(self):
self.patch_catalogue_category(
catalogue_category_id, {"properties": [CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT]}
)
self.check_patch_catalogue_category_failed_with_message(422, "The specified unit does not exist")
self.check_patch_catalogue_category_failed_with_detail(422, "The specified unit does not exist")

def test_partial_update_leaf_with_duplicate_properties(self):
"""Test updating a leaf catalogue category with duplicate properties provided."""
Expand All @@ -1130,7 +1130,7 @@ def test_partial_update_leaf_with_duplicate_properties(self):

catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES)
self.patch_catalogue_category(catalogue_category_id, {"properties": [property_data, property_data]})
self.check_patch_catalogue_category_failed_with_message(
self.check_patch_catalogue_category_failed_with_detail(
422, f"Duplicate property name: {CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY["name"]}"
)

Expand Down Expand Up @@ -1253,13 +1253,13 @@ def test_partial_update_with_non_existent_id(self):
"""Test updating a non-existent catalogue category."""

self.patch_catalogue_category(str(ObjectId()), {})
self.check_patch_catalogue_category_failed_with_message(404, "Catalogue category not found")
self.check_patch_catalogue_category_failed_with_detail(404, "Catalogue category not found")

def test_partial_update_invalid_id(self):
"""Test updating a catalogue category with an invalid id."""

self.patch_catalogue_category("invalid-id", {})
self.check_patch_catalogue_category_failed_with_message(404, "Catalogue category not found")
self.check_patch_catalogue_category_failed_with_detail(404, "Catalogue category not found")


class DeleteDSL(UpdateDSL):
Expand All @@ -1282,7 +1282,7 @@ def check_delete_catalogue_category_success(self) -> None:

assert self._delete_response.status_code == 204

def check_delete_catalogue_category_failed_with_message(self, status_code: int, detail: str) -> None:
def check_delete_catalogue_category_failed_with_detail(self, status_code: int, detail: str) -> None:
"""
Checks that a prior call to `delete_catalogue_category` gave a failed response with the expected code and
error message.
Expand All @@ -1306,14 +1306,14 @@ def test_delete(self):
self.check_delete_catalogue_category_success()

self.get_catalogue_category(catalogue_category_id)
self.check_get_catalogue_category_failed_with_message(404, "Catalogue category not found")
self.check_get_catalogue_category_failed_with_detail(404, "Catalogue category not found")

def test_delete_with_child_catalogue_category(self):
"""Test deleting a catalogue category with a child catalogue category."""

catalogue_category_ids = self.post_nested_catalogue_categories(2)
self.delete_catalogue_category(catalogue_category_ids[0])
self.check_delete_catalogue_category_failed_with_message(
self.check_delete_catalogue_category_failed_with_detail(
409, "Catalogue category has child elements and cannot be deleted"
)

Expand All @@ -1324,18 +1324,18 @@ def test_delete_with_child_item(self):
self.post_child_catalogue_item()

self.delete_catalogue_category(catalogue_category_id)
self.check_delete_catalogue_category_failed_with_message(
self.check_delete_catalogue_category_failed_with_detail(
409, "Catalogue category has child elements and cannot be deleted"
)

def test_delete_with_non_existent_id(self):
"""Test deleting a non-existent catalogue category."""

self.delete_catalogue_category(str(ObjectId()))
self.check_delete_catalogue_category_failed_with_message(404, "Catalogue category not found")
self.check_delete_catalogue_category_failed_with_detail(404, "Catalogue category not found")

def test_delete_with_invalid_id(self):
"""Test deleting a catalogue category with an invalid id."""

self.delete_catalogue_category("invalid_id")
self.check_delete_catalogue_category_failed_with_message(404, "Catalogue category not found")
self.check_delete_catalogue_category_failed_with_detail(404, "Catalogue category not found")
Loading

0 comments on commit c3c20db

Please sign in to comment.