Skip to content

Commit

Permalink
Refactor items update e2e tests and add some missing tests to catalog…
Browse files Browse the repository at this point in the history
…ue items #347
  • Loading branch information
joelvdavies committed Aug 9, 2024
1 parent d712038 commit a186bc2
Show file tree
Hide file tree
Showing 4 changed files with 525 additions and 1,100 deletions.
13 changes: 6 additions & 7 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
CATALOGUE_ITEM_DATA_REQUIRED_VALUES_ONLY,
MANUFACTURER_POST_DATA_REQUIRED_VALUES_ONLY,
UNIT_POST_DATA_MM,
)
MANUFACTURER_POST_DATA_REQUIRED_VALUES_ONLY, UNIT_POST_DATA_MM)
from typing import Optional

import pytest
from bson import ObjectId
from fastapi.testclient import TestClient
from httpx import Response

from inventory_management_system_api.core.consts import BREADCRUMBS_TRAIL_MAX_LENGTH
from inventory_management_system_api.core.consts import \
BREADCRUMBS_TRAIL_MAX_LENGTH


class CreateDSL:
Expand Down Expand Up @@ -777,9 +776,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
89 changes: 72 additions & 17 deletions test/e2e/test_catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,32 @@ def test_create_with_boolean_property_with_invalid_value_type(self):
"'. Expected type: boolean.",
)

def test_create_with_invalid_string_allowed_values_list_value(self):
"""Test creating a catalogue item with an invalid value for a string property with an allowed values list."""
def test_create_with_allowed_values_list(self):
"""Test creating a catalogue item with properties that have allowed values lists."""

self.post_catalogue_item_and_prerequisites_with_given_properties(
catalogue_category_properties_data=[
CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST,
CATALOGUE_CATEGORY_PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST,
],
catalogue_item_properties_data=[
PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_1,
PROPERTY_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_VALUE1,
],
)
self.check_post_catalogue_item_success(
{
**CATALOGUE_ITEM_GET_DATA_WITH_ALL_PROPERTIES,
"properties": [
PROPERTY_GET_DATA_NUMBER_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_1,
PROPERTY_GET_DATA_STRING_NON_MANDATORY_WITH_ALLOWED_VALUES_LIST_VALUE1,
],
}
)

def test_create_with_string_property_with_allowed_values_list_with_invalid_value(self):
"""Test creating a catalogue item with a string property with an allowed values list while giving it a value not
in the list."""

self.post_catalogue_item_and_prerequisites_with_allowed_values(
"string", {"type": "list", "values": ["value1"]}, "value2"
Expand All @@ -494,8 +518,9 @@ def test_create_with_invalid_string_allowed_values_list_value(self):
"Expected one of value1.",
)

def test_create_with_invalid_string_allowed_values_list_type(self):
"""Test creating a catalogue item with an invalid type for a string property with an allowed values list."""
def test_create_with_string_property_with_allowed_values_list_with_invalid_type(self):
"""Test creating a catalogue item with a string property with an allowed values list while giving it a value
with an incorrect type."""

self.post_catalogue_item_and_prerequisites_with_allowed_values(
"string", {"type": "list", "values": ["value1"]}, 42
Expand All @@ -506,17 +531,19 @@ def test_create_with_invalid_string_allowed_values_list_type(self):
"Expected type: string.",
)

def test_create_with_invalid_number_allowed_values_list_value(self):
"""Test creating a catalogue item with an invalid value for a number property with an allowed values list."""
def test_create_with_number_property_with_allowed_values_list_with_invalid_value(self):
"""Test creating a catalogue item with a number property with an allowed values list while giving it a value not
in the list."""

self.post_catalogue_item_and_prerequisites_with_allowed_values("number", {"type": "list", "values": [1]}, 2)
self.check_post_catalogue_item_failed_with_detail(
422,
f"Invalid value for property with ID '{self.property_name_id_dict['property']}'. Expected one of 1.",
)

def test_create_with_invalid_number_allowed_values_list_type(self):
"""Test creating a catalogue item with an invalid type for a number property with an allowed values list."""
def test_create_with_number_property_with_allowed_values_list_with_invalid_type(self):
"""Test creating a catalogue item with a number property with an allowed values list while giving it a value
with an incorrect type."""

