Skip to content

Commit

Permalink
Add a spares definition get SystemService unit test #414
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Nov 22, 2024
1 parent 3e8f3cd commit 68087b5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/unit/services/test_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,39 @@ def test_set_spare_definition_with_non_existent_usage_status_id(self):
# pylint: disable=unsubscriptable-object
f"No usage status found with ID: {self._spares_definition_put.usage_statuses[1].id}"
)


class GetSparesDefinitionDSL(SettingServiceDSL):
"""Base class for `get_spares_definition` tests."""

_expected_spares_definition: MagicMock
_obtained_spares_definition: MagicMock

def mock_get_spares_definition(self) -> None:
"""Mocks repo methods appropriately to test the `get_spares_definition` service method."""

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

def call_get_spares_definition(self) -> None:
"""Calls the `SettingService` `get_spares_definition` method."""

self._obtained_spares_definition = self.setting_service.get_spares_definition()

def check_get_spares_definition_success(self) -> None:
"""Checks that a prior call to `call_get_spares_definition` worked as expected."""

self.mock_setting_repository.get.assert_called_once_with(SparesDefinitionOut)
assert self._obtained_spares_definition == self._expected_spares_definition


class TestGetSparesDefinition(GetSparesDefinitionDSL):
"""Tests for getting the spares definition."""

def test_get(self):
"""Test getting the spares definition."""

self.mock_get_spares_definition()
self.call_get_spares_definition()
self.check_get_spares_definition_success()

0 comments on commit 68087b5

Please sign in to comment.