tests/app/soc/cache/test_sidebar.py
changeset 1477 c724a6eda7ef
parent 1308 35b75ffcbb37
equal deleted inserted replaced
1476:ef8e8de75ebb 1477:c724a6eda7ef
    33   """
    33   """
    34 
    34 
    35   def setUp(self):
    35   def setUp(self):
    36     self.called = 0
    36     self.called = 0
    37     self.user = users.get_current_user()
    37     self.user = users.get_current_user()
       
    38     self.memcache_key = "sidebar_for_'id'"
    38 
    39 
    39   def tearDown(self):
    40   def tearDown(self):
    40     memcache.flush_all()
    41     memcache.flush_all()
    41 
    42 
    42   def testGetCurrentUser(self):
    43   def testGetCurrentUser(self):
    54 
    55 
    55   def testGet(self):
    56   def testGet(self):
    56     """Test that get without setting something returns None.
    57     """Test that get without setting something returns None.
    57     """
    58     """
    58 
    59 
    59     self.assertEqual(None, sidebar.get('id', None))
    60     self.assertEqual((None, self.memcache_key), sidebar.get('id'))
    60 
    61 
    61   def testGetPut(self):
    62   def testGetPut(self):
    62     """Test that getting after putting gives back what you put in.
    63     """Test that getting after putting gives back what you put in.
    63     """
    64     """
    64 
    65 
    65     sidebar.put(42, 'id', None)
    66     sidebar.put(42, self.memcache_key)
    66     self.assertEqual(42, sidebar.get('id', None))
    67     self.assertEqual((42, self.memcache_key), sidebar.get('id'))
    67 
    68 
    68   def testFlush(self):
    69   def testFlush(self):
    69     """Test that getting after putting and flushing returns None.
    70     """Test that getting after putting and flushing returns None.
    70     """
    71     """
    71 
    72 
    72     sidebar.put(42, 'id', None)
    73     sidebar.put(42, self.memcache_key)
    73     sidebar.flush('id')
    74     sidebar.flush('id')
    74     self.assertEqual(None, sidebar.get('id', None))
    75     self.assertEqual((None, self.memcache_key), sidebar.get('id'))
    75 
    76 
    76   def testCache(self):
    77   def testCache(self):
    77     """Test that the result of a cached sidebar is cached.
    78     """Test that the result of a cached sidebar is cached.
    78     """
    79     """
    79 
    80 
    80     @sidebar.cache
    81     @sidebar.cache
    81     def getAnswer(x, y):
    82     def getAnswer(x):
    82       self.called = self.called + 1
    83       self.called = self.called + 1
    83       return 42
    84       return 42
    84 
    85 
    85     self.assertEqual(42, getAnswer('id', None))
    86     self.assertEqual(42, getAnswer('id'))
    86     self.assertEqual(42, getAnswer('id', None))
    87     self.assertEqual(42, getAnswer('id'))
    87     self.assertEqual(self.called, 1)
    88     self.assertEqual(self.called, 1)
    88 
    89 
    89 
    90