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/03/07 10:22:00 UTC

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #6670: [AIRFLOW-4816]MySqlToS3Operator

nuclearpinguin commented on a change in pull request #6670: [AIRFLOW-4816]MySqlToS3Operator
URL: https://github.com/apache/airflow/pull/6670#discussion_r389244322
 
 

 ##########
 File path: tests/providers/amazon/aws/operators/test_mysql_to_s3.py
 ##########
 @@ -0,0 +1,61 @@
+#
+# 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
+
+import pandas as pd
+
+from airflow.operators.mysql_to_s3_operator import MySQLToS3Operator
+
+
+class TestMySqlToS3Operator(unittest.TestCase):
+
+    @mock.patch("airflow.operators.mysql_to_s3_operator.tempfile.NamedTemporaryFile")
+    @mock.patch("airflow.operators.mysql_to_s3_operator.S3Hook")
+    @mock.patch("airflow.operators.mysql_to_s3_operator.MySqlHook")
+    def test_execute(self, mock_mysql_hook, mock_s3_hook, temp_mock):
+        query = "query"
+        s3_bucket = "bucket"
+        s3_key = "key"
+
+        test_df = pd.DataFrame({'a': '1', 'b': '2'}, index=[0, 1])
+        get_pandas_df_mock = mock_mysql_hook.return_value.get_pandas_df
+        get_pandas_df_mock.return_value = test_df
+
+        op = MySQLToS3Operator(query=query,
+                               s3_bucket=s3_bucket,
+                               s3_key=s3_key,
+                               mysql_conn_id="mysql_conn_id",
+                               aws_conn_id="aws_conn_id",
+                               task_id="task_id",
+                               header=False,
+                               index=False,
+                               dag=None
+                               )
+        op.execute(None)
+        mock_mysql_hook.assert_called_once_with(mysql_conn_id="mysql_conn_id")
+        mock_s3_hook.assert_called_once_with(aws_conn_id="aws_conn_id", verify=None)
+
+        get_pandas_df_mock.assert_called_once_with(query)
+
+        temp_mock.assert_called_once_with(mode='r+', suffix=".csv")
+        temp_mock.return_value.__enter__.return_value.name = "file"
+        mock_s3_hook.return_value.load_file.assert_called_once_with(filename=temp_mock.__enter__.name,
 
 Review comment:
   ```suggestion
           filename = "file"
           temp_mock.return_value.__enter__.return_value.name = filename
           mock_s3_hook.return_value.load_file.assert_called_once_with(filename=filename,
   ```

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


With regards,
Apache Git Services