6
6
from unittest .mock import patch
7
7
8
8
import pytest
9
+ from django .conf import settings
9
10
from django .core .cache import caches
10
11
from pytest_django .fixtures import SettingsWrapper
11
12
from pytest_mock import MockerFixture
16
17
from django_redis .serializers .json import JSONSerializer
17
18
from django_redis .serializers .msgpack import MSGPackSerializer
18
19
19
- herd .CACHE_HERD_TIMEOUT = 2
20
-
21
20
22
21
class TestDjangoRedisCache :
23
22
def test_setnx (self , cache : RedisCache ):
@@ -199,7 +198,9 @@ def test_set_many(self, cache: RedisCache):
199
198
res = cache .get_many (["a" , "b" , "c" ])
200
199
assert res == {"a" : 1 , "b" : 2 , "c" : 3 }
201
200
202
- def test_set_call_empty_pipeline (self , cache : RedisCache , mocker : MockerFixture ):
201
+ def test_set_call_empty_pipeline (self , cache : RedisCache , mocker : MockerFixture , settings : SettingsWrapper ):
202
+ settings .CACHE_HERD_TIMEOUT = 2
203
+
203
204
if isinstance (cache .client , ShardClient ):
204
205
pytest .skip ("ShardClient doesn't support get_client" )
205
206
@@ -212,7 +213,7 @@ def test_set_call_empty_pipeline(self, cache: RedisCache, mocker: MockerFixture)
212
213
213
214
if isinstance (cache .client , herd .HerdClient ):
214
215
default_timeout = cache .client ._backend .default_timeout
215
- herd_timeout = (default_timeout + herd .CACHE_HERD_TIMEOUT ) * 1000 # type: ignore # noqa
216
+ herd_timeout = (default_timeout + settings .CACHE_HERD_TIMEOUT ) * 1000 # type: ignore # noqa
216
217
herd_pack_value = cache .client ._pack (value , default_timeout )
217
218
mocked_set .assert_called_once_with (
218
219
cache .client .make_key (key , version = None ),
@@ -495,11 +496,13 @@ def test_delete_pattern_with_custom_count(self, client_mock, cache: RedisCache):
495
496
496
497
@patch ("django_redis.cache.RedisCache.client" )
497
498
def test_delete_pattern_with_settings_default_scan_count (
498
- self , client_mock , cache : RedisCache
499
+ self , client_mock , cache : RedisCache , settings : SettingsWrapper ,
499
500
):
501
+ settings .DJANGO_REDIS_SCAN_ITERSIZE = 30
502
+
500
503
for key in ["foo-aa" , "foo-ab" , "foo-bb" , "foo-bc" ]:
501
504
cache .set (key , "foo" )
502
- expected_count = django_redis . cache .DJANGO_REDIS_SCAN_ITERSIZE
505
+ expected_count = settings .DJANGO_REDIS_SCAN_ITERSIZE
503
506
504
507
cache .delete_pattern ("*foo-a*" )
505
508
0 commit comments