Skip to content

Commit 9ea1038

Browse files
committed
Address comments from CC repo unit tests PR #305
1 parent 2d2d472 commit 9ea1038

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

inventory_management_system_api/repositories/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _has_child_elements(self, system_id: CustomObjectId, session: ClientSession
202202
203203
:param system_id: ID of the system to check
204204
:param session: PyMongo ClientSession to use for database operations
205-
:return: True if the system has child elements, False otherwise
205+
:return: `True` if the system has child elements, `False` otherwise
206206
"""
207207
logger.info("Checking if system with ID '%s' has child elements", str(system_id))
208208

test/e2e/test_catalogue_category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def test_partial_update_parent_id_to_one_with_a_duplicate_name(self):
842842
"""Test updating the parent_id of a catalogue category so that its name conflicts with one already in that
843843
other catalogue category."""
844844

845-
# System with child
845+
# Catalogue category with child
846846
parent_id = self.post_catalogue_category(CATALOGUE_CATEGORY_POST_DATA_NON_LEAF_NO_PARENT_NO_PROPERTIES_A)
847847
self.post_catalogue_category(
848848
{

test/unit/repositories/test_catalogue_category.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def setup(self, database_mock):
7272

7373
# Here we only wrap the utils so they keep their original functionality - this is done here
7474
# to avoid having to mock the code generation function as the output will be passed to
75-
# CatalogueCategoryOut with pydantic validation and so will error otherwise
75+
# `CatalogueCategoryOut` with pydantic validation and so will error otherwise
7676
with patch("inventory_management_system_api.repositories.catalogue_category.utils") as mock_utils:
7777
self.mock_utils = mock_utils
7878
yield
@@ -97,7 +97,7 @@ def check_has_child_elements_performed_expected_calls(self, expected_catalogue_c
9797
"""
9898
Checks that a call to `has_child_elements` performed the expected function calls.
9999
100-
:param expected_catalogue_category_id: Expected catalogue category id used in the database calls.
100+
:param expected_catalogue_category_id: Expected `catalogue_category_id` used in the database calls.
101101
"""
102102

103103
self.catalogue_categories_collection.find_one.assert_called_once_with(
@@ -137,7 +137,7 @@ def mock_create(
137137

138138
inserted_catalogue_category_id = CustomObjectId(str(ObjectId()))
139139

140-
# Pass through CatalogueCategoryIn first as need creation and modified times
140+
# Pass through `CatalogueCategoryIn` first as need creation and modified times
141141
self._catalogue_category_in = CatalogueCategoryIn(**catalogue_category_in_data)
142142

143143
self._expected_catalogue_category_out = CatalogueCategoryOut(
@@ -177,7 +177,7 @@ def mock_create(
177177
)
178178

179179
def call_create(self) -> None:
180-
"""Calls the CatalogueCategoryRepo `create` method with the appropriate data from a prior call to
180+
"""Calls the `CatalogueCategoryRepo` `create` method with the appropriate data from a prior call to
181181
`mock_create`"""
182182

183183
self._created_catalogue_category = self.catalogue_category_repository.create(
@@ -186,7 +186,7 @@ def call_create(self) -> None:
186186

187187
def call_create_expecting_error(self, error_type: type[BaseException]) -> None:
188188
"""
189-
Calls the CatalogueCategoryRepo `create` method with the appropriate data from a prior call to `mock_create`
189+
Calls the `CatalogueCategoryRepo` `create` method with the appropriate data from a prior call to `mock_create`
190190
while expecting an error to be raised
191191
192192
:param error_type: Expected exception to be raised.
@@ -280,7 +280,7 @@ def test_create_with_parent(self):
280280
self.check_create_success()
281281

282282
def test_create_with_non_existent_parent_id(self):
283-
"""Test creating a catalogue category with a non existent parent_id."""
283+
"""Test creating a catalogue category with a non-existent `parent_id`."""
284284

285285
parent_id = str(ObjectId())
286286

@@ -490,7 +490,7 @@ def mock_list(self, catalogue_categories_in_data: list[dict]) -> None:
490490
"""Mocks database methods appropriately to test the `list` repo method
491491
492492
:param catalogue_categories_in_data: List of dictionaries containing the catalogue category data as would be
493-
required for a `CatalogueCategoryIn` database model (i.e. no id or created
493+
required for a `CatalogueCategoryIn` database model (i.e. no ID or created
494494
and modified times required)
495495
"""
496496

@@ -508,7 +508,7 @@ def mock_list(self, catalogue_categories_in_data: list[dict]) -> None:
508508

509509
def call_list(self, parent_id: Optional[str]) -> None:
510510
"""
511-
Calls the CatalogueCategoryRepo `list` method.
511+
Calls the `CatalogueCategoryRepo` `list` method.
512512
513513
:param parent_id: ID of the parent catalogue category to query by, or `None`.
514514
"""
@@ -534,7 +534,7 @@ class TestList(ListDSL):
534534
"""Tests for listing Catalogue Category's."""
535535

536536
def test_list(self):
537-
"""Test listing all Catalogue Categories."""
537+
"""Test listing all catalogue categories."""
538538

539539
self.mock_list(
540540
[
@@ -546,7 +546,7 @@ def test_list(self):
546546
self.check_list_success()
547547

548548
def test_list_with_parent_id_filter(self):
549-
"""Test listing all Catalogue Categories with a given parent_id."""
549+
"""Test listing all catalogue categories with a given `parent_id`."""
550550

551551
self.mock_list(
552552
[
@@ -558,7 +558,7 @@ def test_list_with_parent_id_filter(self):
558558
self.check_list_success()
559559

560560
def test_list_with_null_parent_id_filter(self):
561-
"""Test listing all Catalogue Categories with a 'null' parent_id."""
561+
"""Test listing all catalogue categories with a 'null' parent_id."""
562562

563563
self.mock_list(
564564
[
@@ -570,7 +570,7 @@ def test_list_with_null_parent_id_filter(self):
570570
self.check_list_success()
571571

572572
def test_list_with_parent_id_with_no_results(self):
573-
"""Test listing all Catalogue Categories with a `parent_id` filter returning no results."""
573+
"""Test listing all catalogue categories with a `parent_id` filter returning no results."""
574574

575575
self.mock_list([])
576576
self.call_list(parent_id=str(ObjectId()))
@@ -625,7 +625,7 @@ def mock_update(
625625
:param duplicate_catalogue_category_in_data: Either `None` or a dictionary containing the data for a duplicate
626626
catalogue category as would be required for a `CatalogueCategoryIn`
627627
database model.
628-
:param valid_move_result: Whether to mock in a valid or invalid move result i.e. when True will simulating
628+
:param valid_move_result: Whether to mock in a valid or invalid move result i.e. when `True` will simulate
629629
moving the catalogue category to one of its own children.
630630
"""
631631
self.set_update_data(new_catalogue_category_in_data)
@@ -700,7 +700,7 @@ def mock_update(
700700

701701
def call_update(self, catalogue_category_id: str) -> None:
702702
"""
703-
Calls the CatalogueCategoryRepo `update` method with the appropriate data from a prior call to `mock_update`
703+
Calls the `CatalogueCategoryRepo` `update` method with the appropriate data from a prior call to `mock_update`
704704
(or`set_update_data`).
705705
706706
:param catalogue_category_id: ID of the catalogue category to be updated.
@@ -713,7 +713,7 @@ def call_update(self, catalogue_category_id: str) -> None:
713713

714714
def call_update_expecting_error(self, catalogue_category_id: str, error_type: type[BaseException]) -> None:
715715
"""
716-
Calls the CatalogueCategoryRepo `update` method with the appropriate data from a prior call to `mock_update`
716+
Calls the `CatalogueCategoryRepo` `update` method with the appropriate data from a prior call to `mock_update`
717717
(or `set_update_data`) while expecting an error to be raised.
718718
719719
:param catalogue_category_id: ID of the catalogue category to be updated.
@@ -1024,7 +1024,7 @@ def call_delete(self, catalogue_category_id: str) -> None:
10241024

10251025
def call_delete_expecting_error(self, catalogue_category_id: str, error_type: type[BaseException]) -> None:
10261026
"""
1027-
Calls the CatalogueCategoryRepo `delete` method while expecting an error to be raised.
1027+
Calls the `CatalogueCategoryRepo` `delete` method while expecting an error to be raised.
10281028
10291029
:param catalogue_category_id: ID of the catalogue category to be deleted.
10301030
:param error_type: Expected exception to be raised.

test/unit/repositories/test_system.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def setup(self, database_mock):
5959
self.mock_session = MagicMock()
6060

6161
# Here we only wrap the utils so they keep their original functionality - this is done here
62-
# to avoid having to mock the code generation function as the output will be passed to SystemOut
62+
# to avoid having to mock the code generation function as the output will be passed to `SystemOut`
6363
# with pydantic validation and so will error otherwise
6464
with patch("inventory_management_system_api.repositories.system.utils") as mock_utils:
6565
self.mock_utils = mock_utils
@@ -71,8 +71,8 @@ def mock_has_child_elements(
7171
"""
7272
Mocks database methods appropriately for when the `_has_child_elements` repo method will be called.
7373
74-
:param child_system_data: Dictionary containing a child system's data (or None).
75-
:param child_catalogue_item_data: Dictionary containing a child Item's data (or None).
74+
:param child_system_data: Dictionary containing a child system's data (or `None`).
75+
:param child_catalogue_item_data: Dictionary containing a child Item's data (or `None`).
7676
"""
7777

7878
self._mock_child_system_data = child_system_data
@@ -85,7 +85,7 @@ def check_has_child_elements_performed_expected_calls(self, expected_system_id:
8585
"""
8686
Checks that a call to `_has_child_elements` performed the expected function calls.
8787
88-
:param expected_system_id: Expected system id used in the database calls.
88+
:param expected_system_id: Expected `system_id` used in the database calls.
8989
"""
9090

9191
self.systems_collection.find_one.assert_called_once_with(
@@ -101,7 +101,7 @@ def mock_is_duplicate_system(self, duplicate_system_in_data: Optional[dict] = No
101101
"""
102102
Mocks database methods appropriately for when the `_is_duplicate_system` repo method will be called.
103103
104-
:param duplicate_system_in_data: Either None or a dictionary containing system data for a duplicate system.
104+
:param duplicate_system_in_data: Either `None` or a dictionary containing system data for a duplicate system.
105105
"""
106106

107107
RepositoryTestHelpers.mock_find_one(
@@ -117,10 +117,10 @@ def get_is_duplicate_system_expected_find_one_call(
117117
self, system_in: SystemIn, expected_system_id: Optional[CustomObjectId]
118118
):
119119
"""
120-
Returns the expected find_one calls from that should occur when `_is_duplicate_system` is called.
120+
Returns the expected `find_one` calls from that should occur when `_is_duplicate_system` is called.
121121
122122
:param system_in: `SystemIn` model containing the data about the system.
123-
:param expected_system_id: Expected system_id provided to `is_duplicate_system`.
123+
:param expected_system_id: Expected `system_id` provided to `is_duplicate_system`.
124124
"""
125125

126126
return call(
@@ -158,7 +158,7 @@ def mock_create(
158158
"""
159159
inserted_system_id = CustomObjectId(str(ObjectId()))
160160

161-
# Pass through SystemIn first as need creation and modified times
161+
# Pass through `SystemIn` first as need creation and modified times
162162
self._system_in = SystemIn(**system_in_data)
163163

164164
self._expected_system_out = SystemOut(**self._system_in.model_dump(), id=inserted_system_id)
@@ -377,7 +377,7 @@ def test_get_with_invalid_id(self):
377377

378378

379379
class GetBreadcrumbsDSL(SystemRepoDSL):
380-
"""Base class for `get_breadcrumbs` tests"""
380+
"""Base class for `get_breadcrumbs` tests."""
381381

382382
_breadcrumbs_query_result: list[dict]
383383
_mock_aggregation_pipeline = MagicMock()
@@ -386,10 +386,10 @@ class GetBreadcrumbsDSL(SystemRepoDSL):
386386
_obtained_breadcrumbs: MagicMock
387387

388388
def mock_breadcrumbs(self, breadcrumbs_query_result: list[dict]) -> None:
389-
"""Mocks database methods appropriately to test the `get_breadcrumbs` repo method
389+
"""Mocks database methods appropriately to test the `get_breadcrumbs` repo method.
390390
391391
:param breadcrumbs_query_result: List of dictionaries containing the breadcrumbs query result from the
392-
aggregation pipeline
392+
aggregation pipeline.
393393
"""
394394
self._breadcrumbs_query_result = breadcrumbs_query_result
395395
self._mock_aggregation_pipeline = MagicMock()
@@ -447,7 +447,7 @@ def mock_list(self, systems_in_data: list[dict]):
447447
"""Mocks database methods appropriately to test the `list` repo method.
448448
449449
:param systems_in_data: List of dictionaries containing the system data as would be required for a
450-
`SystemIn` database model (i.e. no id or created and modified times required).
450+
`SystemIn` database model (i.e. no ID or created and modified times required).
451451
"""
452452

453453
self._expected_systems_out = [
@@ -528,7 +528,7 @@ def set_update_data(self, new_system_in_data: dict):
528528
"""
529529
Assigns the update data to use during a call to `call_update`.
530530
531-
:param new_system_data: New system data as would be required for a SystemIn database model to supply to the
531+
:param new_system_data: New system data as would be required for a `SystemIn` database model to supply to the
532532
`SystemRepo` `update` method.
533533
"""
534534
self._system_in = SystemIn(**new_system_in_data)
@@ -544,19 +544,19 @@ def mock_update(
544544
valid_move_result: bool = True,
545545
) -> None:
546546
"""
547-
Mocks database methods appropriately to test the `update` repo method
547+
Mocks database methods appropriately to test the `update` repo method.
548548
549-
:param system_id: ID of the system to be updated
550-
:param new_system_in_data: Dictionary containing the new system data as would be required for a SystemIn
551-
database model (i.e. no ID or created and modified times required)
549+
:param system_id: ID of the system to be updated.
550+
:param new_system_in_data: Dictionary containing the new system data as would be required for a `SystemIn`
551+
database model (i.e. no ID or created and modified times required).
552552
:param stored_system_in_data: Dictionary containing the system data for the existing stored system
553-
as would be required for a `SystemIn` database model
553+
as would be required for a `SystemIn` database model.
554554
:param new_parent_system_in_data: Either `None` or a dictionary containing the new parent system data as would
555-
be required for a `SystemIn` database model
555+
be required for a `SystemIn` database model.
556556
:param duplicate_system_in_data: Either `None` or a dictionary containing the data for a duplicate system as
557-
would be required for a `SystemIn` database model
558-
:param valid_move_result: Whether to mock in a valid or invalid move result i.e. when True will simulating
559-
moving the system to one of its own children
557+
would be required for a `SystemIn` database model.
558+
:param valid_move_result: Whether to mock in a valid or invalid move result i.e. when `True` will simulate
559+
moving the system to one of its own children.
560560
"""
561561
self.set_update_data(new_system_in_data)
562562

test/unit/services/test_catalogue_category.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def mock_create(
170170
:param catalogue_category_data: Dictionary containing the basic catalogue category data as would be required
171171
for a `CatalogueCategoryPostSchema` but with any unit_id's replaced by the
172172
'unit' value in its properties as the ids will be added automatically.
173-
:param parent_catalogue_category_in_data: Either None or a dictionary containing the parent catalogue category
173+
:param parent_catalogue_category_in_data: Either `None` or a dictionary containing the parent catalogue category
174174
data as would be required for a `CatalogueCategoryIn` database model.
175175
:param units_in_data: Either `None` or a list of dictionaries (or `None`) containing the unit data as would be
176176
required for a `UnitIn` database model. These values will be used for any unit look ups
@@ -506,7 +506,7 @@ def mock_update(
506506
'unit' value in its properties as the ids will be added automatically.
507507
:param stored_catalogue_category_post_data: Dictionary containing the catalogue category data for the existing
508508
stored catalogue category as would be required for a
509-
`CatalogueCategoryPostSchema` (i.e. no id, code or created and modified
509+
`CatalogueCategoryPostSchema` (i.e. no ID, code or created and modified
510510
times required).
511511
:param has_child_elements: Boolean of whether the category being updated has child elements or not
512512
:param new_parent_catalogue_category_in_data: Either `None` or a dictionary containing the new parent catalogue

0 commit comments

Comments
 (0)