Commit b86a0018 authored by Karen Tracey's avatar Karen Tracey
Browse files

Merge pull request #28 from akaariai/ticket_18163

Ticket 18163 - use faster password hasher in tests.
parents 435081fd 0819957e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
import hashlib

from django.dispatch import receiver
from django.conf import settings
from django.test.signals import setting_changed
from django.utils import importlib
from django.utils.datastructures import SortedDict
from django.utils.encoding import smart_str
@@ -14,6 +16,13 @@ UNUSABLE_PASSWORD = '!' # This will never be a valid encoded hash
HASHERS = None  # lazily loaded from PASSWORD_HASHERS
PREFERRED_HASHER = None  # defaults to first item in PASSWORD_HASHERS

@receiver(setting_changed)
def reset_hashers(**kwargs):
    if kwargs['setting'] == 'PASSWORD_HASHERS':
        global HASHERS, PREFERRED_HASHER
        HASHERS = None
        PREFERRED_HASHER = None


def is_password_usable(encoded):
    return (encoded is not None and encoded != UNUSABLE_PASSWORD)
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ from django.test.utils import override_settings
            os.path.join(os.path.dirname(__file__), 'templates'),
        ),
    USE_TZ=False,                           # required for loading the fixture
    PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
)
class AuthContextProcessorTests(TestCase):
    """
+6 −6
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ from django.utils import translation
from django.utils.translation import ugettext as _


@override_settings(USE_TZ=False)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class UserCreationFormTest(TestCase):

    fixtures = ['authtestdata.json']
@@ -77,7 +77,7 @@ class UserCreationFormTest(TestCase):
        self.assertEqual(repr(u), '<User: jsmith@example.com>')


@override_settings(USE_TZ=False)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AuthenticationFormTest(TestCase):

    fixtures = ['authtestdata.json']
@@ -129,7 +129,7 @@ class AuthenticationFormTest(TestCase):
        self.assertEqual(form.non_field_errors(), [])


@override_settings(USE_TZ=False)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class SetPasswordFormTest(TestCase):

    fixtures = ['authtestdata.json']
@@ -156,7 +156,7 @@ class SetPasswordFormTest(TestCase):
        self.assertTrue(form.is_valid())


@override_settings(USE_TZ=False)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class PasswordChangeFormTest(TestCase):

    fixtures = ['authtestdata.json']
@@ -204,7 +204,7 @@ class PasswordChangeFormTest(TestCase):
                         ['old_password', 'new_password1', 'new_password2'])


@override_settings(USE_TZ=False)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class UserChangeFormTest(TestCase):

    fixtures = ['authtestdata.json']
@@ -251,7 +251,7 @@ class UserChangeFormTest(TestCase):
        form.as_table()


@override_settings(USE_TZ=False)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class PasswordResetFormTest(TestCase):

    fixtures = ['authtestdata.json']
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ from django.test.utils import override_settings
from django.contrib.auth import signals


@override_settings(USE_TZ=False)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class SignalTestCase(TestCase):
    urls = 'django.contrib.auth.tests.urls'
    fixtures = ['authtestdata.json']
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ from django.contrib.auth.forms import (AuthenticationForm, PasswordChangeForm,
        os.path.join(os.path.dirname(__file__), 'templates'),
    ),
    USE_TZ=False,
    PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
)
class AuthViewsTestCase(TestCase):
    """
Loading