Exemplo n.º 1
0
 def test_operation_get_should_throw_ex_when_operation_name_none(self, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         op = GcpTransferServiceOperationGetOperator(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()
Exemplo n.º 2
0
 def test_operation_get(self, mock_hook):
     mock_hook.return_value.get_transfer_operation.return_value = VALID_OPERATION
     op = GcpTransferServiceOperationGetOperator(operation_name=OPERATION_NAME, task_id=TASK_ID)
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default')
     mock_hook.return_value.get_transfer_operation.assert_called_once_with(operation_name=OPERATION_NAME)
     self.assertEqual(result, VALID_OPERATION)
 def test_operation_get_should_throw_ex_when_operation_name_none(self, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         op = GcpTransferServiceOperationGetOperator(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_get(self, mock_hook):
     mock_hook.return_value.get_transfer_operation.return_value = VALID_OPERATION
     op = GcpTransferServiceOperationGetOperator(operation_name=OPERATION_NAME, task_id=TASK_ID)
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default')
     mock_hook.return_value.get_transfer_operation.assert_called_once_with(operation_name=OPERATION_NAME)
     self.assertEqual(result, VALID_OPERATION)
Exemplo n.º 5
0
 def test_operation_get_with_templates(self, _):
     dag_id = 'test_dag_id'
     args = {'start_date': DEFAULT_DATE}
     self.dag = DAG(dag_id, default_args=args)
     op = GcpTransferServiceOperationGetOperator(
         operation_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, 'operation_name'))
    # [START howto_operator_gcp_transfer_list_operations]
    list_operations = GcpTransferServiceOperationsListOperator(
        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']}}"
            ],
        },
    )
    # [END howto_operator_gcp_transfer_list_operations]

    # [START howto_operator_gcp_transfer_get_operation]
    get_operation = GcpTransferServiceOperationGetOperator(
        task_id="get_operation",
        operation_name=
        "{{task_instance.xcom_pull('list_operations')[0]['name']}}")
    # [END howto_operator_gcp_transfer_get_operation]

    # [START howto_operator_gcp_transfer_resume_operation]
    resume_operation = GcpTransferServiceOperationResumeOperator(
        task_id="resume_operation",
        operation_name="{{task_instance.xcom_pull('get_operation')['name']}}")
    # [END howto_operator_gcp_transfer_resume_operation]

    # [START howto_operator_gcp_transfer_wait_operation]
    wait_for_operation_to_end = GCPTransferServiceWaitForJobStatusSensor(
        task_id="wait_for_operation_to_end",
        job_name=
        "{{task_instance.xcom_pull('create_transfer_job_from_aws')['name']}}",
        project_id=GCP_PROJECT_ID,