Skip to content

Commit 6a7ed23

Browse files
committed
more enterprise support
1 parent 139415b commit 6a7ed23

File tree

3 files changed

+66
-13
lines changed

3 files changed

+66
-13
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def pytest_addoption(parser):
3131
def _get_info(redis_url):
3232
client = redis.Redis.from_url(redis_url)
3333
info = client.info()
34+
try:
35+
client.execute_command("CONFIG SET maxmemory 5555555")
36+
client.execute_command("CONFIG SET maxmemory 0")
37+
info["enterprise"] = False
38+
except redis.exceptions.ResponseError:
39+
info["enterprise"] = True
3440
client.connection_pool.disconnect()
3541
return info
3642

@@ -42,6 +48,7 @@ def pytest_sessionstart(session):
4248
arch_bits = info["arch_bits"]
4349
REDIS_INFO["version"] = version
4450
REDIS_INFO["arch_bits"] = arch_bits
51+
REDIS_INFO["enterprise"] = info["enterprise"]
4552

4653
# module info, if the second redis is running
4754
try:
@@ -92,6 +99,11 @@ def skip_ifmodversion_lt(min_version: str, module_name: str):
9299
raise AttributeError("No redis module named {}".format(module_name))
93100

94101

102+
def skip_if_redis_enterprise(func):
103+
return pytest.mark.skipif(REDIS_INFO["enterprise"] == True,
104+
reason="Redis enterprise")
105+
106+
95107
def _get_client(cls, request, single_connection_client=True, flushdb=True,
96108
from_url=None,
97109
**kwargs):

tests/test_commands.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
_get_client,
1414
skip_if_server_version_gte,
1515
skip_if_server_version_lt,
16+
skip_if_redis_enterprise,
1617
skip_unless_arch_bits,
1718
)
1819

@@ -80,6 +81,7 @@ def test_acl_cat_with_category(self, r):
8081
assert 'get' in commands
8182

8283
@skip_if_server_version_lt("6.0.0")
84+
@skip_if_redis_enterprise
8385
def test_acl_deluser(self, r, request):
8486
username = 'redis-py-user'
8587

@@ -104,6 +106,7 @@ def teardown():
104106
assert r.acl_getuser(users[4]) is None
105107

106108
@skip_if_server_version_lt("6.0.0")
109+
@skip_if_redis_enterprise
107110
def test_acl_genpass(self, r):
108111
password = r.acl_genpass()
109112
assert isinstance(password, str)
@@ -117,6 +120,7 @@ def test_acl_genpass(self, r):
117120
assert isinstance(password, str)
118121

119122
@skip_if_server_version_lt("6.0.0")
123+
@skip_if_redis_enterprise
120124
def test_acl_getuser_setuser(self, r, request):
121125
username = 'redis-py-user'
122126

@@ -210,6 +214,7 @@ def test_acl_help(self, r):
210214
assert len(res) != 0
211215

212216
@skip_if_server_version_lt("6.0.0")
217+
@skip_if_redis_enterprise
213218
def test_acl_list(self, r, request):
214219
username = 'redis-py-user'
215220

@@ -222,6 +227,7 @@ def teardown():
222227
assert len(users) == 2
223228

224229
@skip_if_server_version_lt("6.0.0")
230+
@skip_if_redis_enterprise
225231
def test_acl_log(self, r, request):
226232
username = 'redis-py-user'
227233

@@ -257,6 +263,7 @@ def teardown():
257263
assert r.acl_log_reset()
258264

259265
@skip_if_server_version_lt("6.0.0")
266+
@skip_if_redis_enterprise
260267
def test_acl_setuser_categories_without_prefix_fails(self, r, request):
261268
username = 'redis-py-user'
262269

@@ -268,6 +275,7 @@ def teardown():
268275
r.acl_setuser(username, categories=['list'])
269276

270277
@skip_if_server_version_lt("6.0.0")
278+
@skip_if_redis_enterprise
271279
def test_acl_setuser_commands_without_prefix_fails(self, r, request):
272280
username = 'redis-py-user'
273281

@@ -279,6 +287,7 @@ def teardown():
279287
r.acl_setuser(username, commands=['get'])
280288

281289
@skip_if_server_version_lt("6.0.0")
290+
@skip_if_redis_enterprise
282291
def test_acl_setuser_add_passwords_and_nopass_fails(self, r, request):
283292
username = 'redis-py-user'
284293

@@ -312,12 +321,17 @@ def test_client_info(self, r):
312321
assert 'addr' in info
313322

