def testRestTeamCache_Override(self): m = mock.Mock() m.__name__ = 'mockMethod' m.return_value = 5 with self.assertRaises(ValueError): cache.rest_team_cache('foo')(m) wrapped = cache.rest_team_cache('foo-%d')(m) with mock.patch.object(flask, 'g'): flask.g.tid = 111 self.assertEqual(5, wrapped()) m.return_value = 555 self.assertEqual(5, wrapped()) # called twice for caching m.assert_called_once() flask.g.tid = 123 self.assertEqual(555, wrapped()) # different team?
def testRestTeamCache_Basic(self): m = mock.Mock() m.__name__ = 'mockMethod' m.return_value = 5 wrapped = cache.rest_team_cache(m) with mock.patch.object(flask, 'g'): flask.g.tid = 111 self.assertEqual(5, wrapped()) m.return_value = 555 self.assertEqual(5, wrapped()) # called twice for caching m.assert_called_once() flask.g.tid = 123 self.assertEqual(555, wrapped()) # different team?