Debian Codegraph @

tests_app/tests/functional/mixins/paginate_by_max_mixin/tests.py

raw
1 import datetime
2
3 from django.test import TestCase, override_settings
4
5 from .models import CommentForPaginateByMaxMixin
6
7
8 @override_settings(ROOT_URLCONF='tests_app.tests.functional.mixins.paginate_by_max_mixin.urls')
9 class PaginateByMaxMixinTest(TestCase):
10
11 def setUp(self):
12 for i in range(30):
13 CommentForPaginateByMaxMixin.objects.create(
14 email='[email protected]',
15 content='Hello world',
16 created=datetime.datetime.now()
17 )
18
19 def test_default_page_size(self):
20 resp = self.client.get('/comments/')
21 self.assertEqual(len(resp.data['results']), 10)
22
23 def test_custom_page_size__less_then_maximum(self):
24 resp = self.client.get('/comments/?limit=15')
25 self.assertEqual(len(resp.data['results']), 15)
26
27 def test_custom_page_size__more_then_maximum(self):
28 resp = self.client.get('/comments/?limit=25')
29 self.assertEqual(len(resp.data['results']), 20)
30
31 def test_custom_page_size_with_max_value(self):
32 resp = self.client.get('/comments/?limit=max')
33 self.assertEqual(len(resp.data['results']), 20)
34
35 def test_custom_page_size_with_max_value__for_view_without__paginate_by_param__attribute(self):
36 resp = self.client.get(
37 '/comments-without-paginate-by-param-attribute/?page_size=max')
38 self.assertEqual(len(resp.data['results']), 10)
39
40 def test_custom_page_size_with_max_value__for_view_without__max_paginate_by__attribute(self):
41 resp = self.client.get(
42 '/comments-without-max-paginate-by-attribute/?page_size=max')
43 self.assertEqual(len(resp.data['results']), 10)
44
45
46 @override_settings(ROOT_URLCONF='tests_app.tests.functional.mixins.paginate_by_max_mixin.urls')
47 class PaginateByMaxMixinTestBehavior__should_not_affect_view_if_DRF_does_not_supports__max_paginate_by(TestCase):
48
49 def setUp(self):
50 for i in range(30):
51 CommentForPaginateByMaxMixin.objects.create(
52 email='[email protected]',
53 content='Hello world',
54 created=datetime.datetime.now()
55 )
56
57 def test_default_page_size(self):
58 resp = self.client.get('/comments/')
59 self.assertEqual(len(resp.data['results']), 10)
60
61 def test_custom_page_size__less_then_maximum(self):
62 resp = self.client.get('/comments/?limit=15')
63 self.assertEqual(len(resp.data['results']), 15)
64
65 def test_custom_page_size__more_then_maximum(self):
66 resp = self.client.get('/comments/?limit=25')
67 self.assertEqual(len(resp.data['results']), 20)
68
69 def test_custom_page_size_with_max_value(self):
70 resp = self.client.get('/comments/?limit=max')
71 self.assertEqual(len(resp.data['results']), 20)