smentek commented on a change in pull request #4090: [AIRFLOW-3250] Fix for 
Redis Hook for not authorised connection calls
URL: https://github.com/apache/incubator-airflow/pull/4090#discussion_r234934576
 
 

 ##########
 File path: tests/contrib/sensors/test_redis_sensor.py
 ##########
 @@ -47,22 +47,25 @@ def setUp(self):
             key='test_key'
         )
 
-    @patch("airflow.contrib.hooks.redis_hook.RedisHook.key_exists")
-    def test_poke(self, key_exists):
-        key_exists.return_value = True
-        self.assertTrue(self.sensor.poke(None))
+    @patch("airflow.contrib.sensors.redis_key_sensor.RedisHook")
+    def test_poke(self, RedisHook):
+        RedisHook.return_value.get_conn.return_value.exists.side_effect = 
[True, False]
+        self.assertTrue(self.sensor.poke(None), "Key exists on first call.")
+        RedisHook.assert_called_once_with('redis_default')
+        RedisHook.return_value.get_conn.assert_called_once_with()
+        
RedisHook.return_value.get_conn.return_value.exists.assert_called_once_with('test_key')
+        self.assertFalse(self.sensor.poke(None), "Key does NOT exists on 
second call.")
 
-        key_exists.return_value = False
-        self.assertFalse(self.sensor.poke(None))
-
-    @patch("airflow.contrib.hooks.redis_hook.StrictRedis.exists")
-    def test_existing_key_called(self, redis_client_exists):
+    @patch("airflow.contrib.hooks.redis_hook.StrictRedis")
+    @patch('airflow.contrib.hooks.redis_hook.RedisHook.get_connection')
 
 Review comment:
   Why do we want to test redis in tests for airflow project? I understand that 
we may need some integration tests (and the best would be to have them separate 
to unit tests) but it does not mean we need all of it to connect everywhere all 
the time :) That focus of integration as ultimate remedy, is the reason that 
current ticket even exist. AIRFLOW-999 had integration tests, but no proper 
unit tests.

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


With regards,
Apache Git Services

Reply via email to