From b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 16 Sep 2012 13:52:47 +0800 Subject: [PATCH] Refactored skipIfCustomUser into the contrib.auth tests. --- django/contrib/auth/tests/auth_backends.py | 3 ++- django/contrib/auth/tests/basic.py | 3 ++- django/contrib/auth/tests/context_processors.py | 3 ++- django/contrib/auth/tests/decorators.py | 3 +-- django/contrib/auth/tests/forms.py | 3 ++- django/contrib/auth/tests/management.py | 3 ++- django/contrib/auth/tests/models.py | 3 ++- django/contrib/auth/tests/remote_user.py | 3 ++- django/contrib/auth/tests/signals.py | 5 +++-- django/contrib/auth/tests/tokens.py | 3 ++- django/contrib/auth/tests/utils.py | 9 +++++++++ django/contrib/auth/tests/views.py | 3 ++- django/test/__init__.py | 2 +- django/test/testcases.py | 11 ++--------- 14 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 django/contrib/auth/tests/utils.py diff --git a/django/contrib/auth/tests/auth_backends.py b/django/contrib/auth/tests/auth_backends.py index b37de883d4..a6be985412 100644 --- a/django/contrib/auth/tests/auth_backends.py +++ b/django/contrib/auth/tests/auth_backends.py @@ -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 diff --git a/django/contrib/auth/tests/basic.py b/django/contrib/auth/tests/basic.py index cee5dca62b..ec8844026c 100644 --- a/django/contrib/auth/tests/basic.py +++ b/django/contrib/auth/tests/basic.py @@ -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 diff --git a/django/contrib/auth/tests/context_processors.py b/django/contrib/auth/tests/context_processors.py index a0da873f54..4e914133d0 100644 --- a/django/contrib/auth/tests/context_processors.py +++ b/django/contrib/auth/tests/context_processors.py @@ -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 diff --git a/django/contrib/auth/tests/decorators.py b/django/contrib/auth/tests/decorators.py index e75baa251e..be99e7abb6 100644 --- a/django/contrib/auth/tests/decorators.py +++ b/django/contrib/auth/tests/decorators.py @@ -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 diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py index 38f21cd7c0..7c6410da0f 100644 --- a/django/contrib/auth/tests/forms.py +++ b/django/contrib/auth/tests/forms.py @@ -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 diff --git a/django/contrib/auth/tests/management.py b/django/contrib/auth/tests/management.py index 783dd38642..60c05a0255 100644 --- a/django/contrib/auth/tests/management.py +++ b/django/contrib/auth/tests/management.py @@ -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 diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py index 7595dbce34..252a0887c8 100644 --- a/django/contrib/auth/tests/models.py +++ b/django/contrib/auth/tests/models.py @@ -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 diff --git a/django/contrib/auth/tests/remote_user.py b/django/contrib/auth/tests/remote_user.py index f74239b68f..9b0f6f8be3 100644 --- a/django/contrib/auth/tests/remote_user.py +++ b/django/contrib/auth/tests/remote_user.py @@ -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 diff --git a/django/contrib/auth/tests/signals.py b/django/contrib/auth/tests/signals.py index af2da8c93e..53057452d2 100644 --- a/django/contrib/auth/tests/signals.py +++ b/django/contrib/auth/tests/signals.py @@ -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 diff --git a/django/contrib/auth/tests/tokens.py b/django/contrib/auth/tests/tokens.py index 0db0fdad0d..e8aeb46326 100644 --- a/django/contrib/auth/tests/tokens.py +++ b/django/contrib/auth/tests/tokens.py @@ -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 diff --git a/django/contrib/auth/tests/utils.py b/django/contrib/auth/tests/utils.py new file mode 100644 index 0000000000..6bb3d9994f --- /dev/null +++ b/django/contrib/auth/tests/utils.py @@ -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) diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py index 05db1857f2..635ebf5436 100644 --- a/django/contrib/auth/tests/views.py +++ b/django/contrib/auth/tests/views.py @@ -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( diff --git a/django/test/__init__.py b/django/test/__init__.py index 58814ce107..7a4987508e 100644 --- a/django/test/__init__.py +++ b/django/test/__init__.py @@ -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 diff --git a/django/test/testcases.py b/django/test/testcases.py index 0e7c59cd49..e5788ccd76 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -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'(?