Ticket #16507: 16507.5.diff

File 16507.5.diff, 2.2 KB (added by Claude Paroz, 13 years ago)

Add utility methods at SimpleTestCase level

  • django/contrib/messages/tests/base.py

    diff --git a/django/contrib/messages/tests/base.py b/django/contrib/messages/tests/base.py
    index 8d04532..789faf4 100644
    a b class BaseTest(TestCase):  
    5656
    5757    def setUp(self):
    5858        self.settings_override = override_settings_tags(
    59             TEMPLATE_DIRS  = (),
     59            TEMPLATE_LOADERS = (),
    6060            MESSAGE_TAGS    = '',
    6161            MESSAGE_STORAGE = '%s.%s' % (self.storage_class.__module__,
    6262                                         self.storage_class.__name__),
    6363        )
    6464        self.settings_override.enable()
     65        self.reset_handlers_state()
    6566
    6667    def tearDown(self):
    6768        self.settings_override.disable()
     69        self.restore_handlers_state()
    6870
    6971    def get_request(self):
    7072        return http.HttpRequest()
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    index ee22ac2..d8a882a 100644
    a b from functools import wraps  
    66from urlparse import urlsplit, urlunsplit
    77from xml.dom.minidom import parseString, Node
    88
    9 from django.conf import settings
     9from django.conf import settings, urls as urlhandlers
    1010from django.core import mail
    1111from django.core.exceptions import ValidationError
    1212from django.core.management import call_command
    class SimpleTestCase(ut2.TestCase):  
    262262        """
    263263        restore_warnings_state(self._warnings_state)
    264264
     265    def reset_handlers_state(self):
     266        """
     267        Save url handlers state and reset to default value
     268        """
     269        self._old_url_handlers = (
     270            urlhandlers.handler403,
     271            urlhandlers.handler404,
     272            urlhandlers.handler500
     273        )
     274        handler403 = 'django.views.defaults.permission_denied'
     275        handler404 = 'django.views.defaults.page_not_found'
     276        handler500 = 'django.views.defaults.server_error'
     277
     278    def restore_handlers_state(self):
     279        """
     280        Restore handlers to the state before reset_handlers_state()
     281        """
     282        handler403, handler404, handler500 = self._old_url_handlers
     283
    265284    def settings(self, **kwargs):
    266285        """
    267286        A context manager that temporarily sets a setting and reverts
Back to Top