Exemplo n.º 1
0
    def test_job_update(self, mock_hook):
        mock_hook.return_value.update_transfer_job.return_value = VALID_TRANSFER_JOB_GCS
        body = {
            'transferJob': {
                'description': 'example-name'
            },
            'updateTransferJobFieldMask': DESCRIPTION
        }

        op = CloudDataTransferServiceUpdateJobOperator(
            job_name=JOB_NAME,
            body=body,
            task_id=TASK_ID,
            google_impersonation_chain=IMPERSONATION_CHAIN,
        )
        result = op.execute(None)

        mock_hook.assert_called_once_with(
            api_version='v1',
            gcp_conn_id='google_cloud_default',
            impersonation_chain=IMPERSONATION_CHAIN,
        )
        mock_hook.return_value.update_transfer_job.assert_called_once_with(
            job_name=JOB_NAME, body=body)
        assert result == VALID_TRANSFER_JOB_GCS
Exemplo n.º 2
0
 def test_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 = CloudDataTransferServiceUpdateJobOperator(
         job_name='{{ dag.dag_id }}',
         body={'transferJob': {"name": "{{ dag.dag_id }}"}},
         task_id='task-id',
         dag=self.dag,
     )
     ti = TaskInstance(op, DEFAULT_DATE)
     ti.render_templates()
     self.assertEqual(dag_id, getattr(op, 'body')['transferJob']['name'])
     self.assertEqual(dag_id, getattr(op, 'job_name'))
Exemplo n.º 3
0
# [END howto_operator_gcp_transfer_update_job_body]

with models.DAG(
        "example_gcp_transfer",
        schedule_interval='@once',  # Override to match your needs
        start_date=days_ago(1),
        tags=["example"],
) as dag:

    create_transfer = CloudDataTransferServiceCreateJobOperator(
        task_id="create_transfer", body=gcs_to_gcs_transfer_body)

    # [START howto_operator_gcp_transfer_update_job]
    update_transfer = CloudDataTransferServiceUpdateJobOperator(
        task_id="update_transfer",
        job_name="{{task_instance.xcom_pull('create_transfer')['name']}}",
        body=update_body,
    )
    # [END howto_operator_gcp_transfer_update_job]

    wait_for_transfer = CloudDataTransferServiceJobStatusSensor(
        task_id="wait_for_transfer",
        job_name="{{task_instance.xcom_pull('create_transfer')['name']}}",
        project_id=GCP_PROJECT_ID,
        expected_statuses={GcpTransferOperationStatus.SUCCESS},
    )

    list_operations = CloudDataTransferServiceListOperationsOperator(
        task_id="list_operations",
        request_filter={
            FILTER_PROJECT_ID: