Refactored skipIfCustomUser into the contrib.auth tests.

This commit is contained in:
Russell Keith-Magee 2012-09-16 13:52:47 +08:00
parent 52a02f1110
commit b550a6d06d
14 changed files with 34 additions and 23 deletions

View File

@ -2,9 +2,10 @@ from __future__ import unicode_literals
from django.conf import settings
from django.contrib.auth.models import User, Group, Permission, AnonymousUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, skipIfCustomUser
from django.test import TestCase
from django.test.utils import override_settings

View File

@ -2,8 +2,9 @@ import locale
from django.contrib.auth.management.commands import createsuperuser
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core.management import call_command
from django.test import TestCase, skipIfCustomUser
from django.test import TestCase
from django.utils.six import StringIO

View File

@ -2,8 +2,9 @@ import os
from django.conf import global_settings
from django.contrib.auth import authenticate
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.db.models import Q
from django.test import TestCase, skipIfCustomUser
from django.test import TestCase
from django.test.utils import override_settings

View File

@ -1,7 +1,6 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.tests.views import AuthViewsTestCase
from django.test import skipIfCustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser
@skipIfCustomUser

View File

@ -4,9 +4,10 @@ import os
from django.contrib.auth.models import User
from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm,
PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm)
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core import mail
from django.forms.fields import Field, EmailField
from django.test import TestCase, skipIfCustomUser
from django.test import TestCase
from django.test.utils import override_settings
from django.utils.encoding import force_text
from django.utils import translation

View File

@ -5,9 +5,10 @@ from django.contrib.auth import models, management
from django.contrib.auth.management.commands import changepassword
from django.contrib.auth.models import User
from django.contrib.auth.tests import CustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core.management import call_command
from django.core.management.base import CommandError
from django.test import TestCase, skipIfCustomUser
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import six
from django.utils.six import StringIO

View File

@ -1,7 +1,8 @@
from django.conf import settings
from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
UserManager)
from django.test import TestCase, skipIfCustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import six

View File

@ -3,7 +3,8 @@ from datetime import datetime
from django.conf import settings
from django.contrib.auth.backends import RemoteUserBackend
from django.contrib.auth.models import User
from django.test import TestCase, skipIfCustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.test import TestCase
from django.utils import timezone

View File

@ -1,6 +1,7 @@
from django.test import TestCase, skipIfCustomUser
from django.test.utils import override_settings
from django.contrib.auth import signals
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.test import TestCase
from django.test.utils import override_settings
@skipIfCustomUser

View File

@ -4,7 +4,8 @@ from datetime import date, timedelta
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.test import TestCase, skipIfCustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.test import TestCase
from django.utils import unittest

View File

@ -0,0 +1,9 @@
from django.conf import settings
from django.utils.unittest import skipIf
def skipIfCustomUser(test_func):
"""
Skip a test if a custom user model is in use.
"""
return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)

View File

@ -10,12 +10,13 @@ from django.http import QueryDict
from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.http import urlquote
from django.test import TestCase, skipIfCustomUser
from django.test import TestCase
from django.test.utils import override_settings
from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
from django.contrib.auth.forms import (AuthenticationForm, PasswordChangeForm,
SetPasswordForm, PasswordResetForm)
from django.contrib.auth.tests.utils import skipIfCustomUser
@override_settings(

View File

@ -5,6 +5,6 @@ Django Unit Test and Doctest framework.
from django.test.client import Client, RequestFactory
from django.test.testcases import (TestCase, TransactionTestCase,
SimpleTestCase, LiveServerTestCase, skipIfDBFeature,
skipUnlessDBFeature, skipIfCustomUser
skipUnlessDBFeature
)
from django.test.utils import Approximate

View File

@ -48,13 +48,13 @@ from django.utils.unittest import skipIf
from django.views.static import serve
__all__ = ('DocTestRunner', 'OutputChecker', 'TestCase', 'TransactionTestCase',
'SimpleTestCase', 'skipIfDBFeature', 'skipUnlessDBFeature',
'skipIfCustomUser')
'SimpleTestCase', 'skipIfDBFeature', 'skipUnlessDBFeature')
normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
normalize_decimals = lambda s: re.sub(r"Decimal\('(\d+(\.\d*)?)'\)",
lambda m: "Decimal(\"%s\")" % m.groups()[0], s)
def to_list(value):
"""
Puts value into a list if it's not already one.
@ -908,13 +908,6 @@ def skipUnlessDBFeature(feature):
"Database doesn't support feature %s" % feature)
def skipIfCustomUser(test_func):
"""
Skip a test if a custom user model is in use.
"""
return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
class QuietWSGIRequestHandler(WSGIRequestHandler):
"""
Just a regular WSGIRequestHandler except it doesn't log to the standard