From b5adb28c3bfc2accf3a0e3ec6cbee57baa31f8ad Mon Sep 17 00:00:00 2001 From: Mihaela Balutoiu Date: Thu, 25 Jan 2024 12:21:27 +0200 Subject: [PATCH] Add unit tests for `scheduler/filters/base.py` module Signed-off-by: Mihaela Balutoiu --- coriolis/tests/scheduler/filters/__init__.py | 0 coriolis/tests/scheduler/filters/test_base.py | 52 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 coriolis/tests/scheduler/filters/__init__.py create mode 100644 coriolis/tests/scheduler/filters/test_base.py diff --git a/coriolis/tests/scheduler/filters/__init__.py b/coriolis/tests/scheduler/filters/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/coriolis/tests/scheduler/filters/test_base.py b/coriolis/tests/scheduler/filters/test_base.py new file mode 100644 index 000000000..c44636181 --- /dev/null +++ b/coriolis/tests/scheduler/filters/test_base.py @@ -0,0 +1,52 @@ +# Copyright 2024 Cloudbase Solutions Srl +# All Rights Reserved. + +from unittest import mock + +from coriolis.scheduler.filters import base +from coriolis.tests import test_base + + +class BaseServiceFilterTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the BaseServiceFilter class.""" + + @mock.patch.object(base.BaseServiceFilter, '__abstractmethods__', set()) + def setUp(self): + super(BaseServiceFilterTestCase, self).setUp() + self.service_filter = base.BaseServiceFilter() + + def test_is_service_acceptable(self): + self.service_filter.rate_service = mock.Mock() + self.service_filter.rate_service.return_value = 50 + + result = self.service_filter.is_service_acceptable( + mock.sentinel.service) + + self.service_filter.rate_service.assert_called_once_with( + mock.sentinel.service + ) + self.assertTrue(result) + + def test_is_service_acceptable_false(self): + self.service_filter.rate_service = mock.Mock() + self.service_filter.rate_service.return_value = 0 + + result = self.service_filter.is_service_acceptable( + mock.sentinel.service) + + self.service_filter.rate_service.assert_called_once_with( + mock.sentinel.service + ) + self.assertFalse(result) + + def test_filter_services(self): + self.service_filter.is_service_acceptable = mock.Mock() + self.service_filter.is_service_acceptable.side_effect = [ + True, False, True] + + result = self.service_filter.filter_services([mock.sentinel.service1, + mock.sentinel.service2, + mock.sentinel.service3]) + + self.assertEqual(result, [mock.sentinel.service1, + mock.sentinel.service3])