Added pagination settings test case (#8362)

This commit is contained in:
Subin Kim 2022-11-22 17:18:47 +09:00 committed by GitHub
parent 0ae3323bd2
commit 8175f05c89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,31 @@ class TestSettings(TestCase):
assert api_settings.PAGE_SIZE is None, "Setting should have been restored" assert api_settings.PAGE_SIZE is None, "Setting should have been restored"
def test_pagination_settings(self):
"""
Integration tests for pagination system check.
"""
from rest_framework.checks import pagination_system_check
def get_pagination_error(error_id: str):
errors = pagination_system_check(app_configs=None)
return next((error for error in errors if error.id == error_id), None)
self.assertIsNone(api_settings.PAGE_SIZE)
self.assertIsNone(api_settings.DEFAULT_PAGINATION_CLASS)
pagination_error = get_pagination_error('rest_framework.W001')
self.assertIsNone(pagination_error)
with override_settings(REST_FRAMEWORK={'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)
class TestSettingTypes(TestCase): class TestSettingTypes(TestCase):
def test_settings_consistently_coerced_to_list(self): def test_settings_consistently_coerced_to_list(self):