15
15
16
16
from django_valkey .cache import ValkeyCache
17
17
from django_valkey .client import ShardClient , herd
18
+ from django_valkey .cluster_cache .client import DefaultClusterClient
18
19
from django_valkey .serializers .json import JSONSerializer
19
20
from django_valkey .serializers .msgpack import MSGPackSerializer
20
21
from django_valkey .serializers .pickle import PickleSerializer
@@ -99,7 +100,7 @@ def test_unicode_keys(self, cache: ValkeyCache):
99
100
res = cache .get ("ключ" )
100
101
assert res == "value"
101
102
102
- def test_save_and_integer (self , cache : ValkeyCache ):
103
+ def test_save_an_integer (self , cache : ValkeyCache ):
103
104
cache .set ("test_key" , 2 )
104
105
res = cache .get ("test_key" , "Foo" )
105
106
@@ -223,7 +224,9 @@ def test_get_many(self, cache: ValkeyCache):
223
224
assert res == {"a" : 1 , "b" : 2 , "c" : 3 }
224
225
225
226
def test_mget (self , cache : ValkeyCache ):
226
- if isinstance (cache .client , ShardClient ):
227
+ if isinstance (cache .client , ShardClient ) or isinstance (
228
+ cache .client , DefaultClusterClient
229
+ ):
227
230
pytest .skip ()
228
231
cache .set ("a" , 1 )
229
232
cache .set ("b" , 2 )
@@ -240,13 +243,28 @@ def test_get_many_unicode(self, cache: ValkeyCache):
240
243
res = cache .get_many (["a" , "ب" , "c" ])
241
244
assert res == {"a" : "1" , "ب" : "2" , "c" : "الف" }
242
245
246
+ def test_mget_unicode (self , cache : ValkeyCache ):
247
+ if isinstance (cache .client , ShardClient ) or isinstance (
248
+ cache .client , DefaultClusterClient
249
+ ):
250
+ pytest .skip ()
251
+
252
+ cache .set ("fooa" , "1" )
253
+ cache .set ("fooب" , "2" )
254
+ cache .set ("fooc" , "الف" )
255
+
256
+ res = cache .mget (["fooa" , "fooب" , "fooc" ])
257
+ assert res == {"fooa" : "1" , "fooب" : "2" , "fooc" : "الف" }
258
+
243
259
def test_set_many (self , cache : ValkeyCache ):
244
260
cache .set_many ({"a" : 1 , "b" : 2 , "c" : 3 })
245
261
res = cache .get_many (["a" , "b" , "c" ])
246
262
assert res == {"a" : 1 , "b" : 2 , "c" : 3 }
247
263
248
264
def test_mset (self , cache : ValkeyCache ):
249
- if isinstance (cache .client , ShardClient ):
265
+ if isinstance (cache .client , ShardClient ) or isinstance (
266
+ cache .client , DefaultClusterClient
267
+ ):
250
268
pytest .skip ()
251
269
cache .mset ({"a" : 1 , "b" : 2 , "c" : 3 })
252
270
res = cache .mget (["a" , "b" , "c" ])
@@ -518,6 +536,9 @@ def test_ttl_incr_version_no_timeout(self, cache: ValkeyCache):
518
536
assert my_value == "hello world!"
519
537
520
538
def test_delete_pattern (self , cache : ValkeyCache ):
539
+ if isinstance (cache .client , DefaultClusterClient ):
540
+ pytest .skip ("cluster client has a specific test" )
541
+
521
542
for key in ["foo-aa" , "foo-ab" , "foo-bb" , "foo-bc" ]:
522
543
cache .set (key , "foo" )
523
544
@@ -532,6 +553,9 @@ def test_delete_pattern(self, cache: ValkeyCache):
532
553
533
554
@patch ("django_valkey.cache.ValkeyCache.client" )
534
555
def test_delete_pattern_with_custom_count (self , client_mock , cache : ValkeyCache ):
556
+ if isinstance (cache .client , DefaultClusterClient ):
557
+ pytest .skip ("cluster client has a specific test" )
558
+
535
559
for key in ["foo-aa" , "foo-ab" , "foo-bb" , "foo-bc" ]:
536
560
cache .set (key , "foo" )
537
561
@@ -547,6 +571,9 @@ def test_delete_pattern_with_settings_default_scan_count(
547
571
cache : ValkeyCache ,
548
572
settings : SettingsWrapper ,
549
573
):
574
+ if isinstance (cache .client , DefaultClusterClient ):
575
+ pytest .skip ("cluster client has a specific test" )
576
+
550
577
for key in ["foo-aa" , "foo-ab" , "foo-bb" , "foo-bc" ]:
551
578
cache .set (key , "foo" )
552
579
expected_count = settings .DJANGO_VALKEY_SCAN_ITERSIZE
@@ -715,6 +742,11 @@ def test_lock(self, cache: ValkeyCache):
715
742
lock .release ()
716
743
assert not cache .has_key ("foobar" )
717
744
745
+ def test_lock_context_manager (self , cache : ValkeyCache ):
746
+ with cache .lock ("foobar" ):
747
+ assert cache .has_key ("foobar" )
748
+ assert not cache .has_key ("foobar" )
749
+
718
750
def test_lock_released_by_thread (self , cache : ValkeyCache ):
719
751
lock = cache .lock ("foobar" , thread_local = False )
720
752
lock .acquire (blocking = True )
@@ -964,6 +996,9 @@ def test_sinter(self, cache: ValkeyCache):
964
996
if isinstance (cache .client , ShardClient ):
965
997
pytest .skip ("ShardClient doesn't support sinter" )
966
998
999
+ if isinstance (cache .client , DefaultClusterClient ):
1000
+ pytest .skip ("cluster client has a specific test" )
1001
+
967
1002
cache .sadd ("foo1" , "bar1" , "bar2" )
968
1003
cache .sadd ("foo2" , "bar2" , "bar3" )
969
1004
assert cache .sinter ("foo1" , "foo2" ) == {"bar2" }
@@ -972,6 +1007,9 @@ def test_interstore(self, cache: ValkeyCache):
972
1007
if isinstance (cache .client , ShardClient ):
973
1008
pytest .skip ("ShardClient doesn't support sinterstore" )
974
1009
1010
+ if isinstance (cache .client , DefaultClusterClient ):
1011
+ pytest .skip ("cluster client has a specific test" )
1012
+
975
1013
cache .sadd ("foo1" , "bar1" , "bar2" )
976
1014
cache .sadd ("foo2" , "bar2" , "bar3" )
977
1015
assert cache .sinterstore ("foo3" , "foo1" , "foo2" ) == 1
@@ -1066,6 +1104,9 @@ def test_smove(self, cache: ValkeyCache):
1066
1104
# if isinstance(cache.client, ShardClient):
1067
1105
# pytest.skip("ShardClient doesn't support get_client")
1068
1106
1107
+ if isinstance (cache .client , DefaultClusterClient ):
1108
+ pytest .skip ("cluster client has a specific test" )
1109
+
1069
1110
cache .sadd ("foo1" , "bar1" , "bar2" )
1070
1111
cache .sadd ("foo2" , "bar2" , "bar3" )
1071
1112
assert cache .smove ("foo1" , "foo2" , "bar1" ) is True
@@ -1130,6 +1171,9 @@ def test_sunion(self, cache: ValkeyCache):
1130
1171
if isinstance (cache .client , ShardClient ):
1131
1172
pytest .skip ("ShardClient doesn't support sunion" )
1132
1173
1174
+ if isinstance (cache .client , DefaultClusterClient ):
1175
+ pytest .skip ("cluster client has a specific test" )
1176
+
1133
1177
cache .sadd ("foo1" , "bar1" , "bar2" )
1134
1178
cache .sadd ("foo2" , "bar2" , "bar3" )
1135
1179
assert cache .sunion ("foo1" , "foo2" ) == {"bar1" , "bar2" , "bar3" }
@@ -1138,6 +1182,9 @@ def test_sunionstore(self, cache: ValkeyCache):
1138
1182
if isinstance (cache .client , ShardClient ):
1139
1183
pytest .skip ("ShardClient doesn't support sunionstore" )
1140
1184
1185
+ if isinstance (cache .client , DefaultClusterClient ):
1186
+ pytest .skip ("cluster client has a specific test" )
1187
+
1141
1188
cache .sadd ("foo1" , "bar1" , "bar2" )
1142
1189
cache .sadd ("foo2" , "bar2" , "bar3" )
1143
1190
assert cache .sunionstore ("foo3" , "foo1" , "foo2" ) == 3
0 commit comments