314323
@skip_if_server_version_lt('5.0.0')
315-
def test_client_list_type(self, r):
324+
def test_client_list_types_not_replica(self, r):
316325
with pytest.raises(exceptions.RedisError):
317326
r.client_list(_type='not a client type')
318-
for client_type in ['normal', 'master', 'replica', 'pubsub']:
327+
for client_type in ['normal', 'master', 'pubsub']:
319328
clients = r.client_list(_type=client_type)
320329
assert isinstance(clients, list)
330+
331+
@skip_if_redis_enterprise
332+
def test_client_list_replica(self, r):
333+
clients = r.client_list(_type='replica')
334+
assert isinstance(clients, list)
321335

322336
@skip_if_server_version_lt('6.2.0')
323337
def test_client_list_client_id(self, r, request):
@@ -454,6 +468,7 @@ def test_client_kill_filter_by_laddr(self, r, r2):
454468
assert r.client_kill_filter(laddr=client_2_addr)
455469

456470
@skip_if_server_version_lt('2.8.12')
471+
@skip_if_redis_enterprise
457472
def test_client_kill_filter_by_user(self, r, request):
458473
killuser = 'user_to_kill'
459474
r.acl_setuser(killuser, enabled=True, reset=True,
@@ -467,13 +482,15 @@ def test_client_kill_filter_by_user(self, r, request):
467482
r.acl_deluser(killuser)
468483

469484
@skip_if_server_version_lt('2.9.50')
485+
@skip_if_redis_enterprise
470486
def test_client_pause(self, r):
471487
assert r.client_pause(1)
472488
assert r.client_pause(timeout=1)
473489
with pytest.raises(exceptions.RedisError):
474490
r.client_pause(timeout='not an integer')
475491

476492
@skip_if_server_version_lt('6.2.0')
493+
@skip_if_redis_enterprise
477494
def test_client_unpause(self, r):
478495
assert r.client_unpause() == b'OK'
479496

@@ -491,15 +508,18 @@ def test_client_reply(self, r, r_timeout):
491508
assert r.get('foo') == b'bar'
492509

493510
@skip_if_server_version_lt('6.0.0')
511+
@skip_if_redis_enterprise
494512
def test_client_getredir(self, r):
495513
assert isinstance(r.client_getredir(), int)
496514
assert r.client_getredir() == -1
497515

498516
def test_config_get(self, r):
499517
data = r.config_get()
500-
assert 'maxmemory' in data
501-
assert data['maxmemory'].isdigit()
518+
assert len(data.keys()) > 10
519+
# # assert 'maxmemory' in data
520+
# assert data['maxmemory'].isdigit()
502521

522+
@skip_if_redis_enterprise
503523
def test_config_resetstat(self, r):
504524
r.ping()
505525
prior_commands_processed = int(r.info()['total_commands_processed'])
@@ -509,13 +529,16 @@ def test_config_resetstat(self, r):
509529
assert reset_commands_processed < prior_commands_processed
510530

511531
def test_config_set(self, r):
512-
data = r.config_get()
513-
rdbname = data['dbfilename']
514-
try:
515-
assert r.config_set('dbfilename', 'redis_py_test.rdb')
516-
assert r.config_get()['dbfilename'] == 'redis_py_test.rdb'
517-
finally:
518-
assert r.config_set('dbfilename', rdbname)
532+
# data = r.config_get()
533+
# rdbname = data['dbfilename']
534+
# try:
535+
# assert r.config_set('dbfilename', 'redis_py_test.rdb')
536+
# assert r.config_get()['dbfilename'] == 'redis_py_test.rdb'
537+
# finally:
538+
# assert r.config_set('dbfilename', rdbname)
539+
assert r.config_set('list-max-ziplist-entriies', 1000)
540+
assert r.config_get('list-max-ziplist-entries') == 1000
541+
r.config_set('list-max-ziplist-entriies', 0)
519542

520543
def test_dbsize(self, r):
521544
r['a'] = 'foo'
@@ -530,8 +553,10 @@ def test_info(self, r):
530553
r['b'] = 'bar'
531554
info = r.info()
532555
assert isinstance(info, dict)
533-
assert info['db9']['keys'] == 2
556+
assert 'arch_bits' in info.keys()
557+
assert 'redis_version' in info.keys()
534558

559+
@skip_if_redis_enterprise
535560
def test_lastsave(self, r):
536561
assert isinstance(r.lastsave(), datetime.datetime)
537562

@@ -625,6 +650,7 @@ def test_time(self, r):
625650
assert isinstance(t[0], int)
626651
assert isinstance(t[1], int)
627652

653+
@skip_if_redis_enterprise
628654
def test_bgsave(self, r):
629655
assert r.bgsave()
630656
time.sleep(0.3)
@@ -2432,6 +2458,7 @@ def test_cluster_slaves(self, mock_cluster_resp_slaves):
24322458
'slaves', 'nodeid'), dict)
24332459

