Esempio n. 1
0
    def testNormal(self):
        ob = ObjectStub()
        adapter = AnnotationCacheable(ob)
        self.assertEquals(adapter.getCacheId(), None,
                          "initially cache ID should be None")

        adapter.setCacheId("my_id")
        self.assertEquals(adapter.getCacheId(), "my_id",
                          "failed to set cache ID")
Esempio n. 2
0
 def testInvalidate(self):
     # Test that setting a different cache ID invalidates the old cached
     # value
     cache1 = CacheStub()
     ztapi.provideUtility(ICache, cache1, "cache1")
     cache2 = CacheStub()
     ztapi.provideUtility(ICache, cache2, "cache2")
     ob = ObjectStub()
     adapter = AnnotationCacheable(ob)
     adapter.setCacheId('cache1')
     self.assertEquals(cache1.invalidated, [],
                       "called invalidate too early")
     adapter.setCacheId('cache2')
     self.assertEquals(cache1.invalidated, [ob], "did not call invalidate")
     adapter.setCacheId('cache2')
     self.assertEquals(
         cache2.invalidated, [],
         "called invalidate when reassigning to the same cache")