def test_override_default_params(self):
        for key, val in defaults.REDIS_PARAMS.items():
            self.expected_params[key] = self.settings['REDIS_PARAMS'][key] = object()

        server = from_settings(self.settings)
        assert server is self.redis_cls.return_value
        self.redis_cls.assert_called_with(**self.expected_params)
    def test_redis_default(self):
        settings = Settings()

        server = connection.from_settings(settings)
        connect_args = server.connection_pool.connection_kwargs

        self.assertEqual(connect_args['host'], 'localhost')
        self.assertEqual(connect_args['port'], 6379)
    def test_redis_host_port_fallback(self):
        settings = Settings(
            dict(REDIS_HOST='baz', REDIS_PORT=1337, REDIS_URL=None))

        server = connection.from_settings(settings)
        connect_args = server.connection_pool.connection_kwargs

        self.assertEqual(connect_args['host'], 'baz')
        self.assertEqual(connect_args['port'], 1337)
    def test_redis_host_port(self):
        settings = Settings({
            'REDIS_HOST': 'localhost',
            'REDIS_PORT': 9001,
        })

        server = connection.from_settings(settings)
        connect_args = server.connection_pool.connection_kwargs

        self.assertEqual(connect_args['host'], 'localhost')
        self.assertEqual(connect_args['port'], 9001)
    def test_redis_url(self):
        settings = Settings({
            'REDIS_URL': 'redis://*****:*****@localhost:9001/42',
        })

        server = connection.from_settings(settings)
        connect_args = server.connection_pool.connection_kwargs

        self.assertEqual(connect_args['host'], 'localhost')
        self.assertEqual(connect_args['port'], 9001)
        self.assertEqual(connect_args['password'], 'bar')
        self.assertEqual(connect_args['db'], 42)
    def test_redis_url_precedence(self):
        settings = Settings(
            dict(REDIS_HOST='baz',
                 REDIS_PORT=1337,
                 REDIS_URL='redis://*****:*****@localhost:9001/42'))

        server = connection.from_settings(settings)
        connect_args = server.connection_pool.connection_kwargs

        self.assertEqual(connect_args['host'], 'localhost')
        self.assertEqual(connect_args['port'], 9001)
        self.assertEqual(connect_args['password'], 'bar')
        self.assertEqual(connect_args['db'], 42)
 def test_default_params(self):
     server = from_settings(self.settings)
     assert server is self.redis_cls.return_value
     self.redis_cls.assert_called_with(**dict(defaults.REDIS_PARAMS, **self.expected_params))
 def test_redis_cls_custom_path(self):
     self.settings['REDIS_PARAMS']['redis_cls'] = 'mock.Mock'
     server = from_settings(self.settings)
     assert isinstance(server, mock.Mock)
 def test_redis_cls_default(self):
     server = from_settings(Settings())
     assert isinstance(server, defaults.REDIS_CLS)