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 |