Ejemplo n.º 1
0
 def testDeleteInvalidatesRecentUserActivity(self):
     """
     L{CachingTagValueAPI.delete} invalidates cached recent activity data
     for the L{User} that's removed data.
     """
     objectID = uuid4()
     CachingTagAPI(self.user).create([(u'username/tag', u'A tag')])
     cache = RecentUserActivityCache()
     cache.save(
         u'username', [(u'username/tag', objectID, u'about-value',
                        u'tag-value', u'username', datetime.utcnow())])
     self.tagValues.delete([(objectID, u'username/tag')])
     result = cache.get(u'username')
     self.assertEqual({}, result.results)
     self.assertEqual([u'username'], result.uncachedValues)
Ejemplo n.º 2
0
 def testGetReturnsUncachedValues(self):
     """
     L{RecentUserActivityCache.get} returns values not found in the cache
     in the C{uncachedValues} field of the L{CacheResult} object.
     """
     result = RecentUserActivityCache().get(u'user')
     self.assertEqual([u'user'], result.uncachedValues)
     self.assertEqual({}, result.results)
Ejemplo n.º 3
0
 def delete(self, values):
     """See L{TagValueAPI.delete}."""
     if isgenerator(values):
         values = list(values)
     result = self._api.delete(values)
     objectIDs = [objectID for objectID, path in values]
     RecentObjectActivityCache().clear(objectIDs)
     RecentUserActivityCache().clear([self._user.username])
     return result
Ejemplo n.º 4
0
 def testDeleteInvalidatesCachedRecentUserActivity(self):
     """
     L{CachingTagAPI.delete} invalidates recent activity for L{User}s that
     had a L{TagValue} associated with the removed L{Tag}.
     """
     objectID = uuid4()
     self.tags.create([(u'username/tag', u'A tag')])
     CachingTagValueAPI(self.user).set({objectID: {u'username/tag': 42}})
     CachingRecentActivityAPI().getForUsers([u'username'])
     self.tags.delete([u'username/tag'])
     result = RecentUserActivityCache().get(u'username')
     self.assertEqual({}, result.results)
     self.assertEqual(['username'], result.uncachedValues)
Ejemplo n.º 5
0
 def testSaveStoresRecentActivityInTheCache(self):
     """
     L{RecentUserActivityCache.save} stores recent activity in the cache.
     """
     now = datetime.utcnow()
     objectID = uuid4()
     RecentUserActivityCache().save(u'user', [
         (u'user/tag', objectID, u'about-value', u'tag-value', u'user', now)
     ])
     self.assertEqual([[
         u'user/tag',
         str(objectID), u'about-value', u'tag-value', u'user',
         now.isoformat()
     ]], loads(self.cache.get('recentactivity:user:user')))
Ejemplo n.º 6
0
    def delete(self, paths):
        """See L{TagAPI.delete}.

        Permissions for deleted L{Tag}s are removed from the cache.
        """
        if isgenerator(paths):
            paths = list(paths)
        # FIXME getObjectIDs is called twice--once here and once in
        # TagAPI.delete.  It would be better if we only did this once, not to
        # mention that this breaks encapsulation by bypassing the model layer
        # and accessing the data layer directly. -jkakar
        objectIDs = set(getObjectIDs(paths))
        RecentObjectActivityCache().clear(objectIDs)
        usernames = set([path.split('/')[0] for path in paths])
        RecentUserActivityCache().clear(usernames)
        PermissionCache().clearTagPermissions(paths)
        return self._api.delete(paths)
Ejemplo n.º 7
0
    def testGetReturnsRecentActivityFromCache(self):
        """
        L{RecentUserActivityCache.get} returns the recent activity saved in
        the cache.
        """
        now = datetime.utcnow()
        objectID = uuid4()
        activity = [(u'user/tag', str(objectID), u'about-value', u'tag-value',
                     u'user', now.isoformat())]
        self.cache.set(u'recentactivity:user:user', dumps(activity))

        result = RecentUserActivityCache().get(u'user')
        self.assertEqual(
            {
                u'user': [(u'user/tag', objectID, u'about-value', u'tag-value',
                           u'user', now)]
            }, result.results)
        self.assertEqual([], result.uncachedValues)
Ejemplo n.º 8
0
 def set(self, values):
     """See L{TagValueAPI.set}."""
     result = self._api.set(values)
     RecentObjectActivityCache().clear(values.keys())
     RecentUserActivityCache().clear([self._user.username])
     return result