/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

  1. from django.test import TestCase
  2. class ObjectListTest(TestCase):
  3. fixtures = ['testdata.json']
  4. def check_pagination(self, url, expected_status_code, object_count=None):
  5. response = self.client.get(url)
  6. self.assertEqual(response.status_code, expected_status_code)
  7. if object_count:
  8. self.assertEqual(response.context['is_paginated'], True)
  9. self.assertEqual(len(response.context['page_obj'].object_list),
  10. object_count)
  11. return response
  12. def test_finds_pages(self):
  13. # Check page count doesn't start at 0.
  14. self.check_pagination('/views/object_list/page0/', 404)
  15. # Check basic pages.
  16. self.check_pagination('/views/object_list/page/', 200, 2)
  17. self.check_pagination('/views/object_list/page1/', 200, 2)
  18. self.check_pagination('/views/object_list/page2/', 200, 1)
  19. self.check_pagination('/views/object_list/page3/', 404)
  20. # Check the special "last" page.
  21. self.check_pagination('/views/object_list/pagelast/', 200, 1)
  22. self.check_pagination('/views/object_list/pagenotlast/', 404)
  23. def test_no_paginate_by(self):
  24. # Ensure that the view isn't paginated by default.
  25. url = '/views/object_list_no_paginate_by/page1/'
  26. response = self.check_pagination(url, 200)
  27. self.assertEqual(response.context['is_paginated'], False)