def test__sentinel_connect(self): conn_mock = Mock() self.connection_mock.return_value = conn_mock sentinels = [('host1', 12345), ('host2', 12345), ('host3', 12345)] client = pyredis.client.SentinelClient(sentinels=sentinels) client.execute = Mock() self.assertTrue(client._sentinel_connect(sentinel=('host1', 12345))) self.connection_mock.assert_called_with( host='host1', port=12345, conn_timeout=0.1, sentinel=True) client.execute.assert_called_with('PING') self.assertEqual(client._conn, conn_mock)
def test__sentinel_connect_conn_exception(self): conn_mock = Mock() self.connection_mock.return_value = conn_mock sentinels = [('host1', 12345), ('host2', 12345), ('host3', 12345)] client = pyredis.client.SentinelClient(sentinels=sentinels) client.close = Mock() client.execute = Mock() client.execute.side_effect = PyRedisConnError self.assertFalse(client._sentinel_connect(sentinel=('host1', 12345))) self.connection_mock.assert_called_with( host='host1', port=12345, conn_timeout=0.1, sentinel=True) client.execute.assert_called_with('PING') client.close.assert_called_with()