Skip to content

Commit

Permalink
Merge branch 'refactor-item-e2e-tests-#347' into refactor-units-tests-#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGuarnaccia5 committed Aug 13, 2024
2 parents 0aa0a94 + 3254637 commit 0c9fe37
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ jobs:
- name: Run unit tests
run: pytest -c test/pytest.ini test/unit/ --cov

- name: Upload coverage reports to Codecov
if: success()
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

e2e-tests:
needs: [unit-tests]
name: End-to-End Tests
Expand Down
11 changes: 11 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coverage:
status:
project:
default:
target: auto
threshold: 5
patch:
default:
target: 75
ignore:
- "test/"
38 changes: 15 additions & 23 deletions test/unit/repositories/test_catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,27 @@
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_ITEM_DATA_REQUIRED_VALUES_ONLY,
)
CATALOGUE_ITEM_DATA_REQUIRED_VALUES_ONLY)
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 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 Expand Up @@ -487,11 +479,11 @@ class ListDSL(CatalogueCategoryRepoDSL):
_obtained_catalogue_categories_out: list[CatalogueCategoryOut]

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

self._expected_catalogue_categories_out = [
Expand Down Expand Up @@ -531,7 +523,7 @@ def check_list_success(self) -> None:


class TestList(ListDSL):
"""Tests for listing catalogue categorys."""
"""Tests for listing catalogue categories."""

def test_list(self):
"""Test listing all catalogue categories."""
Expand Down Expand Up @@ -1072,9 +1064,9 @@ def call_has_child_elements(self, catalogue_category_id: str) -> None:
)

def check_has_child_elements_success(self, expected_result: bool) -> None:
"""Checks that a prior call to `call_has_child_elements` worked as expected
"""Checks that a prior call to `call_has_child_elements` worked as expected.
:param expected_result: The expected result returned by `has_child_elements`
:param expected_result: The expected result returned by `has_child_elements`.
"""

self.check_has_child_elements_performed_expected_calls(self._has_child_elements_catalogue_category_id)
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 @@ -57,7 +57,7 @@ def mock_has_child_elements(self, child_item_data: Optional[dict] = None) -> Non
"""
Mocks database methods appropriately for when the `has_child_elements` repo method will be called.
:param child_item_data: Dictionary containing a child item's data (or `None`)
:param child_item_data: Dictionary containing a child item's data (or `None`).
"""

self._mock_child_item_data = child_item_data
Expand Down Expand Up @@ -255,11 +255,11 @@ class ListDSL(CatalogueItemRepoDSL):
_obtained_catalogue_items_out: list[CatalogueItemOut]

def mock_list(self, catalogue_items_in_data: list[dict]) -> None:
"""Mocks database methods appropriately to test the `list` repo method
"""Mocks database methods appropriately to test the `list` repo method.
:param catalogue_items_in_data: List of dictionaries containing the catalogue item data as would be
required for a `CatalogueItemIn` database model (i.e. no ID or created
and modified times required)
and modified times required).
"""

self._expected_catalogue_items_out = [
Expand Down Expand Up @@ -582,9 +582,9 @@ def call_has_child_elements(self, catalogue_item_id: str) -> None:
)

def check_has_child_elements_success(self, expected_result: bool) -> None:
"""Checks that a prior call to `call_has_child_elements` worked as expected
"""Checks that a prior call to `call_has_child_elements` worked as expected.
:param expected_result: The expected result returned by `has_child_elements`
:param expected_result: The expected result returned by `has_child_elements`.
"""

self.check_has_child_elements_performed_expected_calls(self._has_child_elements_catalogue_item_id)
Expand Down Expand Up @@ -628,9 +628,9 @@ def call_list_ids(self, catalogue_category_id: str) -> None:
)

def check_list_ids_success(self) -> None:
"""Checks that a prior call to `call_list_ids` worked as expected
"""Checks that a prior call to `call_list_ids` worked as expected.
:param expected_result: The expected result returned by `list_ids`
:param expected_result: The expected result returned by `list_ids`.
"""

self.catalogue_items_collection.find.assert_called_once_with(
Expand Down

0 comments on commit 0c9fe37

Please sign in to comment.