Ticket #10130: 10130-r11594.diff

File 10130-r11594.diff, 1.6 KB (added by Joost Cassee, 15 years ago)

Remember to also add init.py and models.py to test directory.

  • django/utils/functional.py

     
    281281                self._setup()
    282282            setattr(self._wrapped, name, value)
    283283
     284    def __delattr__(self, name):
     285        if name == "_wrapped":
     286            raise AttributeError("Wrapped settings object cannot be deleted.")
     287        else:
     288            if self._wrapped is None:
     289                self._setup()
     290            delattr(self._wrapped, name)
     291
    284292    def _setup(self):
    285293        """
    286294        Must be implemented by subclasses to initialise the wrapped object.
  • tests/regressiontests/settings/tests.py

     
     1import unittest
     2from django.conf import settings
     3
     4class SettingsTest(unittest.TestCase):
     5
     6    def test_set_delete(self):
     7        settings.TEST = 'test'
     8        self.assertEqual('test', settings.TEST)
     9        del settings.TEST
     10        self.assertRaises(AttributeError, lambda: settings.TEST)
     11
     12    def test_delete_wrapped(self):
     13        def del_wrapped():
     14            del settings._wrapped
     15        self.assertRaises(AttributeError, del_wrapped)
Back to Top