@@ -38,6 +38,9 @@ def delete(self, keys):
3838 def watch (self , keys ):
3939 return super (MockImpl , self ).watch (keys )
4040
41+ def unwatch (self , keys ):
42+ return super (MockImpl , self ).unwatch (keys )
43+
4144 def compare_and_swap (self , items , expires = None ):
4245 return super (MockImpl , self ).compare_and_swap (items , expires = expires )
4346
@@ -63,6 +66,11 @@ def test_watch(self):
6366 with pytest .raises (NotImplementedError ):
6467 cache .watch (b"foo" )
6568
69+ def test_unwatch (self ):
70+ cache = self .make_one ()
71+ with pytest .raises (NotImplementedError ):
72+ cache .unwatch (b"foo" )
73+
6674 def test_compare_and_swap (self ):
6775 cache = self .make_one ()
6876 with pytest .raises (NotImplementedError ):
@@ -147,6 +155,16 @@ def test_watch_compare_and_swap_with_expires(time):
147155 result = cache .get ([b"one" , b"two" , b"three" ])
148156 assert result == [None , b"hamburgers" , None ]
149157
158+ @staticmethod
159+ def test_watch_unwatch ():
160+ cache = global_cache ._InProcessGlobalCache ()
161+ result = cache .watch ([b"one" , b"two" , b"three" ])
162+ assert result is None
163+
164+ result = cache .unwatch ([b"one" , b"two" , b"three" ])
165+ assert result is None
166+ assert cache ._watch_keys == {}
167+
150168
151169class TestRedisCache :
152170 @staticmethod
@@ -225,6 +243,23 @@ def test_watch(uuid):
225243 "bar" : global_cache ._Pipeline (pipe , "abc123" ),
226244 }
227245
246+ @staticmethod
247+ def test_unwatch ():
248+ redis = mock .Mock (spec = ())
249+ cache = global_cache .RedisCache (redis )
250+ pipe1 = mock .Mock (spec = ("reset" ,))
251+ pipe2 = mock .Mock (spec = ("reset" ,))
252+ cache ._pipes .pipes = {
253+ "ay" : global_cache ._Pipeline (pipe1 , "abc123" ),
254+ "be" : global_cache ._Pipeline (pipe1 , "abc123" ),
255+ "see" : global_cache ._Pipeline (pipe2 , "def456" ),
256+ "dee" : global_cache ._Pipeline (pipe2 , "def456" ),
257+ "whatevs" : global_cache ._Pipeline (None , "himom!" ),
258+ }
259+
260+ cache .unwatch (["ay" , "be" , "see" , "dee" , "nuffin" ])
261+ assert cache .pipes == {"whatevs" : global_cache ._Pipeline (None , "himom!" )}
262+
228263 @staticmethod
229264 def test_compare_and_swap ():
230265 redis = mock .Mock (spec = ())
@@ -450,6 +485,17 @@ def test_watch():
450485 key2 : b"1" ,
451486 }
452487
488+ @staticmethod
489+ def test_unwatch ():
490+ client = mock .Mock (spec = ())
491+ cache = global_cache .MemcacheCache (client )
492+ key2 = cache ._key (b"two" )
493+ cache .caskeys [key2 ] = b"5"
494+ cache .caskeys ["whatevs" ] = b"6"
495+ cache .unwatch ([b"one" , b"two" ])
496+
497+ assert cache .caskeys == {"whatevs" : b"6" }
498+
453499 @staticmethod
454500 def test_compare_and_swap ():
455501 client = mock .Mock (spec = ("cas" ,))
0 commit comments