Ticket #4788: skipped_test_deco_r8069.diff

File skipped_test_deco_r8069.diff, 2.4 KB (added by devin, 16 years ago)

added decorators for skipping tests

  • django/test/__init__.py

     
    44
    55from django.test.client import Client
    66from django.test.testcases import TestCase
     7
     8class SkippedTest(Exception):
     9    pass
     10 No newline at end of file
  • django/test/decorators.py

     
     1from django.core import urlresolvers
     2from django.test import SkippedTest
     3
     4def views_required(required_views=[]):
     5    def urls_found():
     6        try:
     7            for view in required_views:
     8                url = urlresolvers.reverse(view)
     9            return True
     10        except urlresolvers.NoReverseMatch:
     11            return False
     12    return conditional_skip(urls_found)
     13
     14def conditional_skip(required_condition):
     15    if required_condition():
     16        return lambda x: x
     17    else:
     18        return skip_test
     19
     20def skip_test(function):
     21    def _skip(x):
     22        raise SkippedTest
     23    return _skip
     24 No newline at end of file
  • django/contrib/auth/tests/basic.py

     
    5656"""
    5757
    5858from django.test import TestCase
     59from django.test.decorators import views_required
    5960from django.core import mail
    6061
    6162class PasswordResetTest(TestCase):
    6263    fixtures = ['authtestdata.json']
    6364    urls = 'django.contrib.auth.urls'
    6465   
     66    @views_required(required_views=['django.contrib.auth.views.password_reset'])
    6567    def test_email_not_found(self):
    6668        "Error is raised if the provided email address isn't currently registered"
    6769        response = self.client.get('/password_reset/')
     
    7072        self.assertContains(response, "That e-mail address doesn't have an associated user account")
    7173        self.assertEquals(len(mail.outbox), 0)
    7274   
     75    @views_required(required_views=['django.contrib.auth.views.password_reset'])
    7376    def test_email_found(self):
    7477        "Email is sent if a valid email address is provided for password reset"
    7578        response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
Back to Top