feluelle commented on a change in pull request #7688: [AIRFLOW-6794] Allow AWS 
Operator RedshiftToS3Transfer To Run a Custom Query
URL: https://github.com/apache/airflow/pull/7688#discussion_r400920941
 
 

 ##########
 File path: tests/providers/amazon/aws/operators/test_redshift_to_s3.py
 ##########
 @@ -76,3 +76,55 @@ def test_execute(self, table_as_file_name, expected_s3_key, 
mock_run, mock_sessi
 
         assert mock_run.call_count == 1
         assert_equal_ignore_multiple_spaces(self, mock_run.call_args[0][0], 
unload_query)
+
+    @parameterized.expand([
+        [None],
+        ["SELECT * FROM schema.table;"],
+    ])
+    @mock.patch("boto3.session.Session")
+    @mock.patch("airflow.providers.postgres.hooks.postgres.PostgresHook.run")
+    def test_transfer_customquery_success(self, expected_custom_select_query, 
mock_run, mock_session,):
+        access_key = "aws_access_key_id"
+        secret_key = "aws_secret_access_key"
+        mock_session.return_value = Session(access_key, secret_key)
+        custom_select_query = "SELECT * FROM schema.table;"
+        schema = "schema"
+        table = "table"
+        s3_bucket = "bucket"
+        s3_key = "key"
+        unload_options = ['HEADER', ]
+
+        RedshiftToS3Transfer(
+            custom_select_query=custom_select_query,
+            schema=schema,
+            table=table,
+            s3_bucket=s3_bucket,
+            s3_key=s3_key,
+            unload_options=unload_options,
+            include_header=True,
+            redshift_conn_id="redshift_conn_id",
+            aws_conn_id="aws_conn_id",
+            task_id="task_id",
+            dag=None
+        ).execute(None)
+
+        unload_options = '\n\t\t\t'.join(unload_options)
+        if expected_custom_select_query:
+            select_query = expected_custom_select_query
+        else:
+            select_query = "SELECT * FROM schema.table;"
 
 Review comment:
   ```suggestion
           select_query = expected_custom_select_query or "SELECT * FROM 
schema.table;"
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to