Added conditional skips for all tests dependent on the default User model
This commit is contained in:
parent
40ea8b8882
commit
20d1892491
|
@ -4,10 +4,11 @@ from django.conf import settings
|
|||
from django.contrib.auth.models import User, Group, Permission, AnonymousUser
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.test.utils import override_settings
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class BackendTest(TestCase):
|
||||
|
||||
backend = 'django.contrib.auth.backends.ModelBackend'
|
||||
|
@ -151,6 +152,7 @@ class SimpleRowlevelBackend(object):
|
|||
return ['none']
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class RowlevelBackendTest(TestCase):
|
||||
"""
|
||||
Tests for auth backend that supports object level permissions
|
||||
|
@ -223,6 +225,7 @@ class AnonymousUserBackendTest(TestCase):
|
|||
self.assertEqual(self.user1.get_all_permissions(TestObj()), set(['anon']))
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(AUTHENTICATION_BACKENDS=[])
|
||||
class NoBackendsTest(TestCase):
|
||||
"""
|
||||
|
@ -235,6 +238,7 @@ class NoBackendsTest(TestCase):
|
|||
self.assertRaises(ImproperlyConfigured, self.user.has_perm, ('perm', TestObj(),))
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class InActiveUserBackendTest(TestCase):
|
||||
"""
|
||||
Tests for a inactive user
|
||||
|
|
|
@ -3,10 +3,11 @@ import locale
|
|||
from django.contrib.auth.management.commands import createsuperuser
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.utils.six import StringIO
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class BasicTestCase(TestCase):
|
||||
def test_user(self):
|
||||
"Check that users can be created and can set their password"
|
||||
|
|
|
@ -3,11 +3,11 @@ import os
|
|||
from django.conf import global_settings
|
||||
from django.contrib.auth import authenticate
|
||||
from django.db.models import Q
|
||||
from django.template import context
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.test.utils import override_settings
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(
|
||||
TEMPLATE_DIRS=(
|
||||
os.path.join(os.path.dirname(__file__), 'templates'),
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
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
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class LoginRequiredTestCase(AuthViewsTestCase):
|
||||
"""
|
||||
Tests the login_required decorators
|
||||
|
|
|
@ -6,14 +6,14 @@ from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm,
|
|||
PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm)
|
||||
from django.core import mail
|
||||
from django.forms.fields import Field, EmailField
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils import six
|
||||
from django.utils import translation
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class UserCreationFormTest(TestCase):
|
||||
|
||||
|
@ -81,6 +81,7 @@ class UserCreationFormTest(TestCase):
|
|||
self.assertEqual(repr(u), '<User: jsmith@example.com>')
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class AuthenticationFormTest(TestCase):
|
||||
|
||||
|
@ -133,6 +134,7 @@ class AuthenticationFormTest(TestCase):
|
|||
self.assertEqual(form.non_field_errors(), [])
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class SetPasswordFormTest(TestCase):
|
||||
|
||||
|
@ -160,6 +162,7 @@ class SetPasswordFormTest(TestCase):
|
|||
self.assertTrue(form.is_valid())
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class PasswordChangeFormTest(TestCase):
|
||||
|
||||
|
@ -208,6 +211,7 @@ class PasswordChangeFormTest(TestCase):
|
|||
['old_password', 'new_password1', 'new_password2'])
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class UserChangeFormTest(TestCase):
|
||||
|
||||
|
@ -255,6 +259,7 @@ class UserChangeFormTest(TestCase):
|
|||
form.as_table()
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class PasswordResetFormTest(TestCase):
|
||||
|
||||
|
|
|
@ -7,12 +7,13 @@ from django.contrib.auth.models import User
|
|||
from django.contrib.auth.tests import CustomUser
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import six
|
||||
from django.utils.six import StringIO
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class GetDefaultUsernameTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -41,6 +42,7 @@ class GetDefaultUsernameTestCase(TestCase):
|
|||
self.assertEqual(management.get_default_username(), 'julia')
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class ChangepasswordManagementCommandTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -76,6 +78,7 @@ class ChangepasswordManagementCommandTestCase(TestCase):
|
|||
command.execute("joe", stdout=self.stdout, stderr=self.stderr)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class CreatesuperuserManagementCommandTestCase(TestCase):
|
||||
|
||||
def test_createsuperuser(self):
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.test.utils import override_settings
|
||||
from django.contrib.auth.models import (Group, User,
|
||||
SiteProfileNotAvailable, UserManager)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
|
||||
class ProfileTestCase(TestCase):
|
||||
|
||||
|
@ -30,6 +31,7 @@ class ProfileTestCase(TestCase):
|
|||
user.get_profile()
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False)
|
||||
class NaturalKeysTestCase(TestCase):
|
||||
fixtures = ['authtestdata.json']
|
||||
|
@ -44,6 +46,7 @@ class NaturalKeysTestCase(TestCase):
|
|||
self.assertEqual(Group.objects.get_by_natural_key('users'), users_group)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False)
|
||||
class LoadDataWithoutNaturalKeysTestCase(TestCase):
|
||||
fixtures = ['regular.json']
|
||||
|
@ -54,6 +57,7 @@ class LoadDataWithoutNaturalKeysTestCase(TestCase):
|
|||
self.assertEqual(group, user.groups.get())
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False)
|
||||
class LoadDataWithNaturalKeysTestCase(TestCase):
|
||||
fixtures = ['natural.json']
|
||||
|
@ -64,6 +68,7 @@ class LoadDataWithNaturalKeysTestCase(TestCase):
|
|||
self.assertEqual(group, user.groups.get())
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class UserManagerTestCase(TestCase):
|
||||
|
||||
def test_create_user(self):
|
||||
|
|
|
@ -3,10 +3,11 @@ 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
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class RemoteUserTest(TestCase):
|
||||
|
||||
urls = 'django.contrib.auth.tests.urls'
|
||||
|
@ -106,6 +107,7 @@ class RemoteUserNoCreateBackend(RemoteUserBackend):
|
|||
create_unknown_user = False
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class RemoteUserNoCreateTest(RemoteUserTest):
|
||||
"""
|
||||
Contains the same tests as RemoteUserTest, but using a custom auth backend
|
||||
|
@ -142,6 +144,7 @@ class CustomRemoteUserBackend(RemoteUserBackend):
|
|||
return user
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class RemoteUserCustomTest(RemoteUserTest):
|
||||
"""
|
||||
Tests a custom RemoteUserBackend subclass that overrides the clean_username
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from django.test import TestCase
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.test.utils import override_settings
|
||||
from django.contrib.auth import signals
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class SignalTestCase(TestCase):
|
||||
urls = 'django.contrib.auth.tests.urls'
|
||||
|
|
|
@ -4,10 +4,11 @@ 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
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.utils import unittest
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class TokenGeneratorTest(TestCase):
|
||||
|
||||
def test_make_token(self):
|
||||
|
|
|
@ -10,7 +10,7 @@ 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
|
||||
from django.test import TestCase, skipIfCustomUser
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
|
||||
|
@ -49,6 +49,7 @@ class AuthViewsTestCase(TestCase):
|
|||
return self.assertContains(response, escape(force_text(text)), **kwargs)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class AuthViewNamedURLTests(AuthViewsTestCase):
|
||||
urls = 'django.contrib.auth.urls'
|
||||
|
||||
|
@ -74,6 +75,7 @@ class AuthViewNamedURLTests(AuthViewsTestCase):
|
|||
self.fail("Reversal of url named '%s' failed with NoReverseMatch" % name)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class PasswordResetTest(AuthViewsTestCase):
|
||||
|
||||
def test_email_not_found(self):
|
||||
|
@ -171,6 +173,7 @@ class PasswordResetTest(AuthViewsTestCase):
|
|||
self.assertContainsEscaped(response, SetPasswordForm.error_messages['password_mismatch'])
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class ChangePasswordTest(AuthViewsTestCase):
|
||||
|
||||
def fail_login(self, password='password'):
|
||||
|
@ -230,6 +233,7 @@ class ChangePasswordTest(AuthViewsTestCase):
|
|||
self.assertTrue(response['Location'].endswith('/login/?next=/password_change/done/'))
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class LoginTest(AuthViewsTestCase):
|
||||
|
||||
def test_current_site_in_context_after_login(self):
|
||||
|
@ -288,6 +292,7 @@ class LoginTest(AuthViewsTestCase):
|
|||
"%s should be allowed" % good_url)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class LoginURLSettings(AuthViewsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -346,6 +351,7 @@ class LoginURLSettings(AuthViewsTestCase):
|
|||
querystring.urlencode('/')))
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class LogoutTest(AuthViewsTestCase):
|
||||
|
||||
def confirm_logged_out(self):
|
||||
|
|
|
@ -5,5 +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)
|
||||
skipUnlessDBFeature, skipIfCustomUser
|
||||
)
|
||||
from django.test.utils import Approximate
|
||||
|
|
|
@ -44,10 +44,12 @@ from django.utils import unittest as ut2
|
|||
from django.utils.encoding import force_text
|
||||
from django.utils import six
|
||||
from django.utils.unittest.util import safe_repr
|
||||
from django.utils.unittest import skipIf
|
||||
from django.views.static import serve
|
||||
|
||||
__all__ = ('DocTestRunner', 'OutputChecker', 'TestCase', 'TransactionTestCase',
|
||||
'SimpleTestCase', 'skipIfDBFeature', 'skipUnlessDBFeature')
|
||||
'SimpleTestCase', 'skipIfDBFeature', 'skipUnlessDBFeature',
|
||||
'skipIfCustomUser')
|
||||
|
||||
normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
|
||||
normalize_decimals = lambda s: re.sub(r"Decimal\('(\d+(\.\d*)?)'\)",
|
||||
|
@ -906,6 +908,13 @@ 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
|
||||
|
|
Loading…
Reference in New Issue