diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-01-02 01:33:11 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-01-02 01:33:11 +0000 |
| commit | 544ab30ed71e0d78c4c061008758de29ff79e8f7 (patch) | |
| tree | 55c710a12a6552bd461d621e38c0d6fa526f5ef6 /tests | |
| parent | 7a89d3d503cad96689fee3028a218ff5456f73f1 (diff) | |
Fixed #6218 -- Made MEDIA_URL and STATIC_URL require a trailing slash to ensure there is a consistent way to combine paths in templates. Thanks to Michael Toomim, Chris Heisel and Chris Beaven.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15130 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/settings_tests/tests.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py index 1b129d8c6f..dc7fde4f2c 100644 --- a/tests/regressiontests/settings_tests/tests.py +++ b/tests/regressiontests/settings_tests/tests.py @@ -1,5 +1,7 @@ from django.conf import settings from django.utils import unittest +from django.conf import settings, UserSettingsHolder, global_settings + class SettingsTests(unittest.TestCase): @@ -15,3 +17,62 @@ class SettingsTests(unittest.TestCase): def test_settings_delete_wrapped(self): self.assertRaises(TypeError, delattr, settings, '_wrapped') + + +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): + """ + If blank, no PendingDeprecationWarning error will be raised, even though it + 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): + """ + MEDIA_URL raises an PendingDeprecationWarning error if it doesn't end in a + slash. + """ + import warnings + warnings.filterwarnings('error', 'If set, MEDIA_URL must end with a slash', PendingDeprecationWarning) + + def setattr_settings(settings_module, attr, value): + setattr(settings_module, attr, value) + + self.assertRaises(PendingDeprecationWarning, setattr_settings, + self.settings_module, 'MEDIA_URL', '/foo') + + self.assertRaises(PendingDeprecationWarning, setattr_settings, + 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) |
