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 2018/12/30 19:01:15 UTC

[GitHub] r39132 closed pull request #4402: [AIRFLOW-3597] Add tests for JdbcOperator

r39132 closed pull request #4402: [AIRFLOW-3597] Add tests for JdbcOperator
URL: https://github.com/apache/incubator-airflow/pull/4402
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/operators/jdbc_operator.py b/airflow/operators/jdbc_operator.py
index 1c9423d5ab..f5f5c1ad29 100644
--- a/airflow/operators/jdbc_operator.py
+++ b/airflow/operators/jdbc_operator.py
@@ -46,13 +46,14 @@ class JdbcOperator(BaseOperator):
     ui_color = '#ededed'
 
     @apply_defaults
-    def __init__(
-            self, sql,
-            jdbc_conn_id='jdbc_default', autocommit=False, parameters=None,
-            *args, **kwargs):
+    def __init__(self,
+                 sql,
+                 jdbc_conn_id='jdbc_default',
+                 autocommit=False,
+                 parameters=None,
+                 *args, **kwargs):
         super(JdbcOperator, self).__init__(*args, **kwargs)
         self.parameters = parameters
-
         self.sql = sql
         self.jdbc_conn_id = jdbc_conn_id
         self.autocommit = autocommit
diff --git a/tests/operators/test_jdbc_operator.py b/tests/operators/test_jdbc_operator.py
new file mode 100644
index 0000000000..9d8bde2e17
--- /dev/null
+++ b/tests/operators/test_jdbc_operator.py
@@ -0,0 +1,43 @@
+# -*- 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 mock import patch
+
+from airflow.operators.jdbc_operator import JdbcOperator
+
+
+class TestJdbcOperator(unittest.TestCase):
+
+    def setUp(self):
+        self.kwargs = dict(
+            sql='sql',
+            task_id='test_jdbc_operator',
+            dag=None
+        )
+
+    @patch('airflow.operators.jdbc_operator.JdbcHook')
+    def test_execute(self, mock_jdbc_hook):
+        jdbc_operator = JdbcOperator(**self.kwargs)
+        jdbc_operator.execute(context={})
+
+        mock_jdbc_hook.assert_called_once_with(jdbc_conn_id=jdbc_operator.jdbc_conn_id)
+        mock_jdbc_hook.return_value.run.assert_called_once_with(
+            jdbc_operator.sql, jdbc_operator.autocommit, parameters=jdbc_operator.parameters)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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