2009-12-12 17:51:51 +00:00
|
|
|
from django.conf import settings
|
2010-10-11 12:55:17 +00:00
|
|
|
from django.utils import unittest
|
2011-01-02 01:33:11 +00:00
|
|
|
|
2009-12-12 17:51:51 +00:00
|
|
|
|
|
|
|
class SettingsTests(unittest.TestCase):
|
|
|
|
|
|
|
|
#
|
|
|
|
# Regression tests for #10130: deleting settings.
|
|
|
|
#
|
|
|
|
|
|
|
|
def test_settings_delete(self):
|
|
|
|
settings.TEST = 'test'
|
|
|
|
self.assertEqual('test', settings.TEST)
|
|
|
|
del settings.TEST
|
|
|
|
self.assertRaises(AttributeError, getattr, settings, 'TEST')
|
|
|
|
|
|
|
|
def test_settings_delete_wrapped(self):
|
|
|
|
self.assertRaises(TypeError, delattr, settings, '_wrapped')
|
2011-01-02 01:33:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TrailingSlashURLTests(unittest.TestCase):
|
|
|
|
settings_module = settings
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self._original_media_url = self.settings_module.MEDIA_URL
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.settings_module.MEDIA_URL = self._original_media_url
|
|
|
|
|
|
|
|
def test_blank(self):
|
|
|
|
"""
|
2011-04-02 08:44:47 +00:00
|
|
|
If blank, no DeprecationWarning error will be raised, even though it
|
2011-01-02 01:33:11 +00:00
|
|
|
doesn't end in a slash.
|
|
|
|
"""
|
|
|
|
self.settings_module.MEDIA_URL = ''
|
|
|
|
self.assertEqual('', self.settings_module.MEDIA_URL)
|
|
|
|
|
|
|
|
def test_end_slash(self):
|
|
|
|
"""
|
|
|
|
MEDIA_URL works if you end in a slash.
|
|
|
|
"""
|
|
|
|
self.settings_module.MEDIA_URL = '/foo/'
|
|
|
|
self.assertEqual('/foo/', self.settings_module.MEDIA_URL)
|
|
|
|
|
|
|
|
self.settings_module.MEDIA_URL = 'http://media.foo.com/'
|
|
|
|
self.assertEqual('http://media.foo.com/',
|
|
|
|
self.settings_module.MEDIA_URL)
|
|
|
|
|
|
|
|
def test_no_end_slash(self):
|
|
|
|
"""
|
2011-04-02 08:44:47 +00:00
|
|
|
MEDIA_URL raises an DeprecationWarning error if it doesn't end in a
|
2011-01-02 01:33:11 +00:00
|
|
|
slash.
|
|
|
|
"""
|
|
|
|
import warnings
|
2011-04-02 08:44:47 +00:00
|
|
|
warnings.filterwarnings('error', 'If set, MEDIA_URL must end with a slash', DeprecationWarning)
|
2011-01-02 01:33:11 +00:00
|
|
|
|
|
|
|
def setattr_settings(settings_module, attr, value):
|
|
|
|
setattr(settings_module, attr, value)
|
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
self.assertRaises(DeprecationWarning, setattr_settings,
|
2011-01-02 01:33:11 +00:00
|
|
|
self.settings_module, 'MEDIA_URL', '/foo')
|
|
|
|
|
2011-04-02 08:44:47 +00:00
|
|
|
self.assertRaises(DeprecationWarning, setattr_settings,
|
2011-01-02 01:33:11 +00:00
|
|
|
self.settings_module, 'MEDIA_URL',
|
|
|
|
'http://media.foo.com')
|
|
|
|
|
|
|
|
def test_double_slash(self):
|
|
|
|
"""
|
|
|
|
If a MEDIA_URL ends in more than one slash, presume they know what
|
|
|
|
they're doing.
|
|
|
|
"""
|
|
|
|
self.settings_module.MEDIA_URL = '/stupid//'
|
|
|
|
self.assertEqual('/stupid//', self.settings_module.MEDIA_URL)
|
|
|
|
|
|
|
|
self.settings_module.MEDIA_URL = 'http://media.foo.com/stupid//'
|
|
|
|
self.assertEqual('http://media.foo.com/stupid//',
|
|
|
|
self.settings_module.MEDIA_URL)
|