airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] jmcarp closed pull request #3959: [WIP] Backfill unit test for postgres operator.
Date Thu, 27 Sep 2018 02:49:53 GMT
jmcarp closed pull request #3959: [WIP] Backfill unit test for postgres operator.
URL: https://github.com/apache/incubator-airflow/pull/3959
 
 
   

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/tests/operators/test_postgres_operator.py b/tests/operators/test_postgres_operator.py
new file mode 100644
index 0000000000..9a1dc5db7e
--- /dev/null
+++ b/tests/operators/test_postgres_operator.py
@@ -0,0 +1,51 @@
+# -*- 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 airflow.operators.postgres_operator import PostgresOperator
+
+try:
+    from unittest import mock
+except ImportError:
+    try:
+        import mock
+    except ImportError:
+        mock = None
+
+
+class TestPostgresOperator(unittest.TestCase):
+
+    @mock.patch('airflow.operators.postgres_operator.PostgresHook')
+    def test_execute(self, mock_hook):
+        operator = PostgresOperator(
+            task_id='postgres',
+            sql='select 1',
+        )
+
+        operator.execute(None)
+        mock_hook.assert_called_once_with(
+            postgres_conn_id='postgres_default',
+            schema=None,
+        )
+        mock_hook.return_value.run.assert_called_once_with(
+            'select 1',
+            False,
+            parameters=None,
+        )


 

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

Mime
View raw message