diff options
| author | Tobias Bengfort <tobias.bengfort@posteo.de> | 2019-03-08 17:48:50 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-06-05 13:39:46 +0200 |
| commit | 75337a60509fdfdd321a5caf8e30d57fff6b9518 (patch) | |
| tree | f69d37eaa5a1be92bf82ae089744d73b59506de1 /tests | |
| parent | 4b6dfe16226a81fea464ac5f77942f4d6ba266e8 (diff) | |
Fixed #30226 -- Added BaseBackend for authentication.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_auth_backends.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py index 02f7d3ef27..84facd6c3a 100644 --- a/tests/auth_tests/test_auth_backends.py +++ b/tests/auth_tests/test_auth_backends.py @@ -4,7 +4,7 @@ from unittest import mock from django.contrib.auth import ( BACKEND_SESSION_KEY, SESSION_KEY, authenticate, get_user, signals, ) -from django.contrib.auth.backends import ModelBackend +from django.contrib.auth.backends import BaseBackend, ModelBackend from django.contrib.auth.hashers import MD5PasswordHasher from django.contrib.auth.models import AnonymousUser, Group, Permission, User from django.contrib.contenttypes.models import ContentType @@ -20,6 +20,28 @@ from .models import ( ) +class SimpleBackend(BaseBackend): + def get_group_permissions(self, user_obj, obj=None): + return ['group_perm'] + + +@override_settings(AUTHENTICATION_BACKENDS=['auth_tests.test_auth_backends.SimpleBackend']) +class BaseBackendTest(TestCase): + @classmethod + def setUpTestData(cls): + cls.user = User.objects.create_user('test', 'test@example.com', 'test') + + def test_get_group_permissions(self): + self.assertEqual(self.user.get_group_permissions(), {'group_perm'}) + + def test_get_all_permissions(self): + self.assertEqual(self.user.get_all_permissions(), {'group_perm'}) + + def test_has_perm(self): + self.assertIs(self.user.has_perm('group_perm'), True) + self.assertIs(self.user.has_perm('other_perm', TestObj()), False) + + class CountingMD5PasswordHasher(MD5PasswordHasher): """Hasher that counts how many times it computes a hash.""" |
