From dc8b7ea0ecb6df30cac1e940f0e1b603c09c8906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Lal?= Date: Fri, 5 Mar 2021 14:41:46 +0100 Subject: [PATCH] Add unit tests for sequence_status_check_functions() (#585) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing unit tests for sequence_status_check_functions() helper introduced in PR #584. Signed-off-by: Przemysław Lal --- tests/contrib/openstack/test_os_utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/contrib/openstack/test_os_utils.py b/tests/contrib/openstack/test_os_utils.py index 99ed17d9f..ef52033a4 100644 --- a/tests/contrib/openstack/test_os_utils.py +++ b/tests/contrib/openstack/test_os_utils.py @@ -275,3 +275,25 @@ def test_ordered(self): self.assertEqual(expected, utils.ordered(data)) self.assertRaises(ValueError, utils.ordered, "foo") + + def test_sequence_status_check_functions(self): + # all messages are reported and the highest priority status "wins" + f1 = mock.Mock(return_value=('blocked', 'status 1')) + f2 = mock.Mock(return_value=('', 'status 2')) + f3 = mock.Mock(return_value=('maintenance', 'status 3')) + f = utils.sequence_status_check_functions(f1, f2, f3) + expected = ('blocked', 'status 1, status 2, status 3') + result = f(mock.Mock()) + self.assertEquals(result, expected) + # empty status must be replaced by "unknown" + f4 = mock.Mock(return_value=('', 'status 4')) + f5 = mock.Mock(return_value=('', 'status 5')) + f = utils.sequence_status_check_functions(f4, f5) + expected = ('unknown', 'status 4, status 5') + result = f(mock.Mock()) + self.assertEquals(result, expected) + # sequencing 0 status checks must return state 'unknown', '' + f = utils.sequence_status_check_functions() + expected = ('unknown', '') + result = f(mock.Mock()) + self.assertEquals(result, expected)