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 2020/12/20 11:23:01 UTC

[GitHub] [airflow] TobKed commented on a change in pull request #11747: S3ToFTPOperator

TobKed commented on a change in pull request #11747:
URL: https://github.com/apache/airflow/pull/11747#discussion_r546362781



##########
File path: tests/providers/amazon/aws/transfers/test_s3_to_ftp.py
##########
@@ -0,0 +1,43 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import unittest
+from unittest import mock
+
+from airflow.providers.amazon.aws.transfers.s3_to_ftp import S3ToFTPOperator
+
+TASK_ID = 'test_s3_to_ftp'
+BUCKET = 'test-s3-bucket'
+S3_KEY = 'test/test_1_file.csv'
+FTP_PATH = '/tmp/remote_path.txt'
+AWS_CONN_ID = 'aws_default'
+FTP_CONN_ID = 'ftp_default'
+
+
+class TestS3ToSFTPOperator(unittest.TestCase):
+    @mock.patch("airflow.providers.ftp.hooks.ftp.FTPHook.store_file")
+    @mock.patch("airflow.providers.amazon.aws.hooks.s3.S3Hook.get_key")
+    @mock.patch("airflow.providers.amazon.aws.transfers.s3_to_ftp.NamedTemporaryFile")
+    def test_execute(self, mock_local_tmp_file, mock_s3_hook_get_key, mock_ftp_hook_store_file):
+        operator = S3ToFTPOperator(task_id=TASK_ID, s3_bucket=BUCKET, s3_key=S3_KEY, ftp_path=FTP_PATH)
+        operator.execute(None)
+
+        mock_s3_hook_get_key.assert_called_once_with(operator.s3_key, operator.s3_bucket)
+
+        mock_local_tmp_file_value = mock_local_tmp_file.__enter__.return_value

Review comment:
       ```suggestion
          mock_local_tmp_file_value = mock_local_tmp_file.return_value.__enter__.return_value
   ```
   
   It is answer for your question: https://github.com/apache/airflow/pull/11747#issuecomment-748064241
   
   The reason `return_value` is missed is that `NamedTemporaryFile` is initialized and further mocking is operating on it.




----------------------------------------------------------------
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