# HG changeset patch # User Daniele Nicolodi # Date 1313259929 -7200 # Node ID 3386b1468683e2d5c7cd3e02be52147174c24ed1 # Parent b3570e2e25a5139d0fadf64f32c1061f9f926938 Fix tests. diff -r b3570e2e25a5 -r 3386b1468683 src/ltpdarepo/tests/test_pagination.py --- a/src/ltpdarepo/tests/test_pagination.py Sat Aug 13 20:17:51 2011 +0200 +++ b/src/ltpdarepo/tests/test_pagination.py Sat Aug 13 20:25:29 2011 +0200 @@ -2,78 +2,78 @@ from ltpdarepo.pagination import Pagination -SIZE = 20 +size = 10 class TestCase(unittest.TestCase): def test_zero_elements(self): - p = Pagination(1, SIZE, 0) + p = Pagination(1, 0, size) l = list(p) self.assertEqual(l, []) def test_one_page(self): - p = Pagination(1, SIZE, 1) + p = Pagination(1, 1, size) l = list(p) self.assertEqual(l, [1]) - p = Pagination(1, SIZE, 2) + p = Pagination(1, 2, size) l = list(p) self.assertEqual(l, [1]) def test_two_pages(self): - p = Pagination(1, SIZE, 30) + p = Pagination(1, 18, size) l = list(p) self.assertEqual(l, [1, 2]) - p = Pagination(1, SIZE, 40) + p = Pagination(1, 20, size) l = list(p) self.assertEqual(l, [1, 2]) def test_pages_without_ellipsis(self): for i in range(1, 10): - p = Pagination(1, SIZE, SIZE*i) + p = Pagination(1, size*i, size) l = list(p) self.assertEqual(l, range(1, i + 1)) def test_pages_with_ellipsis(self): npages = 15 - nitems = SIZE*npages + nitems = size*npages for i in range(1, 6): - p = Pagination(i, SIZE, nitems) + p = Pagination(i, nitems, size) l = list(p) self.assertEqual(len(l), 9) self.assertEqual(l, [1, 2, 3, 4, 5, 6, 7, -7, 15]) - p = Pagination(6, SIZE, nitems) + p = Pagination(6, nitems, size) l = list(p) self.assertEqual(len(l), 9) self.assertEqual(l, [1, -2, 4, 5, 6, 7, 8, -6, 15]) - p = Pagination(7, SIZE, nitems) + p = Pagination(7, nitems, size) l = list(p) self.assertEqual(len(l), 9) self.assertEqual(l, [1, -3, 5, 6, 7, 8, 9, -5, 15]) - p = Pagination(8, SIZE, nitems) + p = Pagination(8, nitems, size) l = list(p) self.assertEqual(len(l), 9) self.assertEqual(l, [1, -4, 6, 7, 8, 9, 10, -4, 15]) - p = Pagination(9, SIZE, nitems) + p = Pagination(9, nitems, size) l = list(p) self.assertEqual(len(l), 9) self.assertEqual(l, [1, -5, 7, 8, 9, 10, 11, -3, 15]) - p = Pagination(10, SIZE, nitems) + p = Pagination(10, nitems, size) l = list(p) self.assertEqual(len(l), 9) self.assertEqual(l, [1, -6, 8, 9, 10, 11, 12, -2, 15]) for i in range(11, 15): - p = Pagination(i, SIZE, nitems) + p = Pagination(i, nitems, size) l = list(p) self.assertEqual(len(l), 9) self.assertEqual(l, [1, -7, 9, 10, 11, 12, 13, 14, 15]) diff -r b3570e2e25a5 -r 3386b1468683 src/ltpdarepo/tests/test_users.py --- a/src/ltpdarepo/tests/test_users.py Sat Aug 13 20:17:51 2011 +0200 +++ b/src/ltpdarepo/tests/test_users.py Sat Aug 13 20:25:29 2011 +0200 @@ -42,10 +42,15 @@ from ltpdarepo import app self.app = app self.app.config.update(HOSTNAME='localhost') + # fake request self.ctx = self.app.test_request_context() self.ctx.push() + # execute before request handlers + self.app.preprocess_request() def tearDown(self): + # execute after request handlers + self.app.process_response(self.app.response_class()) self.ctx.pop() from ltpdarepo.admin import wipe wipe()