def test_operation_pause_should_throw_ex_when_name_none(self, mock_hook): with self.assertRaises(AirflowException) as cm: op = CloudDataTransferServicePauseOperationOperator(operation_name="", task_id='task-id') op.execute(None) err = cm.exception self.assertIn("The required parameter 'operation_name' is empty or None", str(err)) mock_hook.assert_not_called()
def test_operation_pause(self, mock_hook): op = CloudDataTransferServicePauseOperationOperator( operation_name=OPERATION_NAME, task_id='task-id') op.execute(None) mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default') mock_hook.return_value.pause_transfer_operation.assert_called_once_with( operation_name=OPERATION_NAME)
def test_operation_pause_with_templates(self, _): dag_id = 'test_dag_id' args = {'start_date': DEFAULT_DATE} self.dag = DAG(dag_id, default_args=args) # pylint: disable=attribute-defined-outside-init op = CloudDataTransferServicePauseOperationOperator( operation_name='{{ dag.dag_id }}', gcp_conn_id='{{ dag.dag_id }}', api_version='{{ dag.dag_id }}', task_id=TASK_ID, dag=self.dag, ) ti = TaskInstance(op, DEFAULT_DATE) ti.render_templates() assert dag_id == getattr(op, 'operation_name') assert dag_id == getattr(op, 'gcp_conn_id') assert dag_id == getattr(op, 'api_version')
task_id="create_transfer_job_from_aws", body=aws_to_gcs_transfer_body) # [END howto_operator_gcp_transfer_create_job] wait_for_operation_to_start = CloudDataTransferServiceJobStatusSensor( task_id="wait_for_operation_to_start", job_name= "{{task_instance.xcom_pull('create_transfer_job_from_aws')['name']}}", project_id=GCP_PROJECT_ID, expected_statuses={GcpTransferOperationStatus.IN_PROGRESS}, poke_interval=WAIT_FOR_OPERATION_POKE_INTERVAL, ) # [START howto_operator_gcp_transfer_pause_operation] pause_operation = CloudDataTransferServicePauseOperationOperator( task_id="pause_operation", operation_name= "{{task_instance.xcom_pull('wait_for_operation_to_start', " "key='sensed_operations')[0]['name']}}", ) # [END howto_operator_gcp_transfer_pause_operation] # [START howto_operator_gcp_transfer_list_operations] list_operations = CloudDataTransferServiceListOperationsOperator( task_id="list_operations", request_filter={ FILTER_PROJECT_ID: GCP_PROJECT_ID, FILTER_JOB_NAMES: [ "{{task_instance.xcom_pull('create_transfer_job_from_aws')['name']}}" ], }, )