2017-12-14 12:33:48 +03:00
|
|
|
from django.test import TestCase, override_settings
|
2015-06-25 23:55:51 +03:00
|
|
|
|
2017-12-14 12:33:48 +03:00
|
|
|
from rest_framework.settings import APISettings, api_settings
|
2013-01-07 16:52:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
class TestSettings(TestCase):
|
|
|
|
def test_import_error_message_maintained(self):
|
2014-12-15 16:18:39 +03:00
|
|
|
"""
|
|
|
|
Make sure import errors are captured and raised sensibly.
|
|
|
|
"""
|
|
|
|
settings = APISettings({
|
|
|
|
'DEFAULT_RENDERER_CLASSES': [
|
|
|
|
'tests.invalid_module.InvalidClassName'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
with self.assertRaises(ImportError):
|
|
|
|
settings.DEFAULT_RENDERER_CLASSES
|
2015-07-02 12:28:46 +03:00
|
|
|
|
2015-12-17 03:32:32 +03:00
|
|
|
def test_warning_raised_on_removed_setting(self):
|
2015-12-08 07:17:33 +03:00
|
|
|
"""
|
|
|
|
Make sure user is alerted with an error when a removed setting
|
|
|
|
is set.
|
|
|
|
"""
|
2016-07-13 18:30:41 +03:00
|
|
|
with self.assertRaises(RuntimeError):
|
2015-12-08 07:17:33 +03:00
|
|
|
APISettings({
|
|
|
|
'MAX_PAGINATE_BY': 100
|
|
|
|
})
|
|
|
|
|
2017-12-14 12:33:48 +03:00
|
|
|
def test_compatibility_with_override_settings(self):
|
|
|
|
"""
|
|
|
|
Ref #5658 & #2466: Documented usage of api_settings
|
|
|
|
is bound at import time:
|
|
|
|
|
|
|
|
from rest_framework.settings import api_settings
|
|
|
|
|
|
|
|
setting_changed signal hook must ensure bound instance
|
|
|
|
is refreshed.
|
|
|
|
"""
|
|
|
|
assert api_settings.PAGE_SIZE is None, "Checking a known default should be None"
|
|
|
|
|
|
|
|
with override_settings(REST_FRAMEWORK={'PAGE_SIZE': 10}):
|
|
|
|
assert api_settings.PAGE_SIZE == 10, "Setting should have been updated"
|
|
|
|
|
|
|
|
assert api_settings.PAGE_SIZE is None, "Setting should have been restored"
|
|
|
|
|
2015-07-02 12:28:46 +03:00
|
|
|
|
|
|
|
class TestSettingTypes(TestCase):
|
|
|
|
def test_settings_consistently_coerced_to_list(self):
|
|
|
|
settings = APISettings({
|
|
|
|
'DEFAULT_THROTTLE_CLASSES': ('rest_framework.throttling.BaseThrottle',)
|
|
|
|
})
|
|
|
|
self.assertTrue(isinstance(settings.DEFAULT_THROTTLE_CLASSES, list))
|
|
|
|
|
|
|
|
settings = APISettings({
|
|
|
|
'DEFAULT_THROTTLE_CLASSES': ()
|
|
|
|
})
|
|
|
|
self.assertTrue(isinstance(settings.DEFAULT_THROTTLE_CLASSES, list))
|