Skip to content

Commit

Permalink
Remove some old test fixtures #90
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Sep 24, 2024
1 parent a4deafc commit 2b65b62
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 60 deletions.
49 changes: 1 addition & 48 deletions test/unit/repositories/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module for providing common test configuration, test fixtures, and helper functions.
"""

from typing import List, Type
from typing import List
from unittest.mock import MagicMock, Mock

import pytest
Expand All @@ -12,10 +12,6 @@
from pymongo.database import Database
from pymongo.results import DeleteResult, InsertOneResult, UpdateResult

from inventory_management_system_api.repositories.item import ItemRepo
from inventory_management_system_api.repositories.unit import UnitRepo
from inventory_management_system_api.repositories.usage_status import UsageStatusRepo


@pytest.fixture(name="database_mock")
def fixture_database_mock() -> Mock:
Expand All @@ -35,39 +31,6 @@ def fixture_database_mock() -> Mock:
return database_mock


@pytest.fixture(name="item_repository")
def fixture_item_repository(database_mock: Mock) -> ItemRepo:
"""
Fixture to create a `ItemRepo` instance with a mocked Database dependency.
:param database_mock: Mocked MongoDB database instance.
:return: `ItemRepo` instance with the mocked dependency.
"""
return ItemRepo(database_mock)


@pytest.fixture(name="unit_repository")
def fixture_unit_repository(database_mock: Mock) -> UnitRepo:
"""
Fixture to create a `UnitRepo` instance with a mocked Database dependency.
:param database_mock: Mocked MongoDB database instance.
:return: `UnitRepo` instance with the mocked dependency.
"""
return UnitRepo(database_mock)


@pytest.fixture(name="usage_status_repository")
def fixture_usage_status_repository(database_mock: Mock) -> UsageStatusRepo:
"""
Fixture to create a `UsageStatusRepo` instance with a mocked Database dependency.
:param database_mock: Mocked MongoDB database instance.
:return: `UsageStatusRepo` instance with the mocked dependency.
"""
return UsageStatusRepo(database_mock)


class RepositoryTestHelpers:
"""
A utility class containing common helper methods for the repository tests.
Expand Down Expand Up @@ -154,13 +117,3 @@ def mock_update_many(collection_mock: Mock) -> None:
update_many_result_mock = Mock(UpdateResult)
update_many_result_mock.acknowledged = True
collection_mock.update_many.return_value = update_many_result_mock


# pylint:disable=fixme
# TODO: Remove this once tests refactored - should be able to just use `RepositoryTestHelpers.`
@pytest.fixture(name="test_helpers")
def fixture_test_helpers() -> Type[RepositoryTestHelpers]:
"""
Fixture to provide a TestHelpers class.
"""
return RepositoryTestHelpers
2 changes: 1 addition & 1 deletion test/unit/repositories/test_system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Unit tests for the `SystemRepo` repository
Unit tests for the `SystemRepo` repository.
"""

# Expect some duplicate code inside tests as the tests for the different entities can be very similar
Expand Down
12 changes: 1 addition & 11 deletions test/unit/services/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from datetime import datetime, timezone
from typing import List, Type, Union
from typing import List, Union
from unittest.mock import Mock, patch

import pytest
Expand Down Expand Up @@ -406,16 +406,6 @@ def construct_properties_in_and_post_with_ids(
return expected_properties_in, property_post_schemas


# pylint:disable=fixme
# TODO: Remove this once tests refactored - should be able to just use `ServiceTestHelpers.`
@pytest.fixture(name="test_helpers")
def fixture_test_helpers() -> Type[ServiceTestHelpers]:
"""
Fixture to provide a TestHelpers class.
"""
return ServiceTestHelpers


MODEL_MIXINS_FIXED_DATETIME_NOW = datetime(2024, 2, 16, 14, 0, 0, 0, tzinfo=timezone.utc)


Expand Down

0 comments on commit 2b65b62

Please sign in to comment.