def test_get_recent_posts(self): from miniblog.models import get_recent_posts, Entry from time import sleep # test with not enough entries DBSession.add(Entry('Title 1', 'Text 1')) self.assertEqual(len(get_recent_posts()), 1) # make sure caching is still in place # sleep(1) # activate this when order test fails DBSession.add(Entry('Title 2', 'Text 2')) self.assertEqual(len(get_recent_posts()), 1) # Invalidate and recount get_recent_posts.invalidate() self.assertEqual(len(get_recent_posts()), 2) # Check order is correct recent = get_recent_posts() first = recent[0].entry_time second = recent[1].entry_time self.assertGreater(first, second) # Check count param: self.assertEqual(len(get_recent_posts(1)), 1) for i in range(3, 9): DBSession.add(Entry('Title {0}'.format(i), 'Text {0}'.format(i))) get_recent_posts.invalidate() self.assertEqual(len(get_recent_posts()), 7)
def recent(self): """A list of recent posts as returned by :func:`miniblog.models.get_recent_posts`.""" recent_entries = get_recent_posts() return recent_entries