Skip to content

Commit

Permalink
Address further comments of missed IDs and misnamed test #314
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Jul 26, 2024
1 parent 6dfdddc commit 20dab81
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
27 changes: 13 additions & 14 deletions test/e2e/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY,
CATALOGUE_CATEGORY_PROPERTY_DATA_BOOLEAN_MANDATORY,
CATALOGUE_CATEGORY_PROPERTY_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
UNIT_POST_DATA_MM)
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 All @@ -52,7 +52,7 @@ def setup(self, 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.
"""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`.
"""
Expand All @@ -62,7 +62,7 @@ def post_unit(self, unit_post_data: dict) -> None:

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
Stores a unit value and ID inside the `unit_value_id_dict` for tests that need to have a
non-existent or invalid unit ID.
:param unit_value: Value of the unit.
Expand All @@ -73,7 +73,7 @@ def add_unit_value_and_id(self, unit_value: str, unit_id: str) -> None:

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
Posts a catalogue category with the given data and returns the ID of the created catalogue category if
successful.
:param catalogue_category_data: Dictionary containing the basic catalogue category data as would be required
Expand Down Expand Up @@ -185,8 +185,8 @@ def test_create_with_valid_parent_id(self):
{**CATALOGUE_CATEGORY_GET_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, "parent_id": parent_id}
)

def test_create_with_non_leaf_parent(self):
"""Test creating a catalogue category with a non-leaf parent."""
def test_create_with_eaf_parent(self):
"""Test creating a catalogue category with a leaf parent."""

parent_id = self.post_catalogue_category(
{**CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_REQUIRED_VALUES_ONLY, "is_leaf": True}
Expand Down Expand Up @@ -247,14 +247,14 @@ def test_create_leaf_with_properties(self):
self.check_post_catalogue_category_success(CATALOGUE_CATEGORY_GET_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM)

def test_create_leaf_with_properties_with_non_existent_unit_id(self):
"""Test creating a leaf catalogue category with a property with a non-existent unit id provided."""
"""Test creating a leaf catalogue category with a property with a non-existent unit ID provided."""

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_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."""
"""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)
Expand Down Expand Up @@ -390,8 +390,7 @@ def get_catalogue_category(self, catalogue_category_id: str) -> None:

def check_get_catalogue_category_success(self, expected_catalogue_category_get_data: dict) -> None:
"""
Checks that a prior call to `get_catalogue_category` gave a successful response with the expected data
returned.
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`.
Expand Down Expand Up @@ -871,7 +870,7 @@ def test_partial_update_parent_id_to_child_of_self(self):
)

def test_partial_update_parent_id_to_leaf(self):
"""Test updating the `parent_id` of a catalogue category to the id of a leaf catalogue category."""
"""Test updating the `parent_id` of a catalogue category to the ID of a leaf catalogue category."""

parent_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES)
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_LEAF_REQUIRED_VALUES_ONLY)
Expand Down Expand Up @@ -1114,7 +1113,7 @@ def test_partial_update_leaf_with_properties_with_non_existent_unit_id(self):
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."""
"""Test updating a leaf catalogue category's properties to have a property with an invalid unit ID provided."""

