feluelle commented on a change in pull request #6604: [AIRFLOW-5920] Neo4j 
operator and hook
URL: https://github.com/apache/airflow/pull/6604#discussion_r352659460
 
 

 ##########
 File path: tests/contrib/hooks/test_neo4j_hook.py
 ##########
 @@ -0,0 +1,91 @@
+# -*- 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.
+"""Test the Neo4J Hook provides the expected interface to the operator
+and makes the right calls to the underlying driver"""
+import unittest
+from unittest.mock import Mock, patch
+
+from airflow.contrib.hooks import neo4j_hook
+from airflow.models import Connection
+from airflow.utils import db
+
+
+class TestNeo4JHook(unittest.TestCase):
+    """This class provides all the test methods for the Neo4j hook"""
+
+    _conn_id = 'neo4j_conn_id_test'
+    _hook = None
+
+    def setUp(self):
+        """Instantiates the hook and stores it in the test class to support 
test execution"""
+        self._hook = neo4j_hook.Neo4JHook(self._conn_id)
+
+    @patch('airflow.contrib.hooks.neo4j_hook.Neo4JHook.get_config')
+    @patch('airflow.contrib.hooks.neo4j_hook.Neo4JHook.get_driver')
+    @patch('airflow.contrib.hooks.neo4j_hook.Neo4JHook.get_session')
+    def test_run_query_with_session(self, mock_get_config, mock_get_driver, 
mock_get_session):
+        """
+        Proves that the run_query() method makes calls to the supporting 
methods
+        :param mock_get_config: Stub to test the call to this function
+        :param mock_get_driver: Stub to test the call to this function
+        :param mock_get_session: Stub to test the call to this function
+        """
+        self._hook.run_query(cypher_query="QUERY")
+        assert mock_get_config.called
+        assert mock_get_driver.called
+        assert mock_get_session.called
+        # assert result.assert_called_once_with(lambda tx, inputs: 
tx.run("QUERY", inputs), None)
 
 Review comment:
   It would be better to use `mock_obj.assert_called_once_with` instead of 
`assert mock_obj.called`. You only want it to be called once, don't you?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to