def test_named_slave_no_sentinel(self):
     sentinel = SentinelExtension(client_class=FakeRedis, sentinel_class=FakeSentinel)
     self.app.config['REDIS_URL'] = 'redis://hostname:7001/3'
     sentinel.init_app(self.app)
     conn = sentinel.slave_for('otherslave', db=6)
     with self.app.app_context():
         self.assertIsNone(sentinel.sentinel._get_current_object())
         with self.assertRaisesRegexp(ValueError, 'Cannot get slave otherslave using non-sentinel configuration'):
             inst = conn._get_current_object()
 def test_named_slave_no_sentinel(self):
     sentinel = SentinelExtension(client_class=FakeRedis,
                                  sentinel_class=FakeSentinel)
     self.app.config['REDIS_URL'] = 'redis://hostname:7001/3'
     sentinel.init_app(self.app)
     conn = sentinel.slave_for('otherslave', db=6)
     with self.app.app_context():
         self.assertIsNone(sentinel.sentinel._get_current_object())
         with self.assertRaisesRegexp(
                 RuntimeError,
                 'Cannot get slave otherslave using non-sentinel configuration'
         ):
             inst = conn._get_current_object()
 def test_named_slave(self):
     sentinel = SentinelExtension(client_class=FakeRedis, sentinel_class=FakeSentinel)
     self.app.config['REDIS_URL'] = 'redis+sentinel://hostname:7001/mymaster/3'
     self.app.config['REDIS_DECODE_RESPONSES'] = True
     sentinel.init_app(self.app)
     conn = sentinel.slave_for('otherslave', db=6)
     with self.app.app_context():
         self.assertIsNotNone(sentinel.sentinel)
         inst = conn._get_current_object()
         self.assertEqual(inst.kwargs['is_master'], False)
         self.assertEqual(inst.kwargs['service_name'], 'otherslave')
         self.assertEqual(inst.kwargs['connection_kwargs']['db'], 6)
         self.assertEqual(inst.kwargs['connection_kwargs']['decode_responses'], True)
 def test_named_slave(self):
     sentinel = SentinelExtension(client_class=FakeRedis,
                                  sentinel_class=FakeSentinel)
     self.app.config[
         'REDIS_URL'] = 'redis+sentinel://hostname:7001/mymaster/3'
     self.app.config['REDIS_DECODE_RESPONSES'] = True
     sentinel.init_app(self.app)
     conn = sentinel.slave_for('otherslave', db=6)
     with self.app.app_context():
         self.assertIsNotNone(sentinel.sentinel)
         inst = conn._get_current_object()
         self.assertEqual(inst.kwargs['is_master'], False)
         self.assertEqual(inst.kwargs['service_name'], 'otherslave')
         self.assertEqual(inst.kwargs['connection_kwargs']['db'], 6)
         self.assertEqual(
             inst.kwargs['connection_kwargs']['decode_responses'], True)