예제 #1
0
 def test_basic_pagination(self):
     p = sqlalchemy.Pagination(None, 1, 20, 500, [])
     self.assertEqual(p.page, 1)
     self.assertFalse(p.has_prev)
     self.assertTrue(p.has_next)
     self.assertEqual(p.total, 500)
     self.assertEqual(p.pages, 25)
     self.assertEqual(p.next_num, 2)
     self.assertEqual(list(p.iter_pages()), [1, 2, 3, 4, 5, None, 24, 25])
     p.page = 10
     self.assertEqual(list(p.iter_pages()),
                      [1, 2, None, 8, 9, 10, 11, 12, 13, 14, None, 24, 25])
예제 #2
0
 def test_pagination_pages_when_0_items_per_page(self):
     p = sqlalchemy.Pagination(None, 1, 0, 500, [])
     self.assertEqual(p.pages, 0)
예제 #3
0
        app.config['SQLALCHEMY_ENGINE'] = 'sqlite'
        db = sqlalchemy.SQLAlchemy(app)
  
        class FOOBar(db.Model)
            id = db.Column(db.Integer, primary_key=True)
        class BazBar(db.Model)
            id = db.Column(db.Integer, primary_key=True)
  
        self.assertEqual(FOOBar.__tablename__, 'foo_bar')
        self.assertEqual(BazBar.__tablename__, 'baz_bar')
  
  
class PaginationTestCase(unittest.TestCase)
  
    def test_basic_pagination(self)
        p = sqlalchemy.Pagination(None, 1, 20, 500, [])
        self.assertEqual(p.page, 1)
        self.assertFalse(p.has_prev)
        self.assertTrue(p.has_next)
        self.assertEqual(p.total, 500)
        self.assertEqual(p.pages, 25)
        self.assertEqual(p.next_num, 2)
        self.assertEqual(list(p.iter_pages()),
                         [1, 2, 3, 4, 5, None, 24, 25])
        p.page = 10
        self.assertEqual(list(p.iter_pages()),
                         [1, 2, None, 8, 9, 10, 11, 12, 13, 14, None, 24, 25])
  
    def test_pagination_pages_when_0_items_per_page(self)
        p = sqlalchemy.Pagination(None, 1, 0, 500, [])
        self.assertEqual(p.pages, 0)