self.post_catalogue_item_and_prerequisites_with_allowed_values(
"number", {"type": "list", "values": [1]}, "test"
Expand Down Expand Up @@ -748,13 +775,13 @@ def patch_catalogue_item(self, catalogue_item_id: str, catalogue_item_update_dat
"""
Updates a catalogue item with the given ID.
:param catalogue_item_id: ID of the catalogue category to patch.
:param catalogue_item_id: ID of the catalogue item to patch.
:param catalogue_item_update_data: Dictionary containing the basic patch data as would be required for a
`CatalogueItemPatchSchema` but with any `id`'s replaced by the `name` value
in its properties as the IDs will be added automatically.
"""

# Replace any unit values with unit ids
# Replace any property names with ids
catalogue_item_update_data = E2ETestHelpers.replace_property_names_with_ids_in_properties(
catalogue_item_update_data, self.property_name_id_dict
)
Expand Down Expand Up @@ -793,10 +820,10 @@ def check_patch_catalogue_item_response_success(self, expected_catalogue_item_ge
Checks that a prior call to `patch_catalogue_item` gave a successful response with the expected data
returned.
:param expected_catalogue_item_get_data: Dictionary containing the expected system data returned as would
be required for a `CatalogueItemSchema`. Does not need mandatory IDs
(e.g. manufacturer_id) as they will be added automatically to check
they are as expected.
: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 automatically to check they are
as expected.
"""

assert self._patch_response_catalogue_item.status_code == 200
Expand Down Expand Up @@ -1337,7 +1364,7 @@ def test_partial_update_properties_with_boolean_property_with_invalid_value_type
)

def test_partial_update_properties_with_allowed_values_list(self):
"""Test updating the `properties` of a catalogue item that have a list of allowed values."""
"""Test updating the `properties` of a catalogue item that has allowed values lists."""

catalogue_item_id = self.post_catalogue_item_and_prerequisites_with_given_properties(
catalogue_category_properties_data=[
Expand Down Expand Up @@ -1366,7 +1393,7 @@ def test_partial_update_properties_with_allowed_values_list(self):
}
)

def test_partial_update_properties_with_string_allowed_values_list_to_invalid_value(self):
def test_partial_update_string_property_with_allowed_values_list_to_invalid_value(self):
"""Test updating the value of a string property with an allowed values list to be a value not in the list."""

catalogue_item_id = self.post_catalogue_item_and_prerequisites_with_allowed_values(
Expand All @@ -1380,7 +1407,21 @@ def test_partial_update_properties_with_string_allowed_values_list_to_invalid_va
"value2, value3.",
)

def test_partial_update_properties_with_number_allowed_values_list_to_invalid_value(self):
def test_partial_update_string_property_with_allowed_values_list_to_invalid_value_type(self):
"""Test updating the value of a string property with an allowed values list to be the wrong type."""

catalogue_item_id = self.post_catalogue_item_and_prerequisites_with_allowed_values(
"string", {"type": "list", "values": ["value1"]}, "value1"
)

self.patch_catalogue_item(catalogue_item_id, {"properties": [{"name": "property", "value": 42}]})
self.check_patch_catalogue_item_failed_with_detail(
422,
f"Invalid value type for property with ID '{self.property_name_id_dict['property']}'. "
"Expected type: string.",
)

def test_partial_update_number_property_with_allowed_values_list_to_invalid_value(self):
"""Test updating the value of a number property with an allowed values list to be a value not in the list."""

catalogue_item_id = self.post_catalogue_item_and_prerequisites_with_allowed_values(
Expand All @@ -1393,6 +1434,20 @@ def test_partial_update_properties_with_number_allowed_values_list_to_invalid_va
f"Invalid value for property with ID '{self.property_name_id_dict['property']}'. Expected one of 1, 2, 3.",
)

def test_partial_update_number_property_with_allowed_values_list_to_invalid_value_type(self):
"""Test updating the value of a number property with an allowed values list to be the wrong type."""

catalogue_item_id = self.post_catalogue_item_and_prerequisites_with_allowed_values(
"number", {"type": "list", "values": [1]}, 1
)

self.patch_catalogue_item(catalogue_item_id, {"properties": [{"name": "property", "value": "2"}]})
self.check_patch_catalogue_item_failed_with_detail(
422,
f"Invalid value type for property with ID '{self.property_name_id_dict['property']}'. "
"Expected type: number.",
)

def test_partial_update_properties_with_children(self):
"""Test updating the `properties` of a catalogue item when it has children."""

Expand Down
Loading

0 comments on commit a186bc2

Please sign in to comment.