Skip to content

Commit adc5116

Browse files
authored
RESP3 fix async tests (#2806)
* fix tests * add stralgo callback in resp2 * add callback to acl list in resp2
1 parent e4faf3a commit adc5116

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

redis/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ class AbstractRedis:
812812
"HGETALL": lambda r: r and pairs_to_dict(r) or {},
813813
"MEMORY STATS": parse_memory_stats,
814814
"MODULE LIST": lambda r: [pairs_to_dict(m) for m in r],
815+
"STRALGO": parse_stralgo,
816+
"ACL LIST": lambda r: list(map(str_if_bytes, r)),
815817
# **string_keys_to_dict(
816818
# "COPY "
817819
# "HEXISTS HMSET MOVE MSETNX PERSIST "
@@ -833,7 +835,6 @@ class AbstractRedis:
833835
# **string_keys_to_dict("ZRANK ZREVRANK", int_or_none),
834836
# **string_keys_to_dict("BGREWRITEAOF BGSAVE", lambda r: True),
835837
# "ACL HELP": lambda r: list(map(str_if_bytes, r)),
836-
# "ACL LIST": lambda r: list(map(str_if_bytes, r)),
837838
# "ACL LOAD": bool_ok,
838839
# "ACL SAVE": bool_ok,
839840
# "ACL USERS": lambda r: list(map(str_if_bytes, r)),
@@ -855,7 +856,6 @@ class AbstractRedis:
855856
# "MODULE UNLOAD": parse_module_result,
856857
# "OBJECT": parse_object,
857858
# "QUIT": bool_ok,
858-
# "STRALGO": parse_stralgo,
859859
# "RANDOMKEY": lambda r: r and r or None,
860860
# "SCRIPT EXISTS": lambda r: list(map(bool, r)),
861861
# "SCRIPT KILL": bool_ok,

tests/test_asyncio/test_commands.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ class TestResponseCallbacks:
7474
"""Tests for the response callback system"""
7575

7676
async def test_response_callbacks(self, r: redis.Redis):
77-
resp3_callbacks = redis.Redis.RESPONSE_CALLBACKS.copy()
78-
resp3_callbacks.update(redis.Redis.RESP3_RESPONSE_CALLBACKS)
79-
assert_resp_response(
80-
r, r.response_callbacks, redis.Redis.RESPONSE_CALLBACKS, resp3_callbacks
81-
)
77+
callbacks = redis.Redis.RESPONSE_CALLBACKS
78+
if is_resp2_connection(r):
79+
callbacks.update(redis.Redis.RESP2_RESPONSE_CALLBACKS)
80+
else:
81+
callbacks.update(redis.Redis.RESP3_RESPONSE_CALLBACKS)
82+
assert r.response_callbacks == callbacks
8283
assert id(r.response_callbacks) != id(redis.Redis.RESPONSE_CALLBACKS)
8384
r.set_response_callback("GET", lambda x: "static")
8485
await r.set("a", "foo")

tests/test_commands.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class TestResponseCallbacks:
5959

6060
def test_response_callbacks(self, r):
6161
callbacks = redis.Redis.RESPONSE_CALLBACKS
62-
if not is_resp2_connection(r):
62+
if is_resp2_connection(r):
63+
callbacks.update(redis.Redis.RESP2_RESPONSE_CALLBACKS)
64+
else:
6365
callbacks.update(redis.Redis.RESP3_RESPONSE_CALLBACKS)
6466
assert r.response_callbacks == callbacks
6567
assert id(r.response_callbacks) != id(redis.Redis.RESPONSE_CALLBACKS)

tests/test_credentials.py

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ def test_change_username_password_on_existing_connection(self, r, request):
198198
password = "origin_password"
199199
new_username = "new_username"
200200
new_password = "new_password"
201+
202+
def teardown():
203+
r.acl_deluser(new_username)
204+
205+
request.addfinalizer(teardown)
206+
201207
init_acl_user(r, request, username, password)
202208
r2 = _get_client(
203209
redis.Redis, request, flushdb=False, username=username, password=password

0 commit comments

Comments
 (0)