Skip to content

Commit

Permalink
Remove test_helpers instance in SystemServiceDSL #90
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Jun 27, 2024
1 parent e9491a0 commit 7bb0e1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions test/unit/services/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ def mock_update(
repository_mock.update.return_value = repo_obj


# 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]:
"""
Expand Down
16 changes: 7 additions & 9 deletions test/unit/services/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
class SystemServiceDSL:
"""Base class for SystemService unit tests"""

test_helpers: ServiceTestHelpers
wrapped_utils: Mock
mock_system_repository: Mock
system_service: SystemService

@pytest.fixture(autouse=True)
def setup(
self,
test_helpers,
system_repository_mock,
system_service,
# Ensures all created and modified times are mocked throughout
Expand All @@ -38,7 +36,6 @@ def setup(
):
"""Setup fixtures"""

self.test_helpers = test_helpers
self.mock_system_repository = system_repository_mock
self.system_service = system_service

Expand All @@ -62,14 +59,15 @@ def mock_create(self, system_post_data: dict):
:param system_post_data: Dictionary containing the basic system data as would be required for a
SystemPostSchema (i.e. no id, code or created and modified times required)
"""

self._system_post = SystemPostSchema(**system_post_data)

self._expected_system_in = SystemIn(
**system_post_data, code=utils.generate_code(system_post_data["name"], "system")
)
self._expected_system_out = SystemOut(**self._expected_system_in.model_dump(), id=ObjectId())

self.test_helpers.mock_create(self.mock_system_repository, self._expected_system_out)
ServiceTestHelpers.mock_create(self.mock_system_repository, self._expected_system_out)

def call_create(self):
"""Calls the SystemService `create` method with the appropriate data from a prior call to `mock_create`"""
Expand Down Expand Up @@ -115,7 +113,7 @@ def mock_get(self):

# Simply a return currently, so no need to use actual data
self._expected_system = MagicMock()
self.test_helpers.mock_get(self.mock_system_repository, self._expected_system)
ServiceTestHelpers.mock_get(self.mock_system_repository, self._expected_system)

def call_get(self, system_id: str):
"""Calls the SystemService `get` method"""
Expand Down Expand Up @@ -154,7 +152,7 @@ def mock_get_breadcrumbs(self):

# Simply a return currently, so no need to use actual data
self._expected_breadcrumbs = MagicMock()
self.test_helpers.mock_get_breadcrumbs(self.mock_system_repository, self._expected_breadcrumbs)
ServiceTestHelpers.mock_get_breadcrumbs(self.mock_system_repository, self._expected_breadcrumbs)

def call_get_breadcrumbs(self, system_id: str):
"""Calls the SystemService `get` method"""
Expand Down Expand Up @@ -193,7 +191,7 @@ def mock_list(self):

# Simply a return currently, so no need to use actual data
self._expected_systems = MagicMock()
self.test_helpers.mock_list(self.mock_system_repository, self._expected_systems)
ServiceTestHelpers.mock_list(self.mock_system_repository, self._expected_systems)

def call_list(self, parent_id: Optional[str]):
"""Calls the SystemService `list` method"""
Expand Down Expand Up @@ -253,14 +251,14 @@ def mock_update(self, system_id: str, system_patch_data: dict, stored_system_pos
if stored_system_post_data
else None
)
self.test_helpers.mock_get(self.mock_system_repository, self._stored_system)
ServiceTestHelpers.mock_get(self.mock_system_repository, self._stored_system)

# Patch schema
self._system_patch = SystemPatchSchema(**system_patch_data)

# Updated system
self._expected_system_out = MagicMock()
self.test_helpers.mock_update(self.mock_system_repository, self._expected_system_out)
ServiceTestHelpers.mock_update(self.mock_system_repository, self._expected_system_out)

# Construct the expected input for the repository
merged_system_data = {**(stored_system_post_data or {}), **system_patch_data}
Expand Down

0 comments on commit 7bb0e1f

Please sign in to comment.