def test_instance_delete_aborts_and_succeeds_if_instance_does_not_exist( self, mock_hook): mock_hook.return_value.get_instance.return_value = None op = CloudSpannerInstanceDeleteOperator(project_id=PROJECT_ID, instance_id=INSTANCE_ID, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default") mock_hook.return_value.delete_instance.assert_not_called() self.assertTrue(result)
def test_instance_delete_missing_project_id(self, mock_hook): mock_hook.return_value.get_instance.return_value = { "name": INSTANCE_ID } op = CloudSpannerInstanceDeleteOperator(instance_id=INSTANCE_ID, task_id="id") result = op.execute(None) mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default") mock_hook.return_value.delete_instance.assert_called_once_with( project_id=None, instance_id=INSTANCE_ID) self.assertTrue(result)
def test_instance_delete_ex_if_param_missing(self, project_id, instance_id, exp_msg, mock_hook): with self.assertRaises(AirflowException) as cm: CloudSpannerInstanceDeleteOperator(project_id=project_id, instance_id=instance_id, task_id="id") err = cm.exception self.assertIn("The required parameter '{}' is empty".format(exp_msg), str(err)) mock_hook.assert_not_called()
# [START howto_operator_spanner_database_delete] spanner_database_delete_task = CloudSpannerInstanceDatabaseDeleteOperator( project_id=GCP_PROJECT_ID, instance_id=GCP_SPANNER_INSTANCE_ID, database_id=GCP_SPANNER_DATABASE_ID, task_id='spanner_database_delete_task') spanner_database_delete_task2 = CloudSpannerInstanceDatabaseDeleteOperator( instance_id=GCP_SPANNER_INSTANCE_ID, database_id=GCP_SPANNER_DATABASE_ID, task_id='spanner_database_delete_task2') # [END howto_operator_spanner_database_delete] # [START howto_operator_spanner_delete] spanner_instance_delete_task = CloudSpannerInstanceDeleteOperator( project_id=GCP_PROJECT_ID, instance_id=GCP_SPANNER_INSTANCE_ID, task_id='spanner_instance_delete_task') spanner_instance_delete_task2 = CloudSpannerInstanceDeleteOperator( instance_id=GCP_SPANNER_INSTANCE_ID, task_id='spanner_instance_delete_task2') # [END howto_operator_spanner_delete] spanner_instance_create_task \ >> spanner_instance_update_task \ >> spanner_database_deploy_task \ >> spanner_database_deploy_task2 \ >> spanner_database_update_task \ >> spanner_database_update_idempotent1_task \ >> spanner_database_update_idempotent2_task \ >> spanner_instance_query_task \ >> spanner_instance_query_task2 \