from juju.model import Model
from juju.machine import Machine
from juju.application import Application
-from juju.client._definitions import FullStatus
+from juju.client._definitions import FullStatus, QueryApplicationOffersResults
from n2vc.juju_watcher import JujuModelWatcher
from n2vc.provisioner import AsyncSSHProvisioner
from n2vc.n2vc_conn import N2VCConnector
return models
finally:
await self.disconnect_controller(controller)
+
+ async def list_offers(self, model_name: str) -> QueryApplicationOffersResults:
+ """List models with certain names
+
+ :param: model_name: Model name
+
+ :return: Returns list of offers
+ """
+
+ controller = await self.get_controller()
+ try:
+ return await controller.list_offers(model_name)
+ finally:
+ await self.disconnect_controller(controller)
)
self.assertTrue(exist)
self.assertEqual(non_existing_models, [])
+
+
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.get_controller")
+@asynctest.mock.patch("n2vc.libjuju.Libjuju.disconnect_controller")
+@asynctest.mock.patch("juju.controller.Controller.list_offers")
+class ListOffers(LibjujuTestCase):
+ def setUp(self):
+ super(ListOffers, self).setUp()
+
+ def test_disconnect_controller(
+ self, mock_list_offers, mock_disconnect_controller, mock_get_controller,
+ ):
+ mock_get_controller.return_value = juju.controller.Controller()
+ mock_list_offers.side_effect = Exception()
+ with self.assertRaises(Exception):
+ self.loop.run_until_complete(self.libjuju.list_offers("model"))
+ mock_disconnect_controller.assert_called_once()
+
+ def test_empty_list(
+ self, mock_list_offers, mock_disconnect_controller, mock_get_controller,
+ ):
+ mock_get_controller.return_value = juju.controller.Controller()
+ mock_list_offers.return_value = []
+ offers = self.loop.run_until_complete(self.libjuju.list_offers("model"))
+ self.assertEqual(offers, [])
+ mock_disconnect_controller.assert_called_once()
+
+ def test_non_empty_list(
+ self, mock_list_offers, mock_disconnect_controller, mock_get_controller,
+ ):
+ mock_get_controller.return_value = juju.controller.Controller()
+ mock_list_offers.return_value = ["offer"]
+ offers = self.loop.run_until_complete(self.libjuju.list_offers("model"))
+ self.assertEqual(offers, ["offer"])
+ mock_disconnect_controller.assert_called_once()