Modified auth to work with unittest2 discovery.

This commit is contained in:
Preston Timmons 2013-04-03 03:22:07 +00:00 committed by Carl Meyer
parent e3cfbaaca4
commit fde2e4fd6e
15 changed files with 35 additions and 36 deletions

View File

@ -1,29 +1,16 @@
from django.contrib.auth.tests.custom_user import * from django.contrib.auth.tests.test_custom_user import *
from django.contrib.auth.tests.auth_backends import * from django.contrib.auth.tests.test_auth_backends import *
from django.contrib.auth.tests.basic import * from django.contrib.auth.tests.test_basic import *
from django.contrib.auth.tests.context_processors import * from django.contrib.auth.tests.test_context_processors import *
from django.contrib.auth.tests.decorators import * from django.contrib.auth.tests.test_decorators import *
from django.contrib.auth.tests.forms import * from django.contrib.auth.tests.test_forms import *
from django.contrib.auth.tests.remote_user import * from django.contrib.auth.tests.test_remote_user import *
from django.contrib.auth.tests.management import * from django.contrib.auth.tests.test_management import *
from django.contrib.auth.tests.models import * from django.contrib.auth.tests.test_models import *
from django.contrib.auth.tests.handlers import * from django.contrib.auth.tests.test_handlers import *
from django.contrib.auth.tests.hashers import * from django.contrib.auth.tests.test_hashers import *
from django.contrib.auth.tests.signals import * from django.contrib.auth.tests.test_signals import *
from django.contrib.auth.tests.tokens import * from django.contrib.auth.tests.test_tokens import *
from django.contrib.auth.tests.views import * from django.contrib.auth.tests.test_views import *
# The password for the fixture data users is 'password' # The password for the fixture data users is 'password'
from django.dispatch import receiver
from django.test.signals import setting_changed
@receiver(setting_changed)
def user_model_swapped(**kwargs):
if kwargs['setting'] == 'AUTH_USER_MODEL':
from django.db.models.manager import ensure_default_manager
from django.contrib.auth.models import User
# Reset User manager
setattr(User, 'objects', User._default_manager)
ensure_default_manager(User)

View File

@ -4,7 +4,7 @@ from datetime import date
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User, Group, Permission, AnonymousUser from django.contrib.auth.models import User, Group, Permission, AnonymousUser
from django.contrib.auth.tests.utils import skipIfCustomUser from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.auth.tests.custom_user import ExtensionUser, CustomPermissionsUser, CustomUser from django.contrib.auth.tests.test_custom_user import ExtensionUser, CustomPermissionsUser, CustomUser
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
@ -263,7 +263,7 @@ class RowlevelBackendTest(TestCase):
""" """
Tests for auth backend that supports object level permissions Tests for auth backend that supports object level permissions
""" """
backend = 'django.contrib.auth.tests.auth_backends.SimpleRowlevelBackend' backend = 'django.contrib.auth.tests.test_auth_backends.SimpleRowlevelBackend'
def setUp(self): def setUp(self):
self.curr_auth = settings.AUTHENTICATION_BACKENDS self.curr_auth = settings.AUTHENTICATION_BACKENDS
@ -304,7 +304,7 @@ class AnonymousUserBackendTest(TestCase):
Tests for AnonymousUser delegating to backend. Tests for AnonymousUser delegating to backend.
""" """
backend = 'django.contrib.auth.tests.auth_backends.SimpleRowlevelBackend' backend = 'django.contrib.auth.tests.test_auth_backends.SimpleRowlevelBackend'
def setUp(self): def setUp(self):
self.curr_auth = settings.AUTHENTICATION_BACKENDS self.curr_auth = settings.AUTHENTICATION_BACKENDS
@ -348,7 +348,7 @@ class InActiveUserBackendTest(TestCase):
""" """
Tests for a inactive user Tests for a inactive user
""" """
backend = 'django.contrib.auth.tests.auth_backends.SimpleRowlevelBackend' backend = 'django.contrib.auth.tests.test_auth_backends.SimpleRowlevelBackend'
def setUp(self): def setUp(self):
self.curr_auth = settings.AUTHENTICATION_BACKENDS self.curr_auth = settings.AUTHENTICATION_BACKENDS
@ -386,7 +386,7 @@ class PermissionDeniedBackendTest(TestCase):
""" """
Tests that other backends are not checked once a backend raises PermissionDenied Tests that other backends are not checked once a backend raises PermissionDenied
""" """
backend = 'django.contrib.auth.tests.auth_backends.PermissionDeniedBackend' backend = 'django.contrib.auth.tests.test_auth_backends.PermissionDeniedBackend'
def setUp(self): def setUp(self):
self.user1 = User.objects.create_user('test', 'test@example.com', 'test') self.user1 = User.objects.create_user('test', 'test@example.com', 'test')

View File

@ -6,17 +6,29 @@ import locale
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.management.commands import createsuperuser from django.contrib.auth.management.commands import createsuperuser
from django.contrib.auth.models import User, AnonymousUser from django.contrib.auth.models import User, AnonymousUser
from django.contrib.auth.tests.custom_user import CustomUser from django.contrib.auth.tests.test_custom_user import CustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command from django.core.management import call_command
from django.dispatch import receiver
from django.test import TestCase from django.test import TestCase
from django.test.signals import setting_changed
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils import translation from django.utils import translation
from django.utils.encoding import force_str from django.utils.encoding import force_str
from django.utils.six import binary_type, PY3, StringIO from django.utils.six import binary_type, PY3, StringIO
@receiver(setting_changed)
def user_model_swapped(**kwargs):
if kwargs['setting'] == 'AUTH_USER_MODEL':
from django.db.models.manager import ensure_default_manager
from django.contrib.auth.models import User
# Reset User manager
setattr(User, 'objects', User._default_manager)
ensure_default_manager(User)
def mock_inputs(inputs): def mock_inputs(inputs):
""" """
Decorator to temporarily replace input/getpass to allow interactive Decorator to temporarily replace input/getpass to allow interactive

View File

@ -1,5 +1,5 @@
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.tests.views import AuthViewsTestCase from django.contrib.auth.tests.test_views import AuthViewsTestCase
from django.contrib.auth.tests.utils import skipIfCustomUser from django.contrib.auth.tests.utils import skipIfCustomUser

View File

@ -137,7 +137,7 @@ class RemoteUserNoCreateTest(RemoteUserTest):
""" """
backend =\ backend =\
'django.contrib.auth.tests.remote_user.RemoteUserNoCreateBackend' 'django.contrib.auth.tests.test_remote_user.RemoteUserNoCreateBackend'
def test_unknown_user(self): def test_unknown_user(self):
num_users = User.objects.count() num_users = User.objects.count()
@ -174,7 +174,7 @@ class RemoteUserCustomTest(RemoteUserTest):
""" """
backend =\ backend =\
'django.contrib.auth.tests.remote_user.CustomRemoteUserBackend' 'django.contrib.auth.tests.test_remote_user.CustomRemoteUserBackend'
# REMOTE_USER strings with email addresses for the custom backend to # REMOTE_USER strings with email addresses for the custom backend to
# clean. # clean.
known_user = 'knownuser@example.com' known_user = 'knownuser@example.com'