def test_reconnect(self, redis_mock): master = redistools.get_redis() redis_mock.reset_mock() assert master is redistools.get_redis() redis_mock.assert_not_called() master_new = redistools.get_redis(reconnect=True) assert master_new is not master redis_mock.assert_called_once_with(host="myhost", port=6379, db=0)
def test_sentinel_non_standard(self, sentinel_mock): master_for_mock = sentinel_mock.return_value.master_for slave_for_mock = sentinel_mock.return_value.slave_for master = redistools.get_redis() sentinel_mock.assert_called_once_with([("sentinel2", 2222)], socket_timeout=3.0) master_for_mock.assert_called_once_with("mymaster1", socket_timeout=3.0) slave_for_mock.assert_called_once_with("mymaster1", socket_timeout=3.0) sentinel_mock.reset_mock() slave = redistools.get_redis(master=False) sentinel_mock.assert_not_called() # Uses cached slave assert master != slave
def test_sentinel_defaults(self, sentinel_mock): master_for_mock = sentinel_mock.return_value.master_for slave_for_mock = sentinel_mock.return_value.slave_for master = redistools.get_redis() sentinel_mock.assert_called_once_with([("sentinel1", 26379)], socket_timeout=0.2) master_for_mock.assert_called_once_with("redis", socket_timeout=0.2) slave_for_mock.assert_called_once_with("redis", socket_timeout=0.2) sentinel_mock.reset_mock() slave = redistools.get_redis(master=False) sentinel_mock.assert_not_called() # Uses cached slave assert master != slave
def test_getset_json(self): redistools.set_json("mykey", {"foo": "bar"}) assert {"foo": "bar"} == redistools.get_json("mykey") assert redistools.get_json("otherkey") is None master = redistools.get_redis() assert b'{"foo": "bar"}' == master.get("mykey")
def test_non_standard_db_port(self, redis_mock): redistools.get_redis() redis_mock.assert_called_once_with(host="myhost", port=4567, db=23)
def test_defaults(self, redis_mock): master = redistools.get_redis() redis_mock.assert_called_once_with(host="myhost", port=6379, db=0) slave = redistools.get_redis(master=False) assert master is slave return master