mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-28 04:24:00 +03:00
Update check for pagination settings, update test
This commit is contained in:
parent
a9d25af791
commit
1ada7c7d22
|
@ -6,14 +6,16 @@ def pagination_system_check(app_configs, **kwargs):
|
|||
errors = []
|
||||
# Use of default page size setting requires a default Paginator class
|
||||
from rest_framework.settings import api_settings
|
||||
if api_settings.PAGE_SIZE and not api_settings.DEFAULT_PAGINATION_CLASS:
|
||||
if (
|
||||
api_settings.PAGE_SIZE or api_settings.MAX_PAGE_SIZE
|
||||
) and not api_settings.DEFAULT_PAGINATION_CLASS:
|
||||
errors.append(
|
||||
Warning(
|
||||
"You have specified a default PAGE_SIZE pagination rest_framework setting, "
|
||||
"You have specified a default PAGE_SIZE pagination or MAX_PAGE_SIZE limit rest_framework setting, "
|
||||
"without specifying also a DEFAULT_PAGINATION_CLASS.",
|
||||
hint="The default for DEFAULT_PAGINATION_CLASS is None. "
|
||||
"In previous versions this was PageNumberPagination. "
|
||||
"If you wish to define PAGE_SIZE globally whilst defining "
|
||||
"If you wish to define PAGE_SIZE or MAX_PAGE_SIZE globally whilst defining "
|
||||
"pagination_class on a per-view basis you may silence this check.",
|
||||
id="rest_framework.W001"
|
||||
)
|
||||
|
|
|
@ -54,6 +54,7 @@ class TestSettings(TestCase):
|
|||
return next((error for error in errors if error.id == error_id), None)
|
||||
|
||||
self.assertIsNone(api_settings.PAGE_SIZE)
|
||||
self.assertIsNone(api_settings.MAX_PAGE_SIZE)
|
||||
self.assertIsNone(api_settings.DEFAULT_PAGINATION_CLASS)
|
||||
|
||||
pagination_error = get_pagination_error('rest_framework.W001')
|
||||
|
@ -63,11 +64,19 @@ class TestSettings(TestCase):
|
|||
pagination_error = get_pagination_error('rest_framework.W001')
|
||||
self.assertIsNotNone(pagination_error)
|
||||
|
||||
with override_settings(REST_FRAMEWORK={'MAX_PAGE_SIZE': 10}):
|
||||
pagination_error = get_pagination_error('rest_framework.W001')
|
||||
self.assertIsNotNone(pagination_error)
|
||||
|
||||
default_pagination_class = 'rest_framework.pagination.PageNumberPagination'
|
||||
with override_settings(REST_FRAMEWORK={'PAGE_SIZE': 10, 'DEFAULT_PAGINATION_CLASS': default_pagination_class}):
|
||||
pagination_error = get_pagination_error('rest_framework.W001')
|
||||
self.assertIsNone(pagination_error)
|
||||
|
||||
with override_settings(REST_FRAMEWORK={'MAX_PAGE_SIZE': 10, 'DEFAULT_PAGINATION_CLASS': default_pagination_class}):
|
||||
pagination_error = get_pagination_error('rest_framework.W001')
|
||||
self.assertIsNone(pagination_error)
|
||||
|
||||
|
||||
class TestSettingTypes(TestCase):
|
||||
def test_settings_consistently_coerced_to_list(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user