X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Ftests%2Funit%2Ftest_juju_watcher.py;h=5f8127420649a3c63629ea551a3cb6807dfb53d7;hp=593ff0d997902d61d510509ae108c51207ce51da;hb=refs%2Fchanges%2F16%2F10616%2F9;hpb=c38a696d168531e3c067451044262ef4d78ef11f;ds=sidebyside diff --git a/n2vc/tests/unit/test_juju_watcher.py b/n2vc/tests/unit/test_juju_watcher.py index 593ff0d..5f81274 100644 --- a/n2vc/tests/unit/test_juju_watcher.py +++ b/n2vc/tests/unit/test_juju_watcher.py @@ -45,6 +45,7 @@ class JujuWatcherTest(asynctest.TestCase): def test_model_watcher(self, allwatcher): tests = Deltas allwatcher.return_value = FakeWatcher() + n2vc = AsyncMock() for test in tests: with self.assertRaises(asyncio.TimeoutError): allwatcher.return_value.delta_to_return = [test.delta] @@ -55,12 +56,12 @@ class JujuWatcherTest(asynctest.TestCase): test.filter.entity_type, timeout=0, db_dict={"something"}, - n2vc=self.n2vc, + n2vc=n2vc, + vca_id=None, ) ) - self.assertEqual(self.n2vc.last_written_values, test.db.data) - self.n2vc.last_written_values = None + n2vc.write_app_status_to_db.assert_called() @mock.patch("n2vc.juju_watcher.asyncio.wait") def test_wait_for(self, wait): @@ -140,3 +141,30 @@ class StatusTest(TestCase): value = status(application) mock_derive_status.assert_called_once() self.assertTrue(isinstance(value, str)) + + +@asynctest.mock.patch("asyncio.sleep") +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, mock_sleep): + 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, mock_sleep): + 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()