Пример #1
0
 def test_execute(self, mock_hook):
     mock_instance = mock_hook.return_value
     operator = FileToGoogleCloudStorageOperator(
         task_id='gcs_to_file_sensor', dag=self.dag, **self._config)
     operator.execute(None)
     mock_instance.upload.assert_called_once_with(
         bucket_name=self._config['bucket'],
         filename=self._config['src'],
         gzip=self._config['gzip'],
         mime_type=self._config['mime_type'],
         object_name=self._config['dst'])
Пример #2
0
 def test_init(self):
     operator = FileToGoogleCloudStorageOperator(
         task_id='file_to_gcs_operator', dag=self.dag, **self._config)
     self.assertEqual(operator.src, self._config['src'])
     self.assertEqual(operator.dst, self._config['dst'])
     self.assertEqual(operator.bucket, self._config['bucket'])
     self.assertEqual(operator.mime_type, self._config['mime_type'])
     self.assertEqual(operator.gzip, self._config['gzip'])
Пример #3
0
    create_bucket2 = GCSCreateBucketOperator(task_id="create_bucket2",
                                             bucket_name=BUCKET_2,
                                             project_id=PROJECT_ID)

    list_buckets = GCSListObjectsOperator(task_id="list_buckets",
                                          bucket=BUCKET_1)

    list_buckets_result = BashOperator(
        task_id="list_buckets_result",
        bash_command="echo \"{{ task_instance.xcom_pull('list_buckets') }}\"",
    )

    upload_file = FileToGoogleCloudStorageOperator(
        task_id="upload_file",
        src=PATH_TO_UPLOAD_FILE,
        dst=BUCKET_FILE_LOCATION,
        bucket=BUCKET_1,
    )

    transform_file = GcsFileTransformOperator(
        task_id="transform_file",
        source_bucket=BUCKET_1,
        source_object=BUCKET_FILE_LOCATION,
        transform_script=["python", PATH_TO_TRANSFORM_SCRIPT])
    # [START howto_operator_gcs_bucket_create_acl_entry_task]
    gcs_bucket_create_acl_entry_task = GCSBucketCreateAclEntryOperator(
        bucket=BUCKET_1,
        entity=GCS_ACL_ENTITY,
        role=GCS_ACL_BUCKET_ROLE,
        task_id="gcs_bucket_create_acl_entry_task",
    )