示例#1
0
 def test_last_link(self):
     app = self.application()
     request = app.wsgi_request()
     pagination = Pagination()
     #
     pag = pagination(request, [], 0, 25, 0)
     self.assertFalse('first' in pag)
     self.assertFalse('prev' in pag)
     self.assertFalse('next' in pag)
     self.assertFalse('last' in pag)
     #
     pag = pagination(request, [], 120, 25, 0)
     query = query_dict(urlparse(pag['next']).query)
     self.assertEqual(query['offset'], '25')
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '100')
     #
     pag = pagination(request, [], 120, 25, 75)
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '100')
     self.assertFalse('next' in pag)
     #
     pag = pagination(request, [], 120, 25, 50)
     query = query_dict(urlparse(pag['next']).query)
     self.assertEqual(query['offset'], '75')
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '100')
示例#2
0
 def test_last_link(self):
     app = self.application()
     request = app.wsgi_request()
     pagination = Pagination()
     #
     pag = pagination(request, [], 0, 25, 0)
     self.assertFalse('first' in pag)
     self.assertFalse('prev' in pag)
     self.assertFalse('next' in pag)
     self.assertFalse('last' in pag)
     #
     pag = pagination(request, [], 120, 25, 0)
     query = query_dict(urlparse(pag['next']).query)
     self.assertEqual(query['offset'], '25')
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '100')
     #
     pag = pagination(request, [], 120, 25, 75)
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '100')
     self.assertFalse('next' in pag)
     #
     pag = pagination(request, [], 120, 25, 50)
     query = query_dict(urlparse(pag['next']).query)
     self.assertEqual(query['offset'], '75')
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '100')
示例#3
0
 def test_custom_offset(self):
     app = self.application()
     request = app.wsgi_request()
     pagination = Pagination()
     #
     pag = pagination(request, [], 27, 5, 2)
     self.assertFalse('prev' in pag)
     query = query_dict(urlparse(pag['first']).query)
     self.assertEqual(query['offset'], '0')
     self.assertEqual(query['limit'], '2')
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '22')
     self.assertEqual(query['limit'], '5')
     #
     pag = pagination(request, [], 27, 5, 22)
     self.assertFalse('next' in pag)
     self.assertFalse('last' in pag)
     query = query_dict(urlparse(pag['first']).query)
     self.assertEqual(query['offset'], '0')
     self.assertEqual(query['limit'], '2')
     query = query_dict(urlparse(pag['prev']).query)
     self.assertEqual(query['offset'], '17')
     self.assertEqual(query['limit'], '5')
示例#4
0
 def test_custom_offset(self):
     app = self.application()
     request = app.wsgi_request()
     pagination = Pagination()
     #
     pag = pagination(request, [], 27, 5, 2)
     self.assertFalse('prev' in pag)
     query = query_dict(urlparse(pag['first']).query)
     self.assertEqual(query['offset'], '0')
     self.assertEqual(query['limit'], '2')
     query = query_dict(urlparse(pag['last']).query)
     self.assertEqual(query['offset'], '22')
     self.assertEqual(query['limit'], '5')
     #
     pag = pagination(request, [], 27, 5, 22)
     self.assertFalse('next' in pag)
     self.assertFalse('last' in pag)
     query = query_dict(urlparse(pag['first']).query)
     self.assertEqual(query['offset'], '0')
     self.assertEqual(query['limit'], '2')
     query = query_dict(urlparse(pag['prev']).query)
     self.assertEqual(query['offset'], '17')
     self.assertEqual(query['limit'], '5')