def test_createMongoObjectDefinition(self, client_mock): service = KubernetesService() client_mock.reset_mock() expected_def = V1beta1CustomResourceDefinition( api_version="apiextensions.k8s.io/v1beta1", kind="CustomResourceDefinition", metadata=V1ObjectMeta(name="mongos.operators.ultimaker.com"), spec=V1beta1CustomResourceDefinitionSpec( group="operators.ultimaker.com", version="v1", scope="Namespaced", names=V1beta1CustomResourceDefinitionNames(plural="mongos", singular="mongo", kind="Mongo", short_names=["mng" ]))) client_mock.ApiextensionsV1beta1Api.return_value.list_custom_resource_definition.return_value = \ V1beta1CustomResourceDefinitionList(items=[]) client_mock.ApiextensionsV1beta1Api.return_value.create_custom_resource_definition.return_value = expected_def result = service.createMongoObjectDefinition() self.assertEquals(expected_def, result) expected_calls = [ call.ApiextensionsV1beta1Api().list_custom_resource_definition(), call.ApiextensionsV1beta1Api().create_custom_resource_definition( expected_def), ] self.assertEqual(expected_calls, client_mock.mock_calls)
def test_listMongoObjects_404(self, client_mock): service = KubernetesService() client_mock.reset_mock() item = MagicMock() item.spec.names.plural = "mongos" client_mock.ApiextensionsV1beta1Api.return_value.list_custom_resource_definition.return_value.items = [ item ] client_mock.CustomObjectsApi.return_value.list_cluster_custom_object.side_effect = ApiException( 404) with self.assertRaises(TimeoutError) as context: service.listMongoObjects(param="value") expected_calls = [ call.ApiextensionsV1beta1Api().list_custom_resource_definition(), call.CustomObjectsApi().list_cluster_custom_object( 'operators.ultimaker.com', 'v1', "mongos", param='value'), call.CustomObjectsApi().list_cluster_custom_object( 'operators.ultimaker.com', 'v1', "mongos", param='value'), call.CustomObjectsApi().list_cluster_custom_object( 'operators.ultimaker.com', 'v1', "mongos", param='value'), ] self.assertEquals(expected_calls, client_mock.mock_calls) self.assertEquals( "Could not list the custom mongo objects after 3 retries", str(context.exception))
def test___init__(self, client_mock): KubernetesService() config = Configuration() config.debug = False expected = [ call.ApiClient(config), call.CoreV1Api(client_mock.ApiClient.return_value), call.CustomObjectsApi(client_mock.ApiClient.return_value), call.ApiextensionsV1beta1Api(client_mock.ApiClient.return_value), call.AppsV1beta1Api(client_mock.ApiClient.return_value), ] with patch("kubernetes.client.configuration.Configuration.__eq__", dict_eq): self.assertEqual(expected, client_mock.mock_calls)
def test_createMongoObjectDefinition_existing(self, client_mock): service = KubernetesService() client_mock.reset_mock() item = MagicMock() item.spec.names.plural = "mongos" client_mock.ApiextensionsV1beta1Api.return_value.list_custom_resource_definition.return_value.items = [ item ] result = service.createMongoObjectDefinition() self.assertEquals(item, result) expected_calls = [ call.ApiextensionsV1beta1Api().list_custom_resource_definition() ] self.assertEqual(expected_calls, client_mock.mock_calls)
def test_listMongoObjects(self, client_mock): service = KubernetesService() client_mock.reset_mock() item = MagicMock() item.spec.names.plural = "mongos" client_mock.ApiextensionsV1beta1Api.return_value.list_custom_resource_definition.return_value.items = [ item ] result = service.listMongoObjects(param="value") expected_calls = [ call.ApiextensionsV1beta1Api().list_custom_resource_definition(), call.CustomObjectsApi().list_cluster_custom_object( 'operators.ultimaker.com', 'v1', "mongos", param='value') ] self.assertEqual(expected_calls, client_mock.mock_calls) self.assertEqual( client_mock.CustomObjectsApi().list_cluster_custom_object. return_value, result)
def test_listMongoObjects_400(self, client_mock): service = KubernetesService() client_mock.reset_mock() item = MagicMock() item.spec.names.plural = "mongos" client_mock.ApiextensionsV1beta1Api.return_value.list_custom_resource_definition.return_value.items = [ item ] client_mock.CustomObjectsApi.return_value.list_cluster_custom_object.side_effect = ApiException( 400) with self.assertRaises(ApiException): service.listMongoObjects(param="value") expected_calls = [ call.ApiextensionsV1beta1Api().list_custom_resource_definition(), call.CustomObjectsApi().list_cluster_custom_object( "operators.ultimaker.com", "v1", "mongos", param="value") ] self.assertEqual(expected_calls, client_mock.mock_calls)