summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_auth_backends.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-02-11 14:38:52 -0500
committerTim Graham <timograham@gmail.com>2015-02-12 07:38:16 -0500
commit0f7f5bc9e7a94ab91c2b3db29ef7cf000eff593f (patch)
tree17168b2dcd85eab4a78cba0596ee2120f889baab /tests/auth_tests/test_auth_backends.py
parent93b3ef9b2e191101c1a49b332d042864df74a658 (diff)
Fixed #24161 -- Stored the user primary key as a serialized value in the session.
This allows using a UUIDField primary key along with the JSON session serializer. Thanks to Trac alias jamesbeith for the report and Simon Charette for the initial patch.
Diffstat (limited to 'tests/auth_tests/test_auth_backends.py')
-rw-r--r--tests/auth_tests/test_auth_backends.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py
index b5d6b82fcc..1977494a24 100644
--- a/tests/auth_tests/test_auth_backends.py
+++ b/tests/auth_tests/test_auth_backends.py
@@ -2,7 +2,9 @@ from __future__ import unicode_literals
from datetime import date
-from django.contrib.auth import BACKEND_SESSION_KEY, authenticate, get_user
+from django.contrib.auth import (
+ BACKEND_SESSION_KEY, SESSION_KEY, authenticate, get_user,
+)
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.hashers import MD5PasswordHasher
from django.contrib.auth.models import AnonymousUser, Group, Permission, User
@@ -12,7 +14,7 @@ from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.http import HttpRequest
from django.test import TestCase, modify_settings, override_settings
-from .models import CustomPermissionsUser
+from .models import CustomPermissionsUser, UUIDUser
class CountingMD5PasswordHasher(MD5PasswordHasher):
@@ -288,6 +290,18 @@ class CustomUserModelBackendAuthenticateTest(TestCase):
self.assertEqual(test_user, authenticated_user)
+@override_settings(AUTH_USER_MODEL='auth.UUIDUser')
+class UUIDUserTests(TestCase):
+
+ def test_login(self):
+ """
+ A custom user with a UUID primary key should be able to login.
+ """
+ user = UUIDUser.objects.create_user(username='uuid', password='test')
+ self.assertTrue(self.client.login(username='uuid', password='test'))
+ self.assertEqual(UUIDUser.objects.get(pk=self.client.session[SESSION_KEY]), user)
+
+
class TestObj(object):
pass