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 )
@@ -918,6 +950,9 @@ def test_sdiff(self, cache: ValkeyCache):
918
950
if isinstance (cache .client , ShardClient ):
919
951
pytest .skip ("ShardClient doesn't support sdiff" )
920
952
953
+ if isinstance (cache .client , DefaultClusterClient ):
954
+ pytest .skip ("cluster client has a specific test" )
955
+
921
956
cache .sadd ("foo1" , "bar1" , "bar2" )
922
957
cache .sadd ("foo2" , "bar2" , "bar3" )
923
958
assert cache .sdiff ("foo1" , "foo2" ) == {"bar1" }
@@ -926,6 +961,9 @@ def test_sdiffstore(self, cache: ValkeyCache):
926
961
if isinstance (cache .client , ShardClient ):
927
962
pytest .skip ("ShardClient doesn't support sdiffstore" )
928
963
964
+ if isinstance (cache .client , DefaultClusterClient ):
965
+ pytest .skip ("cluster client has a specific test" )
966
+
929
967
cache .sadd ("foo1" , "bar1" , "bar2" )
930
968
cache .sadd ("foo2" , "bar2" , "bar3" )
931
969
assert cache .sdiffstore ("foo3" , "foo1" , "foo2" ) == 1
@@ -935,6 +973,9 @@ def test_sdiffstore_with_keys_version(self, cache: ValkeyCache):
935
973
if isinstance (cache .client , ShardClient ):
936
974
pytest .skip ("ShardClient doesn't support sdiffstore" )
937
975
976
+ if isinstance (cache .client , DefaultClusterClient ):
977
+ pytest .skip ("cluster client has a specific test" )
978
+
938
979
cache .sadd ("foo1" , "bar1" , "bar2" , version = 2 )
939
980
cache .sadd ("foo2" , "bar2" , "bar3" , version = 2 )
940
981
assert cache .sdiffstore ("foo3" , "foo1" , "foo2" , version_keys = 2 ) == 1
@@ -946,6 +987,9 @@ def test_sdiffstore_with_different_keys_versions_without_initial_set_in_version(
946
987
if isinstance (cache .client , ShardClient ):
947
988
pytest .skip ("ShardClient doesn't support sdiffstore" )
948
989
990
+ if isinstance (cache .client , DefaultClusterClient ):
991
+ pytest .skip ("cluster client has a specific test" )
992
+
949
993
cache .sadd ("foo1" , "bar1" , "bar2" , version = 1 )
950
994
cache .sadd ("foo2" , "bar2" , "bar3" , version = 2 )
951
995
assert cache .sdiffstore ("foo3" , "foo1" , "foo2" , version_keys = 2 ) == 0
@@ -956,6 +1000,9 @@ def test_sdiffstore_with_different_keys_versions_with_initial_set_in_version(
956
1000
if isinstance (cache .client , ShardClient ):
957
1001
pytest .skip ("ShardClient doesn't support sdiffstore" )
958
1002
1003
+ if isinstance (cache .client , DefaultClusterClient ):
1004
+ pytest .skip ("cluster client has a specific test" )
1005
+
959
1006
cache .sadd ("foo1" , "bar1" , "bar2" , version = 2 )
960
1007
cache .sadd ("foo2" , "bar2" , "bar3" , version = 1 )
961
1008
assert cache .sdiffstore ("foo3" , "foo1" , "foo2" , version_keys = 2 ) == 2
@@ -964,14 +1011,20 @@ def test_sinter(self, cache: ValkeyCache):
964
1011
if isinstance (cache .client , ShardClient ):
965
1012
pytest .skip ("ShardClient doesn't support sinter" )
966
1013
1014
+ if isinstance (cache .client , DefaultClusterClient ):
1015
+ pytest .skip ("cluster client has a specific test" )
1016
+
967
1017
cache .sadd ("foo1" , "bar1" , "bar2" )
968
1018
cache .sadd ("foo2" , "bar2" , "bar3" )
969
1019
assert cache .sinter ("foo1" , "foo2" ) == {"bar2" }
970
1020
971
- def test_interstore (self , cache : ValkeyCache ):
1021
+ def test_sinterstore (self , cache : ValkeyCache ):
972
1022
if isinstance (cache .client , ShardClient ):
973
1023
pytest .skip ("ShardClient doesn't support sinterstore" )
974
1024
1025
+ if isinstance (cache .client , DefaultClusterClient ):
1026
+ pytest .skip ("cluster client has a specific test" )
1027
+
975
1028
cache .sadd ("foo1" , "bar1" , "bar2" )
976
1029
cache .sadd ("foo2" , "bar2" , "bar3" )
977
1030
assert cache .sinterstore ("foo3" , "foo1" , "foo2" ) == 1
@@ -1066,6 +1119,9 @@ def test_smove(self, cache: ValkeyCache):
1066
1119
# if isinstance(cache.client, ShardClient):
1067
1120
# pytest.skip("ShardClient doesn't support get_client")
1068
1121
1122
+ if isinstance (cache .client , DefaultClusterClient ):
1123
+ pytest .skip ("cluster client has a specific test" )
1124
+
1069
1125
cache .sadd ("foo1" , "bar1" , "bar2" )
1070
1126
cache .sadd ("foo2" , "bar2" , "bar3" )
1071
1127
assert cache .smove ("foo1" , "foo2" , "bar1" ) is True
@@ -1130,6 +1186,9 @@ def test_sunion(self, cache: ValkeyCache):
1130
1186
if isinstance (cache .client , ShardClient ):
1131
1187
pytest .skip ("ShardClient doesn't support sunion" )
1132
1188
1189
+ if isinstance (cache .client , DefaultClusterClient ):
1190
+ pytest .skip ("cluster client has a specific test" )
1191
+
1133
1192
cache .sadd ("foo1" , "bar1" , "bar2" )
1134
1193
cache .sadd ("foo2" , "bar2" , "bar3" )
1135
1194
assert cache .sunion ("foo1" , "foo2" ) == {"bar1" , "bar2" , "bar3" }
@@ -1138,6 +1197,9 @@ def test_sunionstore(self, cache: ValkeyCache):
1138
1197
if isinstance (cache .client , ShardClient ):
1139
1198
pytest .skip ("ShardClient doesn't support sunionstore" )
1140
1199
1200
+ if isinstance (cache .client , DefaultClusterClient ):
1201
+ pytest .skip ("cluster client has a specific test" )
1202
+
1141
1203
cache .sadd ("foo1" , "bar1" , "bar2" )
1142
1204
cache .sadd ("foo2" , "bar2" , "bar3" )
1143
1205
assert cache .sunionstore ("foo3" , "foo1" , "foo2" ) == 3
0 commit comments