Feature 9751: Centralized VCA for KNFs
[osm/N2VC.git] / n2vc / tests / unit / test_juju_watcher.py
index 593ff0d..41065bf 100644 (file)
@@ -140,3 +140,29 @@ class StatusTest(TestCase):
         value = status(application)
         mock_derive_status.assert_called_once()
         self.assertTrue(isinstance(value, str))
+
+
+class WaitForModelTest(asynctest.TestCase):
+    @asynctest.mock.patch("juju.client.connector.Connector.connect")
+    def setUp(self, mock_connect=None):
+        self.loop = asyncio.new_event_loop()
+        self.model = Model()
+
+    @asynctest.mock.patch("juju.model.Model.block_until")
+    def test_wait_for_model(self, mock_block_until):
+        self.loop.run_until_complete(
+            JujuModelWatcher.wait_for_model(self.model, timeout=None)
+        )
+        mock_block_until.assert_called()
+
+    @asynctest.mock.patch("asyncio.ensure_future")
+    @asynctest.mock.patch("asyncio.wait")
+    def test_wait_for_model_exception(self, mock_wait, mock_ensure_future):
+        task = Mock()
+        mock_ensure_future.return_value = task
+        mock_wait.side_effect = Exception
+        with self.assertRaises(Exception):
+            self.loop.run_until_complete(
+                JujuModelWatcher.wait_for_model(self.model, timeout=None)
+            )
+        task.cancel.assert_called()