1515from pytest_mock import MockerFixture
1616
1717from django_valkey .async_cache .cache import AsyncValkeyCache
18+ from django_valkey .async_cache .client import AsyncHerdClient
1819from django_valkey .serializers .json import JSONSerializer
1920from django_valkey .serializers .msgpack import MSGPackSerializer
2021
@@ -251,25 +252,25 @@ async def test_set_call_empty_pipeline(
251252 mocked_set = mocker .patch .object (pipeline , "set" , AsyncMock ())
252253 await cache .aset (key , value , client = pipeline )
253254
254- # if isinstance(cache.client, AsyncHerdClient):
255- # default_timeout = cache.client._backend.default_timeout
256- # herd_timeout = (default_timeout + settings.CACHE_HERD_TIMEOUT) * 1000
257- # herd_pack_value = await cache.client._pack(value, default_timeout)
258- # mocked_set.assert_called_once_with(
259- # await cache.client.make_key(key, version=None),
260- # await cache.client.encode(herd_pack_value),
261- # nx=False,
262- # px=herd_timeout,
263- # xx=False,
264- # )
265- # else:
266- mocked_set .assert_called_once_with (
267- await cache .client .make_key (key , version = None ),
268- await cache .client .encode (value ),
269- nx = False ,
270- px = cache .client ._backend .default_timeout * 1000 ,
271- xx = False ,
272- )
255+ if isinstance (cache .client , AsyncHerdClient ):
256+ default_timeout = cache .client ._backend .default_timeout
257+ herd_timeout = (default_timeout + settings .CACHE_HERD_TIMEOUT ) * 1000
258+ herd_pack_value = await cache .client ._pack (value , default_timeout )
259+ mocked_set .assert_called_once_with (
260+ await cache .client .make_key (key , version = None ),
261+ await cache .client .encode (herd_pack_value ),
262+ nx = False ,
263+ px = herd_timeout ,
264+ xx = False ,
265+ )
266+ else :
267+ mocked_set .assert_called_once_with (
268+ await cache .client .make_key (key , version = None ),
269+ await cache .client .encode (value ),
270+ nx = False ,
271+ px = cache .client ._backend .default_timeout * 1000 ,
272+ xx = False ,
273+ )
273274
274275 async def test_delete (self , cache : AsyncValkeyCache ):
275276 await cache .aset_many ({"a" : 1 , "b" : 2 , "c" : 3 })
@@ -318,8 +319,8 @@ async def test_delete_many_empty_generator(self, cache: AsyncValkeyCache):
318319 assert res == 0
319320
320321 async def test_incr (self , cache : AsyncValkeyCache ):
321- # if isinstance(cache.client, AsyncHerdClient):
322- # pytest.skip("HerdClient doesn't support incr")
322+ if isinstance (cache .client , AsyncHerdClient ):
323+ pytest .skip ("HerdClient doesn't support incr" )
323324
324325 await cache .aset ("num" , 1 )
325326
@@ -349,8 +350,8 @@ async def test_incr(self, cache: AsyncValkeyCache):
349350 assert res == 5
350351
351352 async def test_incr_no_timeout (self , cache : AsyncValkeyCache ):
352- # if isinstance(cache.client, AsyncHerdClient):
353- # pytest.skip("HerdClient doesn't support incr")
353+ if isinstance (cache .client , AsyncHerdClient ):
354+ pytest .skip ("HerdClient doesn't support incr" )
354355
355356 await cache .aset ("num" , 1 , timeout = None )
356357
@@ -380,8 +381,8 @@ async def test_incr_no_timeout(self, cache: AsyncValkeyCache):
380381 assert res == 5
381382
382383 async def test_incr_error (self , cache : AsyncValkeyCache ):
383- # if isinstance(cache.client, AsyncHerdClient):
384- # pytest.skip("HerdClient doesn't support incr")
384+ if isinstance (cache .client , AsyncHerdClient ):
385+ pytest .skip ("HerdClient doesn't support incr" )
385386
386387 with pytest .raises (ValueError ):
387388 # key does not exist
@@ -390,8 +391,8 @@ async def test_incr_error(self, cache: AsyncValkeyCache):
390391 async def test_incr_ignore_check (self , cache : AsyncValkeyCache ):
391392 # if isinstance(cache.client, ShardClient):
392393 # pytest.skip("ShardClient doesn't support argument ignore_key_check to incr")
393- # if isinstance(cache.client, AsyncHerdClient):
394- # pytest.skip("HerdClient doesn't support incr")
394+ if isinstance (cache .client , AsyncHerdClient ):
395+ pytest .skip ("HerdClient doesn't support incr" )
395396
396397 # key exists check will be skipped and the value will be incremented by
397398 # '1' which is the default delta
@@ -438,8 +439,8 @@ async def test_get_set_bool(self, cache: AsyncValkeyCache):
438439 assert res is False
439440
440441 async def test_decr (self , cache : AsyncValkeyCache ):
441- # if isinstance(cache.client, AsyncHerdClient):
442- # pytest.skip("HerdClient doesn't support decr")
442+ if isinstance (cache .client , AsyncHerdClient ):
443+ pytest .skip ("HerdClient doesn't support decr" )
443444
444445 await cache .aset ("num" , 20 )
445446
@@ -562,10 +563,10 @@ async def test_ttl(self, cache: AsyncValkeyCache):
562563 await cache .aset ("foo" , "bar" , 10 )
563564 ttl = await cache .attl ("foo" )
564565
565- # if isinstance(cache.client, AsyncHerdClient):
566- # assert pytest.approx(ttl) == 12
567- # else:
568- assert pytest .approx (ttl ) == 10
566+ if isinstance (cache .client , AsyncHerdClient ):
567+ assert pytest .approx (ttl ) == 12
568+ else :
569+ assert pytest .approx (ttl ) == 10
569570
570571 # Test ttl None
571572 await cache .aset ("foo" , "foo" , timeout = None )
@@ -587,19 +588,19 @@ async def test_pttl(self, cache: AsyncValkeyCache):
587588 ttl = await cache .apttl ("foo" )
588589
589590 # delta is set to 10 as precision error causes tests to fail
590- # if isinstance(cache.client, AsyncHerdClient):
591- # assert pytest.approx(ttl, 10) == 12000
592- # else:
593- assert pytest .approx (ttl , 10 ) == 10000
591+ if isinstance (cache .client , AsyncHerdClient ):
592+ assert pytest .approx (ttl , 10 ) == 12000
593+ else :
594+ assert pytest .approx (ttl , 10 ) == 10000
594595
595596 # Test pttl with float value
596597 await cache .aset ("foo" , "bar" , 5.5 )
597598 ttl = await cache .apttl ("foo" )
598599
599- # if isinstance(cache.client, AsyncHerdClient):
600- # assert pytest.approx(ttl, 10) == 7500
601- # else:
602- assert pytest .approx (ttl , 10 ) == 5500
600+ if isinstance (cache .client , AsyncHerdClient ):
601+ assert pytest .approx (ttl , 10 ) == 7500
602+ else :
603+ assert pytest .approx (ttl , 10 ) == 5500
603604
604605 # Test pttl None
605606 await cache .aset ("foo" , "foo" , timeout = None )
0 commit comments