1 | from django.test import TestCase
|
---|
2 |
|
---|
3 | from django.db import models
|
---|
4 | from django.core.paginator import Paginator,NBPageList
|
---|
5 | from models import Model1
|
---|
6 | import random
|
---|
7 |
|
---|
8 | class SimpleTest(TestCase):
|
---|
9 | def setUp(self):
|
---|
10 | for i in range(10):
|
---|
11 | m = Model1()
|
---|
12 | m.name = random.random()*3000
|
---|
13 | m.save()
|
---|
14 | def test_basic_addition(self):
|
---|
15 | objs = NBPageList(Model1.objects)
|
---|
16 | p = Paginator(objs, 5)
|
---|
17 | self.assertEqual( p.count,10 )
|
---|
18 | self.assertEqual( p.num_pages,2 )
|
---|
19 | self.assertEqual( p.page_range,[1,2] )
|
---|
20 | page1 = p.page(1)
|
---|
21 | print page1
|
---|
22 | print page1.object_list
|
---|
23 | page2 = p.page(2)
|
---|
24 | print page2
|
---|
25 | print page2.object_list
|
---|
26 | self.assertEqual( page2.has_next(),False )
|
---|
27 | self.assertEqual( page2.has_previous(),True )
|
---|
28 | self.assertEqual( page1.has_next(),True )
|
---|
29 |
|
---|