Feature-9904: Enhancing NG-UI to enable Juju operational view dashboard 96/10496/3
authorksaikiranr <saikiran.k@tataelxsi.co.in>
Wed, 17 Mar 2021 07:24:15 +0000 (12:54 +0530)
committerksaikiranr <saikiran.k@tataelxsi.co.in>
Wed, 14 Apr 2021 04:38:02 +0000 (10:08 +0530)
Added unit test for update_vca_status method for KNF

Change-Id: Iba6285d0d5deeaa7bef685a22abeba0ae535ab19
Signed-off-by: jayaramans <selvi.j@tataelxsi.co.in>
Signed-off-by: ksaikiranr <saikiran.k@tataelxsi.co.in>
n2vc/tests/unit/test_k8s_juju_conn.py

index b182d8c..f454380 100644 (file)
@@ -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()