From f8c25c9ceeeca8ac91caa62faa402a8b6dab02e1 Mon Sep 17 00:00:00 2001 From: ksaikiranr Date: Wed, 17 Mar 2021 12:54:15 +0530 Subject: [PATCH] Feature-9904: Enhancing NG-UI to enable Juju operational view dashboard Added unit test for update_vca_status method for KNF Change-Id: Iba6285d0d5deeaa7bef685a22abeba0ae535ab19 Signed-off-by: jayaramans Signed-off-by: ksaikiranr --- n2vc/tests/unit/test_k8s_juju_conn.py | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/n2vc/tests/unit/test_k8s_juju_conn.py b/n2vc/tests/unit/test_k8s_juju_conn.py index b182d8c..f454380 100644 --- a/n2vc/tests/unit/test_k8s_juju_conn.py +++ b/n2vc/tests/unit/test_k8s_juju_conn.py @@ -789,3 +789,31 @@ class GetCredentialsTest(K8sJujuConnTestCase): self.k8s_juju_conn.db.get_one.assert_called_once() self.k8s_juju_conn.db.encrypt_decrypt_fields.assert_called_once() mock_safe_dump.assert_called_once() + + +class UpdateVcaStatusTest(K8sJujuConnTestCase): + def setUp(self): + super(UpdateVcaStatusTest, self).setUp() + self.vcaStatus = {"model": {"applications": {"app": {"actions": {}}}}} + self.kdu_name = "kdu_name" + self.kdu_instance = "{}-{}".format(self.kdu_name, "id") + self.k8s_juju_conn.libjuju.get_executed_actions = AsyncMock() + self.k8s_juju_conn.libjuju.get_actions = AsyncMock() + self.k8s_juju_conn.libjuju.get_application_configs = AsyncMock() + + def test_success(self): + self.loop.run_until_complete(self.k8s_juju_conn.update_vca_status( + self.vcaStatus, self.kdu_instance)) + self.k8s_juju_conn.libjuju.get_executed_actions.assert_called_once() + self.k8s_juju_conn.libjuju.get_actions.assert_called_once() + self.k8s_juju_conn.libjuju.get_application_configs.assert_called_once() + + def test_exception(self): + self.k8s_juju_conn.libjuju.get_model.return_value = None + self.k8s_juju_conn.libjuju.get_executed_actions.side_effect = Exception() + with self.assertRaises(Exception): + self.loop.run_until_complete(self.k8s_juju_conn.update_vca_status( + self.vcaStatus, self.kdu_instance)) + self.k8s_juju_conn.libjuju.get_executed_actions.assert_not_called() + self.k8s_juju_conn.libjuju.get_actions.assert_not_called_once() + self.k8s_juju_conn.libjuju.get_application_configs.assert_not_called_once() -- 2.25.1