airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] smentek commented on a change in pull request #4090: [AIRFLOW-3250] Fix for Redis Hook for not authorised connection calls
Date Mon, 19 Nov 2018 15:02:13 GMT
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_r234651267
 
 

 ##########
 File path: tests/contrib/hooks/test_redis_hook.py
 ##########
 @@ -19,32 +19,116 @@
 
 
 import unittest
-from mock import patch
-
+from mock import patch, MagicMock
 from airflow import configuration
 from airflow.contrib.hooks.redis_hook import RedisHook
 
 
 class TestRedisHook(unittest.TestCase):
+
     def setUp(self):
         configuration.load_test_config()
 
-    def test_get_conn(self):
+    @patch('airflow.contrib.hooks.redis_hook.StrictRedis')
+    @patch('airflow.contrib.hooks.redis_hook.RedisHook.get_connection')
+    def test_get_conn(self, redis_hook_get_connection_mock, StrictRedisMock):
+        HOST = 'localhost'
+        PORT = 6379
+        PASSWORD = 's3cret!'
+        DB = 0
+
+        extra_dejson_mock = MagicMock()
+        extra_dejson_mock.get.return_value = DB
+        connection_parameters = MagicMock()
+        connection_parameters.configure_mock(
+            host=HOST,
+            port=PORT,
+            password=PASSWORD,
+            extra_dejson=extra_dejson_mock)
+        redis_hook_get_connection_mock.return_value = connection_parameters
+
+        hook = RedisHook(redis_conn_id='redis_default')
+        self.assertEqual(hook.redis, None)
+
+        self.assertEqual(hook.host, None, 'host initialised as None.')
+        self.assertEqual(hook.port, None, 'port initialised as None.')
+        self.assertEqual(hook.password, None, 'password initialised as None.')
+        self.assertEqual(hook.db, None, 'db initialised as None.')
+
+        self.assertIs(hook.get_conn(), hook.get_conn(), 'Connection initialized only if None.')
+
+        StrictRedisMock.assert_called_once_with(
+            host=HOST,
+            port=PORT,
+            password=PASSWORD,
+            db=DB)
+
+    @patch('airflow.contrib.hooks.redis_hook.StrictRedis')
+    @patch('airflow.contrib.hooks.redis_hook.RedisHook.get_connection')
 
 Review comment:
   Done.

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