def test_different_error_reraised(self, mock_hook): mock_hook.return_value.get_instance.return_value = None op = BigtableCreateInstanceOperator(project_id=PROJECT_ID, instance_id=INSTANCE_ID, main_cluster_id=CLUSTER_ID, main_cluster_zone=CLUSTER_ZONE, task_id="id", gcp_conn_id=GCP_CONN_ID) mock_hook.return_value.create_instance.side_effect = mock.Mock( side_effect=google.api_core.exceptions.GoogleAPICallError('error')) with self.assertRaises(google.api_core.exceptions.GoogleAPICallError): op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID) mock_hook.return_value.create_instance.assert_called_once_with( cluster_nodes=None, cluster_storage_type=None, instance_display_name=None, instance_id=INSTANCE_ID, instance_labels=None, instance_type=None, main_cluster_id=CLUSTER_ID, main_cluster_zone=CLUSTER_ZONE, project_id=PROJECT_ID, replica_cluster_id=None, replica_cluster_zone=None, timeout=None)
def test_create_instance_with_replicas_that_doesnt_exists(self, mock_hook): mock_hook.return_value.get_instance.return_value = None op = BigtableCreateInstanceOperator( project_id=PROJECT_ID, instance_id=INSTANCE_ID, main_cluster_id=CLUSTER_ID, main_cluster_zone=CLUSTER_ZONE, replica_clusters=REPLICATE_CLUSTERS, task_id="id", gcp_conn_id=GCP_CONN_ID, impersonation_chain=IMPERSONATION_CHAIN, ) op.execute(None) mock_hook.assert_called_once_with( gcp_conn_id=GCP_CONN_ID, impersonation_chain=IMPERSONATION_CHAIN, ) mock_hook.return_value.create_instance.assert_called_once_with( cluster_nodes=None, cluster_storage_type=None, instance_display_name=None, instance_id=INSTANCE_ID, instance_labels=None, instance_type=None, main_cluster_id=CLUSTER_ID, main_cluster_zone=CLUSTER_ZONE, project_id=PROJECT_ID, replica_clusters=REPLICATE_CLUSTERS, replica_cluster_id=None, replica_cluster_zone=None, timeout=None, )
def test_create_instance_that_exists_empty_project_id(self, mock_hook): mock_hook.return_value.get_instance.return_value = mock.Mock(Instance) op = BigtableCreateInstanceOperator(instance_id=INSTANCE_ID, main_cluster_id=CLUSTER_ID, main_cluster_zone=CLUSTER_ZONE, task_id="id", gcp_conn_id=GCP_CONN_ID) op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID) mock_hook.return_value.create_instance.assert_not_called()
def test_create_instance_that_exists(self, mock_hook): mock_hook.return_value.get_instance.return_value = mock.Mock(Instance) op = BigtableCreateInstanceOperator( project_id=PROJECT_ID, instance_id=INSTANCE_ID, main_cluster_id=CLUSTER_ID, main_cluster_zone=CLUSTER_ZONE, task_id="id", gcp_conn_id=GCP_CONN_ID, impersonation_chain=IMPERSONATION_CHAIN, ) op.execute(None) mock_hook.assert_called_once_with( gcp_conn_id=GCP_CONN_ID, impersonation_chain=IMPERSONATION_CHAIN, ) mock_hook.return_value.create_instance.assert_not_called()