Changed error to warning message

This commit is contained in:
Luis San Pablo 2015-12-16 18:32:32 -06:00
parent fbd89d6b7e
commit dab6bf4b1a
2 changed files with 7 additions and 3 deletions

View File

@ -17,6 +17,7 @@ This module provides the `api_setting` object, that is used to access
REST framework settings, checking for user settings first, then falling REST framework settings, checking for user settings first, then falling
back to the defaults. back to the defaults.
""" """
import warnings
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings from django.conf import settings
@ -216,7 +217,7 @@ class APISettings(object):
SETTINGS_DOC = "http://www.django-rest-framework.org/api-guide/settings/" SETTINGS_DOC = "http://www.django-rest-framework.org/api-guide/settings/"
for setting in REMOVED_SETTINGS: for setting in REMOVED_SETTINGS:
if setting in user_settings: if setting in user_settings:
raise AttributeError("The '%s' setting has been removed. Please refer to '%s' for available settings." % (setting, SETTINGS_DOC)) warnings.warn("The '%s' setting has been removed. Please refer to '%s' for available settings." % (setting, SETTINGS_DOC), DeprecationWarning)
return user_settings return user_settings

View File

@ -18,15 +18,18 @@ class TestSettings(TestCase):
with self.assertRaises(ImportError): with self.assertRaises(ImportError):
settings.DEFAULT_RENDERER_CLASSES settings.DEFAULT_RENDERER_CLASSES
def test_loud_error_raised_on_removed_setting(self): def test_warning_raised_on_removed_setting(self):
""" """
Make sure user is alerted with an error when a removed setting Make sure user is alerted with an error when a removed setting
is set. is set.
""" """
with self.assertRaises(AttributeError): with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
APISettings({ APISettings({
'MAX_PAGINATE_BY': 100 'MAX_PAGINATE_BY': 100
}) })
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
class TestSettingTypes(TestCase): class TestSettingTypes(TestCase):