Skip to content

Commit 0105fb1

Browse files
committed
Fix tests.
1 parent 9dc3e30 commit 0105fb1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/test_backend.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from unittest.mock import patch
77

88
import pytest
9+
from django.conf import settings
910
from django.core.cache import caches
1011
from pytest_django.fixtures import SettingsWrapper
1112
from pytest_mock import MockerFixture
@@ -16,8 +17,6 @@
1617
from django_redis.serializers.json import JSONSerializer
1718
from django_redis.serializers.msgpack import MSGPackSerializer
1819

19-
herd.CACHE_HERD_TIMEOUT = 2
20-
2120

2221
class TestDjangoRedisCache:
2322
def test_setnx(self, cache: RedisCache):
@@ -199,7 +198,9 @@ def test_set_many(self, cache: RedisCache):
199198
res = cache.get_many(["a", "b", "c"])
200199
assert res == {"a": 1, "b": 2, "c": 3}
201200

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+
203204
if isinstance(cache.client, ShardClient):
204205
pytest.skip("ShardClient doesn't support get_client")
205206

@@ -212,7 +213,7 @@ def test_set_call_empty_pipeline(self, cache: RedisCache, mocker: MockerFixture)
212213

213214
if isinstance(cache.client, herd.HerdClient):
214215
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
216217
herd_pack_value = cache.client._pack(value, default_timeout)
217218
mocked_set.assert_called_once_with(
218219
cache.client.make_key(key, version=None),
@@ -495,11 +496,13 @@ def test_delete_pattern_with_custom_count(self, client_mock, cache: RedisCache):
495496

496497
@patch("django_redis.cache.RedisCache.client")
497498
def test_delete_pattern_with_settings_default_scan_count(
498-
self, client_mock, cache: RedisCache
499+
self, client_mock, cache: RedisCache, settings: SettingsWrapper,
499500
):
501+
settings.DJANGO_REDIS_SCAN_ITERSIZE = 30
502+
500503
for key in ["foo-aa", "foo-ab", "foo-bb", "foo-bc"]:
501504
cache.set(key, "foo")
502-
expected_count = django_redis.cache.DJANGO_REDIS_SCAN_ITERSIZE
505+
expected_count = settings.DJANGO_REDIS_SCAN_ITERSIZE
503506

504507
cache.delete_pattern("*foo-a*")
505508

0 commit comments

Comments
 (0)