17
17
from django_redis .serializers .msgpack import MSGPackSerializer
18
18
19
19
20
- @pytest .fixture
21
- def patch_herd_settings ():
22
- default_cache = caches ["default" ]
23
- if isinstance (default_cache .client , herd .HerdClient ):
24
- # destroy cache to force recreation with updated settings
25
- del caches ["default" ]
26
- with override_settings (CACHE_HERD_TIMEOUT = 2 ):
27
- yield
28
- # destroy cache force recreation with original settings
29
- del caches ["default" ]
30
- else :
31
- yield
32
-
33
-
34
20
class TestDjangoRedisCache :
35
21
def test_setnx (self , cache : RedisCache ):
36
22
# we should ensure there is no test_key_nx in redis
@@ -50,7 +36,7 @@ def test_setnx(self, cache: RedisCache):
50
36
res = cache .get ("test_key_nx" )
51
37
assert res is None
52
38
53
- def test_setnx_timeout (self , patch_herd_settings , cache : RedisCache ):
39
+ def test_setnx_timeout (self , cache : RedisCache ):
54
40
# test that timeout still works for nx=True
55
41
res = cache .set ("test_key_nx" , 1 , timeout = 2 , nx = True )
56
42
assert res is True
@@ -129,7 +115,7 @@ def test_save_float(self, cache: RedisCache):
129
115
assert isinstance (res , float )
130
116
assert res == float_val
131
117
132
- def test_timeout (self , patch_herd_settings , cache : RedisCache ):
118
+ def test_timeout (self , cache : RedisCache ):
133
119
cache .set ("test_key" , 222 , timeout = 3 )
134
120
time .sleep (4 )
135
121
@@ -141,9 +127,7 @@ def test_timeout_0(self, cache: RedisCache):
141
127
res = cache .get ("test_key" )
142
128
assert res is None
143
129
144
- def test_timeout_parameter_as_positional_argument (
145
- self , patch_herd_settings , cache : RedisCache
146
- ):
130
+ def test_timeout_parameter_as_positional_argument (self , cache : RedisCache ):
147
131
cache .set ("test_key" , 222 , - 1 )
148
132
res = cache .get ("test_key" )
149
133
assert res is None
@@ -215,7 +199,6 @@ def test_set_many(self, cache: RedisCache):
215
199
216
200
def test_set_call_empty_pipeline (
217
201
self ,
218
- patch_herd_settings ,
219
202
cache : RedisCache ,
220
203
mocker : MockerFixture ,
221
204
settings : SettingsWrapper ,
@@ -516,11 +499,7 @@ def test_delete_pattern_with_custom_count(self, client_mock, cache: RedisCache):
516
499
@patch ("django_redis.cache.RedisCache.client" )
517
500
@override_settings (DJANGO_REDIS_SCAN_ITERSIZE = 30 )
518
501
def test_delete_pattern_with_settings_default_scan_count (
519
- self ,
520
- client_mock ,
521
- patch_herd_settings ,
522
- cache : RedisCache ,
523
- settings : SettingsWrapper ,
502
+ self , client_mock , cache : RedisCache , settings : SettingsWrapper ,
524
503
):
525
504
for key in ["foo-aa" , "foo-ab" , "foo-bb" , "foo-bc" ]:
526
505
cache .set (key , "foo" )
@@ -542,7 +521,7 @@ def test_close_client(self, cache: RedisCache, mocker: MockerFixture):
542
521
cache .close ()
543
522
assert mock .called
544
523
545
- def test_ttl (self , patch_herd_settings , cache : RedisCache ):
524
+ def test_ttl (self , cache : RedisCache ):
546
525
cache .set ("foo" , "bar" , 10 )
547
526
ttl = cache .ttl ("foo" )
548
527
@@ -749,7 +728,7 @@ def test_touch_zero_timeout(self, cache: RedisCache):
749
728
res = cache .get ("test_key" )
750
729
assert res is None
751
730
752
- def test_touch_positive_timeout (self , patch_herd_settings , cache : RedisCache ):
731
+ def test_touch_positive_timeout (self , cache : RedisCache ):
753
732
cache .set ("test_key" , 222 , timeout = 10 )
754
733
755
734
assert cache .touch ("test_key" , 2 ) is True
0 commit comments