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/02/03 15:24:40 UTC

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

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

 ##########
 File path: tests/operators/test_mysql_to_s3_operator.py
 ##########
 @@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+#
+# 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 boto3.session import Session
+
+from airflow.operators.mysql_to_s3_operator import MySQLToS3Operator
+
+
+class TestMySqlToS3Operator(unittest.TestCase):
+
+    @mock.patch("boto3.session.Session")
+    @mock.patch("airflow.hooks.mysql_hook.MySqlHook.run")
+    def test_execute(self, mock_hook, mock_session):
+        access_key = "aws_access_key_id"
+        secret_key = "aws_secret_access_key"
+        query = "query"
+        s3_bucket = "bucket"
+        s3_key = "key"
+        mock_session.return_value = Session(access_key, secret_key)
+
+        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_hook.assert_called_once_with(mysql_conn_id="mysql_conn_id")
+
+        mock_hook.return_value.get_pandas_df.assert_called_once_with(query=query)
+
+        test_df = pd.DataFrame({'a': '1', 'b': '2'}, index=[0, 1])
+        mock_hook.return_value.get_pandas_df.return_value = test_df
+
+        mock_hook.return_value.fix_int_dtypes.assert_called_once_with(test_df)
+
+        mock_session.assert_called_once()
+        mock_session.return_value = Session(access_key, secret_key)
 
 Review comment:
   Thanks for your answer. I am afraid that this is not the error. I already changed operator to operators and mock.path to mock.patch (as suggested in error of the test):
   https://github.com/apache/airflow/pull/6670/commits/86bd33cffa8c7b249d4e0cb2677c3fa970d8b323
   https://github.com/apache/airflow/pull/6670/commits/f6d04141da4ecbae902d1871d7459bcef64054c3 

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