24342460
@skip_if_server_version_lt('3.0.0')
2461+
@skip_if_redis_enterprise
24352462
def test_readwrite(self, r):
24362463
assert r.readwrite()
24372464

@@ -3613,6 +3640,7 @@ def test_memory_usage(self, r):
36133640
assert isinstance(r.memory_usage('foo'), int)
36143641

36153642
@skip_if_server_version_lt('4.0.0')
3643+
@skip_if_redis_enterprise
36163644
def test_module_list(self, r):
36173645
assert isinstance(r.module_list(), list)
36183646
for x in r.module_list():
@@ -3625,6 +3653,7 @@ def test_command_count(self, r):
36253653
assert res >= 100
36263654

36273655
@skip_if_server_version_lt('4.0.0')
3656+
@skip_if_redis_enterprise
36283657
def test_module(self, r):
36293658
with pytest.raises(redis.exceptions.ModuleError) as excinfo:
36303659
r.module_load('/some/fake/path')
@@ -3677,6 +3706,7 @@ def test_restore(self, r):
36773706
assert r.get(key) == b'blee!'
36783707

36793708
@skip_if_server_version_lt('5.0.0')
3709+
@skip_if_redis_enterprise
36803710
def test_replicaof(self, r):
36813711

36823712
with pytest.raises(redis.ResponseError):
@@ -3755,6 +3785,7 @@ def test_22_info(self, r):
37553785
assert '6' in parsed['allocation_stats']
37563786
assert '>=256' in parsed['allocation_stats']
37573787

3788+
@skip_if_redis_enterprise
37583789
def test_large_responses(self, r):
37593790
"The PythonParser has some special cases for return values > 1MB"
37603791
# load up 5MB of data into a key

tests/test_connection_pool.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
from threading import Thread
99
from redis.connection import ssl_available, to_bool
10-
from .conftest import skip_if_server_version_lt, _get_client
10+
from .conftest import (
11+
skip_if_server_version_lt,
12+
skip_if_redis_enterprise,
13+
_get_client
14+
)
1115
from .test_pubsub import wait_for_message
1216

1317

@@ -481,6 +485,7 @@ def test_on_connect_error(self):
481485
assert not pool._available_connections[0]._sock
482486

483487
@skip_if_server_version_lt('2.8.8')
488+
@skip_if_redis_enterprise
484489
def test_busy_loading_disconnects_socket(self, r):
485490
"""
486491
If Redis raises a LOADING error, the connection should be
@@ -491,6 +496,7 @@ def test_busy_loading_disconnects_socket(self, r):
491496
assert not r.connection._sock
492497

493498
@skip_if_server_version_lt('2.8.8')
499+
@skip_if_redis_enterprise
494500
def test_busy_loading_from_pipeline_immediate_command(self, r):
495501
"""
496502
BusyLoadingErrors should raise from Pipelines that execute a
@@ -506,6 +512,7 @@ def test_busy_loading_from_pipeline_immediate_command(self, r):
506512
assert not pool._available_connections[0]._sock
507513

508514
@skip_if_server_version_lt('2.8.8')
515+
@skip_if_redis_enterprise
509516
def test_busy_loading_from_pipeline(self, r):
510517
"""
511518
BusyLoadingErrors should be raised from a pipeline execution
@@ -521,6 +528,7 @@ def test_busy_loading_from_pipeline(self, r):
521528
assert not pool._available_connections[0]._sock
522529

523530
@skip_if_server_version_lt('2.8.8')
531+
@skip_if_redis_enterprise
524532
def test_read_only_error(self, r):
525533
"READONLY errors get turned in ReadOnlyError exceptions"
526534
with pytest.raises(redis.ReadOnlyError):
@@ -546,6 +554,7 @@ def test_connect_from_url_unix(self):
546554
'path=/path/to/socket,db=0',
547555
)
548556

557+
@skip_if_redis_enterprise
549558
def test_connect_no_auth_supplied_when_required(self, r):
550559
"""
551560
AuthenticationError should be raised when the server requires a
@@ -555,6 +564,7 @@ def test_connect_no_auth_supplied_when_required(self, r):
555564
r.execute_command('DEBUG', 'ERROR',
556565
'ERR Client sent AUTH, but no password is set')
557566

567+
@skip_if_redis_enterprise
558568
def test_connect_invalid_password_supplied(self, r):
559569
"AuthenticationError should be raised when sending the wrong password"
560570
with pytest.raises(redis.AuthenticationError):

0 commit comments

Comments
 (0)