changeset 47:3386b1468683

Fix tests.
author Daniele Nicolodi <daniele@grinta.net>
date Sat, 13 Aug 2011 20:25:29 +0200
parents b3570e2e25a5
children a06d8abe37c1
files src/ltpdarepo/tests/test_pagination.py src/ltpdarepo/tests/test_users.py
diffstat 2 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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])
--- 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()