From 68087b5f44be4312eeb0ed9a4033223b568b7e32 Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Fri, 22 Nov 2024 11:49:07 +0000 Subject: [PATCH] Add a spares definition get SystemService unit test #414 --- test/unit/services/test_setting.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/unit/services/test_setting.py b/test/unit/services/test_setting.py index c10b2e7a..4379d7ee 100644 --- a/test/unit/services/test_setting.py +++ b/test/unit/services/test_setting.py @@ -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()