You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/06/05 15:51:28 UTC

[GitHub] [airflow] sunki-hong commented on a change in pull request #16241: Update copy command for s3 to redshift

sunki-hong commented on a change in pull request #16241:
URL: https://github.com/apache/airflow/pull/16241#discussion_r646005770



##########
File path: tests/providers/amazon/aws/transfers/test_s3_to_redshift.py
##########
@@ -65,6 +65,45 @@ def test_execute(self, mock_run, mock_session):
         assert secret_key in copy_query
         assert_equal_ignore_multiple_spaces(self, mock_run.call_args[0][0], copy_query)
 
+    @mock.patch("boto3.session.Session")
+    @mock.patch("airflow.providers.postgres.hooks.postgres.PostgresHook.run")
+    def test_execute_with_column_list(self, 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)
+        mock_session.return_value.access_key = access_key
+        mock_session.return_value.secret_key = secret_key
+        mock_session.return_value.token = None
+
+        schema = "schema"
+        table = "table"
+        s3_bucket = "bucket"
+        s3_key = "key"
+        column_list = ["column_1", "column_2"]
+        copy_options = ""
+
+        op = S3ToRedshiftOperator(
+            schema=schema,
+            table=table,
+            s3_bucket=s3_bucket,
+            s3_key=s3_key,
+            column_list=column_list,
+            copy_options=copy_options,
+            redshift_conn_id="redshift_conn_id",
+            aws_conn_id="aws_conn_id",
+            task_id="task_id",
+            dag=None,
+        )
+        op.execute(None)
+
+        credentials_block = build_credentials_block(mock_session.return_value)
+        copy_query = op._build_copy_query(credentials_block, copy_options)

Review comment:
       Hi @mik-laj :) Thanks for the review.
   
   Could you explain it in more detail? 
   
   Do you want the result of `op._build_copy_query` to be asserted with expected plain copy text?
   I thought that line 105 ` assert_equal_ignore_multiple_spaces(self, mock_run.call_args[0][0], copy_query)` checks the result
   
   
   FYI expected `copy_query` looks like this 
   ```sql
   COPY schema.table (column_1, column_2)
   FROM 's3://bucket/key'
   with credentials
   'aws_access_key_id=aws_access_key_id;aws_secret_access_key=aws_secret_access_key'
   ;
   ```
   
   
   
   




-- 
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:
users@infra.apache.org