self.add_unit_value_and_id("mm", "invalid-id")
catalogue_category_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_LEAF_NO_PARENT_NO_PROPERTIES)
Expand Down
15 changes: 9 additions & 6 deletions test/e2e/test_catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"""
from test.conftest import add_ids_to_properties
from test.e2e.conftest import replace_unit_values_with_ids_in_properties
from test.e2e.mock_schemas import (CATALOGUE_CATEGORY_POST_ALLOWED_VALUES,
CATALOGUE_ITEM_POST_ALLOWED_VALUES,
CATALOGUE_ITEM_POST_ALLOWED_VALUES_EXPECTED,
CREATED_MODIFIED_VALUES_EXPECTED,
SYSTEM_POST_A, USAGE_STATUS_POST_A,
USAGE_STATUS_POST_B)
from test.e2e.mock_schemas import (
CATALOGUE_CATEGORY_POST_ALLOWED_VALUES,
CATALOGUE_ITEM_POST_ALLOWED_VALUES,
CATALOGUE_ITEM_POST_ALLOWED_VALUES_EXPECTED,
CREATED_MODIFIED_VALUES_EXPECTED,
SYSTEM_POST_A,
USAGE_STATUS_POST_A,
USAGE_STATUS_POST_B,
)
from test.e2e.test_item import ITEM_POST
from test.e2e.test_unit import UNIT_POST_A, UNIT_POST_B
from unittest.mock import ANY
Expand Down
28 changes: 18 additions & 10 deletions test/unit/repositories/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,36 @@
CATALOGUE_CATEGORY_IN_DATA_LEAF_NO_PARENT_WITH_PROPERTIES_MM,
CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A,
CATALOGUE_CATEGORY_IN_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_B,
CATALOGUE_CATEGORY_PROPERTY_IN_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT)
CATALOGUE_CATEGORY_PROPERTY_IN_DATA_NUMBER_NON_MANDATORY_WITH_MM_UNIT,
)
from test.unit.repositories.conftest import RepositoryTestHelpers
from test.unit.repositories.test_utils import (
MOCK_BREADCRUMBS_QUERY_RESULT_LESS_THAN_MAX_LENGTH,
MOCK_MOVE_QUERY_RESULT_INVALID, MOCK_MOVE_QUERY_RESULT_VALID)
MOCK_MOVE_QUERY_RESULT_INVALID,
MOCK_MOVE_QUERY_RESULT_VALID,
)
from test.unit.services.test_catalogue_item import CATALOGUE_ITEM_A_INFO
from typing import Optional
from unittest.mock import MagicMock, Mock, call, patch

import pytest
from bson import ObjectId

from inventory_management_system_api.core.custom_object_id import \
CustomObjectId
from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.exceptions import (
ChildElementsExistError, DuplicateRecordError, InvalidActionError,
InvalidObjectIdError, MissingRecordError)
ChildElementsExistError,
DuplicateRecordError,
InvalidActionError,
InvalidObjectIdError,
MissingRecordError,
)
from inventory_management_system_api.models.catalogue_category import (
CatalogueCategoryIn, CatalogueCategoryOut, CatalogueCategoryPropertyIn,
CatalogueCategoryPropertyOut)
from inventory_management_system_api.repositories.catalogue_category import \
CatalogueCategoryRepo
CatalogueCategoryIn,
CatalogueCategoryOut,
CatalogueCategoryPropertyIn,
CatalogueCategoryPropertyOut,
)
from inventory_management_system_api.repositories.catalogue_category import CatalogueCategoryRepo


class CatalogueCategoryRepoDSL:
Expand Down
14 changes: 7 additions & 7 deletions test/unit/repositories/test_catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
Unit tests for the `CatalogueItemRepo` repository.
"""

from test.unit.repositories.mock_models import (MOCK_CREATED_MODIFIED_TIME,
MOCK_PROPERTY_A_INFO)
from test.unit.repositories.mock_models import MOCK_CREATED_MODIFIED_TIME, MOCK_PROPERTY_A_INFO
from test.unit.repositories.test_item import FULL_ITEM_INFO
from unittest.mock import MagicMock, patch

import pytest
from bson import ObjectId
from pymongo.cursor import Cursor

from inventory_management_system_api.core.custom_object_id import \
CustomObjectId
from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.exceptions import (
ChildElementsExistError, InvalidObjectIdError, MissingRecordError)
from inventory_management_system_api.models.catalogue_item import (
CatalogueItemIn, CatalogueItemOut, PropertyIn)
ChildElementsExistError,
InvalidObjectIdError,
MissingRecordError,
)
from inventory_management_system_api.models.catalogue_item import CatalogueItemIn, CatalogueItemOut, PropertyIn

FULL_CATALOGUE_ITEM_A_INFO = {
"name": "Catalogue Item A",
Expand Down

0 comments on commit 20dab81

Please sign in to comment.