super(GetModelTest, self).setUp()
def test_get_model(
- self, mock_get_model,
+ self,
+ mock_get_model,
):
mock_get_model.return_value = juju.model.Model()
model = self.loop.run_until_complete(
super(ModelExistsTest, self).setUp()
async def test_existing_model(
- self, mock_list_models, mock_get_controller,
+ self,
+ mock_list_models,
+ mock_get_controller,
):
mock_list_models.return_value = ["existing_model"]
self.assertTrue(
@asynctest.mock.patch("n2vc.libjuju.Libjuju.disconnect_controller")
async def test_no_controller(
- self, mock_disconnect_controller, mock_list_models, mock_get_controller,
+ self,
+ mock_disconnect_controller,
+ mock_list_models,
+ mock_get_controller,
):
mock_list_models.return_value = ["existing_model"]
mock_get_controller.return_value = juju.controller.Controller()
mock_disconnect_controller.assert_called_once()
async def test_non_existing_model(
- self, mock_list_models, mock_get_controller,
+ self,
+ mock_list_models,
+ mock_get_controller,
):
mock_list_models.return_value = ["existing_model"]
self.assertFalse(
application = None
with self.assertRaises(JujuApplicationExists):
application = self.loop.run_until_complete(
- self.libjuju.deploy_charm("existing_app", "path", "model", "machine",)
+ self.libjuju.deploy_charm(
+ "existing_app",
+ "path",
+ "model",
+ "machine",
+ )
)
self.assertIsNone(application)
application = None
with self.assertRaises(JujuMachineNotFound):
application = self.loop.run_until_complete(
- self.libjuju.deploy_charm("app", "path", "model", "machine",)
+ self.libjuju.deploy_charm(
+ "app",
+ "path",
+ "model",
+ "machine",
+ )
)
self.assertIsNone(application)
mock_deploy.return_value = FakeApplication()
application = self.loop.run_until_complete(
self.libjuju.deploy_charm(
- "app", "path", "model", "existing_machine", num_units=2,
+ "app",
+ "path",
+ "model",
+ "existing_machine",
+ num_units=2,
)
)
super(GetApplicationTest, self).setUp()
def test_existing_application(
- self, mock_applications,
+ self,
+ mock_applications,
):
mock_applications.return_value = {"existing_app": "exists"}
model = juju.model.Model()
self.assertEqual(result, "exists")
def test_non_existing_application(
- self, mock_applications,
+ self,
+ mock_applications,
):
mock_applications.return_value = {"existing_app": "exists"}
model = juju.model.Model()
status = None
with self.assertRaises(JujuApplicationNotFound):
output, status = self.loop.run_until_complete(
- self.libjuju.execute_action("app", "model", "action",)
+ self.libjuju.execute_action(
+ "app",
+ "model",
+ "action",
+ )
)
self.assertIsNone(output)
self.assertIsNone(status)
status = None
with self.assertRaises(JujuActionNotFound):
output, status = self.loop.run_until_complete(
- self.libjuju.execute_action("app", "model", "action",)
+ self.libjuju.execute_action(
+ "app",
+ "model",
+ "action",
+ )
)
self.assertIsNone(output)
self.assertIsNone(status)
status = None
with self.assertRaises(JujuLeaderUnitNotFound):
output, status = self.loop.run_until_complete(
- self.libjuju.execute_action("app", "model", "action",)
+ self.libjuju.execute_action(
+ "app",
+ "model",
+ "action",
+ )
)
self.assertIsNone(output)
self.assertIsNone(status)
mock_add_relation.side_effect = JujuAPIError(result)
self.loop.run_until_complete(
- self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
+ self.libjuju.add_relation(
+ "model",
+ "app1:relation1",
+ "app2:relation2",
+ )
)
mock_warning.assert_called_with("Relation not found: not found")
mock_add_relation.side_effect = JujuAPIError(result)
self.loop.run_until_complete(
- self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
+ self.libjuju.add_relation(
+ "model",
+ "app1:relation1",
+ "app2:relation2",
+ )
)
mock_warning.assert_called_with("Relation already exists: already exists")
with self.assertRaises(JujuAPIError):
self.loop.run_until_complete(
- self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
+ self.libjuju.add_relation(
+ "model",
+ "app1:relation1",
+ "app2:relation2",
+ )
)
mock_disconnect_controller.assert_called_once()
mock_get_model.return_value = juju.model.Model()
self.loop.run_until_complete(
- self.libjuju.add_relation("model", "app1:relation1", "app2:relation2",)
+ self.libjuju.add_relation(
+ "model",
+ "app1:relation1",
+ "app2:relation2",
+ )
)
mock_add_relation.assert_called_with("app1:relation1", "app2:relation2")
mock_get_model.return_value = juju.model.Model()
self.loop.run_until_complete(
- self.libjuju.add_relation("model", "app1:relation1", "saas_name",)
+ self.libjuju.add_relation(
+ "model",
+ "app1:relation1",
+ "saas_name",
+ )
)
mock_add_relation.assert_called_with("app1:relation1", "saas_name")
mock_get_application.return_value = FakeApplication()
self.loop.run_until_complete(
- self.libjuju.configure_application("model", "app", {"config"},)
+ self.libjuju.configure_application(
+ "model",
+ "app",
+ {"config"},
+ )
)
mock_get_application.assert_called_once()
mock_disconnect_controller.assert_called_once()
with self.assertRaises(Exception):
self.loop.run_until_complete(
- self.libjuju.configure_application("model", "app", {"config"},)
+ self.libjuju.configure_application(
+ "model",
+ "app",
+ {"config"},
+ )
)
mock_disconnect_controller.assert_called_once()
mock_disconnect_model.assert_called_once()
+ def test_controller_exception(
+ self,
+ mock_get_application,
+ mock_disconnect_controller,
+ mock_disconnect_model,
+ mock_get_model,
+ mock_get_controller,
+ ):
+
+ result = {"error": "not found", "response": "response", "request-id": 1}
+
+ mock_get_controller.side_effect = JujuAPIError(result)
+
+ with self.assertRaises(JujuAPIError):
+ self.loop.run_until_complete(
+ self.libjuju.configure_application(
+ "model",
+ "app",
+ {"config"},
+ )
+ )
+ mock_get_model.assert_not_called()
+ mock_disconnect_controller.assert_not_called()
+ mock_disconnect_model.assert_not_called()
+
+ def test_get_model_exception(
+ self,
+ mock_get_application,
+ mock_disconnect_controller,
+ mock_disconnect_model,
+ mock_get_model,
+ mock_get_controller,
+ ):
+
+ result = {"error": "not found", "response": "response", "request-id": 1}
+ mock_get_model.side_effect = JujuAPIError(result)
+
+ with self.assertRaises(JujuAPIError):
+ self.loop.run_until_complete(
+ self.libjuju.configure_application(
+ "model",
+ "app",
+ {"config"},
+ )
+ )
+ mock_get_model.assert_called_once()
+ mock_disconnect_controller.assert_called_once()
+ mock_disconnect_model.assert_not_called()
+
# TODO _get_api_endpoints_db test case
# TODO _update_api_endpoints_db test case
super(ListModelsTest, self).setUp()
def test_containing(
- self, mock_list_models, mock_disconnect_controller, mock_get_controller,
+ self,
+ mock_list_models,
+ mock_disconnect_controller,
+ mock_get_controller,
):
mock_get_controller.return_value = juju.controller.Controller()
mock_list_models.return_value = ["existingmodel"]
self.assertEquals(models, ["existingmodel"])
def test_not_containing(
- self, mock_list_models, mock_disconnect_controller, mock_get_controller,
+ self,
+ mock_list_models,
+ mock_disconnect_controller,
+ mock_get_controller,
):
mock_get_controller.return_value = juju.controller.Controller()
mock_list_models.return_value = ["existingmodel", "model"]
self.assertEquals(models, [])
def test_no_contains_arg(
- self, mock_list_models, mock_disconnect_controller, mock_get_controller,
+ self,
+ mock_list_models,
+ mock_disconnect_controller,
+ mock_get_controller,
):
mock_get_controller.return_value = juju.controller.Controller()
mock_list_models.return_value = ["existingmodel", "model"]
super(ListOffers, self).setUp()
def test_disconnect_controller(
- self, mock_list_offers, mock_disconnect_controller, mock_get_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()
mock_disconnect_controller.assert_called_once()
def test_empty_list(
- self, mock_list_offers, mock_disconnect_controller, mock_get_controller,
+ self,
+ mock_list_offers,
+ mock_disconnect_controller,
+ mock_get_controller,
):
mock_get_controller.return_value = juju.controller.Controller()
mock_list_offers.return_value = []
mock_disconnect_controller.assert_called_once()
def test_non_empty_list(
- self, mock_list_offers, mock_disconnect_controller, mock_get_controller,
+ self,
+ mock_list_offers,
+ mock_disconnect_controller,
+ mock_get_controller,
):
mock_get_controller.return_value = juju.controller.Controller()
mock_list_offers.return_value = ["offer"]
super(RemoveCloudTest, self).setUp()
def test_remove_cloud(
- self, mock_remove_cloud, mock_disconnect_controller, mock_get_controller,
+ self,
+ mock_remove_cloud,
+ mock_disconnect_controller,
+ mock_get_controller,
):
mock_get_controller.return_value = juju.controller.Controller()
mock_disconnect_controller.assert_called_once()
def test_remove_cloud_exception(
- self, mock_remove_cloud, mock_disconnect_controller, mock_get_controller,
+ self,
+ mock_remove_cloud,
+ mock_disconnect_controller,
+ mock_get_controller,
):
mock_get_controller.return_value = juju.controller.Controller()
mock_remove_cloud.side_effect = Exception()
except JujuInvalidK8sConfiguration as e:
exception_raised = True
self.assertEqual(
- e.message, "authentication method not supported",
+ e.message,
+ "authentication method not supported",
)
self.assertTrue(exception_raised)
self.assertEqual(
credential,
juju.client._definitions.CloudCredential(
- attrs={"ClientKeyData": "key", "Token": "Token"}, auth_type="oauth2",
+ attrs={"ClientKeyData": "key", "Token": "Token"},
+ auth_type="oauth2",
),
)
except JujuInvalidK8sConfiguration as e:
exception_raised = True
self.assertEqual(
- e.message, "missing token for auth type oauth2",
+ e.message,
+ "missing token for auth type oauth2",
)
self.assertTrue(exception_raised)
except JujuInvalidK8sConfiguration as e:
exception_raised = True
self.assertEqual(
- e.message, "unknown format of api_key",
+ e.message,
+ "unknown format of api_key",
)
self.assertTrue(exception_raised)
except JujuInvalidK8sConfiguration as e:
exception_raised = True
self.assertEqual(
- e.message, "Cannot set both token and user/pass",
+ e.message,
+ "Cannot set both token and user/pass",
)
self.assertTrue(exception_raised)