PageRenderTime 72ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 24ms app.codeStats 0ms

/tests/regressiontests/settings_tests/tests.py

https://code.google.com/p/mango-py/
Python | 78 lines | 59 code | 10 blank | 9 comment | 2 complexity | b40267fb795af58f8871120245813041 MD5 | raw file
 1from django.conf import settings
 2from django.utils import unittest
 3from django.conf import settings, UserSettingsHolder, global_settings
 4
 5
 6class SettingsTests(unittest.TestCase):
 7
 8    #
 9    # Regression tests for #10130: deleting settings.
10    #
11
12    def test_settings_delete(self):
13        settings.TEST = 'test'
14        self.assertEqual('test', settings.TEST)
15        del settings.TEST
16        self.assertRaises(AttributeError, getattr, settings, 'TEST')
17
18    def test_settings_delete_wrapped(self):
19        self.assertRaises(TypeError, delattr, settings, '_wrapped')
20
21
22class TrailingSlashURLTests(unittest.TestCase):
23    settings_module = settings
24
25    def setUp(self):
26        self._original_media_url = self.settings_module.MEDIA_URL
27
28    def tearDown(self):
29        self.settings_module.MEDIA_URL = self._original_media_url
30
31    def test_blank(self):
32        """
33        If blank, no PendingDeprecationWarning error will be raised, even though it
34        doesn't end in a slash.
35        """
36        self.settings_module.MEDIA_URL = ''
37        self.assertEqual('', self.settings_module.MEDIA_URL)
38
39    def test_end_slash(self):
40        """
41        MEDIA_URL works if you end in a slash.
42        """
43        self.settings_module.MEDIA_URL = '/foo/'
44        self.assertEqual('/foo/', self.settings_module.MEDIA_URL)
45
46        self.settings_module.MEDIA_URL = 'http://media.foo.com/'
47        self.assertEqual('http://media.foo.com/',
48                         self.settings_module.MEDIA_URL)
49
50    def test_no_end_slash(self):
51        """
52        MEDIA_URL raises an PendingDeprecationWarning error if it doesn't end in a
53        slash.
54        """
55        import warnings
56        warnings.filterwarnings('error', 'If set, MEDIA_URL must end with a slash', PendingDeprecationWarning)
57
58        def setattr_settings(settings_module, attr, value):
59            setattr(settings_module, attr, value)
60
61        self.assertRaises(PendingDeprecationWarning, setattr_settings,
62                          self.settings_module, 'MEDIA_URL', '/foo')
63
64        self.assertRaises(PendingDeprecationWarning, setattr_settings,
65                          self.settings_module, 'MEDIA_URL',
66                          'http://media.foo.com')
67
68    def test_double_slash(self):
69        """
70        If a MEDIA_URL ends in more than one slash, presume they know what
71        they're doing.
72        """
73        self.settings_module.MEDIA_URL = '/stupid//'
74        self.assertEqual('/stupid//', self.settings_module.MEDIA_URL)
75
76        self.settings_module.MEDIA_URL = 'http://media.foo.com/stupid//'
77        self.assertEqual('http://media.foo.com/stupid//',
78                         self.settings_module.MEDIA_URL)