PageRenderTime 17ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/views/tests/generic/object_list.py

https://code.google.com/p/mango-py/
Python | 36 lines | 23 code | 9 blank | 4 comment | 1 complexity | 4caf68a20ad7b0e0c8880cce37c77ef4 MD5 | raw file
 1from django.test import TestCase
 2
 3
 4class ObjectListTest(TestCase):
 5    fixtures = ['testdata.json']
 6
 7    def check_pagination(self, url, expected_status_code, object_count=None):
 8        response = self.client.get(url)
 9        self.assertEqual(response.status_code, expected_status_code)
10
11        if object_count:
12            self.assertEqual(response.context['is_paginated'], True)
13            self.assertEqual(len(response.context['page_obj'].object_list),
14                             object_count)
15
16        return response
17
18    def test_finds_pages(self):
19        # Check page count doesn't start at 0.
20        self.check_pagination('/views/object_list/page0/', 404)
21
22        # Check basic pages.
23        self.check_pagination('/views/object_list/page/', 200, 2)
24        self.check_pagination('/views/object_list/page1/', 200, 2)
25        self.check_pagination('/views/object_list/page2/', 200, 1)
26        self.check_pagination('/views/object_list/page3/', 404)
27
28        # Check the special "last" page.
29        self.check_pagination('/views/object_list/pagelast/', 200, 1)
30        self.check_pagination('/views/object_list/pagenotlast/', 404)
31
32    def test_no_paginate_by(self):
33        # Ensure that the view isn't paginated by default.
34        url = '/views/object_list_no_paginate_by/page1/'
35        response = self.check_pagination(url, 200)
36        self.assertEqual(response.context['is_paginated'], False)