diff --git a/wagtail/admin/tests/test_account_management.py b/wagtail/admin/tests/test_account_management.py index f5a1b591da..b84f6cd192 100644 --- a/wagtail/admin/tests/test_account_management.py +++ b/wagtail/admin/tests/test_account_management.py @@ -4,6 +4,7 @@ import tempfile import pytz from django import VERSION as DJANGO_VERSION +from django.conf import settings from django.contrib.auth import views as auth_views from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission @@ -45,7 +46,7 @@ class TestAuthentication(TestCase, WagtailTestUtils): # Post credentials to the login page response = self.client.post(reverse('wagtailadmin_login'), { - 'username': 'test', + 'username': 'test@email.com' if settings.AUTH_USER_MODEL == 'emailuser.EmailUser' else 'test', 'password': 'password', # NOTE: This is set using a hidden field in reality @@ -59,7 +60,7 @@ class TestAuthentication(TestCase, WagtailTestUtils): self.assertTrue('_auth_user_id' in self.client.session) self.assertEqual( str(self.client.session['_auth_user_id']), - str(get_user_model().objects.get(username='test').pk) + str(get_user_model().objects.get(email='test@email.com').pk) ) def test_already_logged_in_redirect(self): diff --git a/wagtail/admin/tests/test_audit_log.py b/wagtail/admin/tests/test_audit_log.py index 37422e4465..d2a627d113 100644 --- a/wagtail/admin/tests/test_audit_log.py +++ b/wagtail/admin/tests/test_audit_log.py @@ -62,7 +62,7 @@ class TestAuditLogAdmin(TestCase, WagtailTestUtils): email='administrator@email.com', password='password' ) - self.editor = self.create_user(username='the_editor', email='editor@email.com', password='password') + self.editor = self.create_user(username='the_editor', email='the_editor@example.com', password='password') sub_editors = Group.objects.create(name='Sub editors') sub_editors.permissions.add(Permission.objects.get( content_type__app_label='wagtailadmin', diff --git a/wagtail/tests/customuser/tests.py b/wagtail/tests/customuser/tests.py index be2e384ef4..28e9c6a60d 100644 --- a/wagtail/tests/customuser/tests.py +++ b/wagtail/tests/customuser/tests.py @@ -1,5 +1,7 @@ import json +import unittest +from django.conf import settings from django.db import connections from django.test import TestCase @@ -8,6 +10,7 @@ from wagtail.tests.utils import WagtailTestUtils from .fields import ConvertedValue, ConvertedValueField +@unittest.skipUnless(settings.AUTH_USER_MODEL == 'customuser.CustomUser', "Only applicable to CustomUser") class TestConvertedValueField(TestCase, WagtailTestUtils): def setUp(self): self.user = self.login() diff --git a/wagtail/users/tests.py b/wagtail/users/tests.py index 27d87a5ab7..860172691b 100644 --- a/wagtail/users/tests.py +++ b/wagtail/users/tests.py @@ -1,4 +1,7 @@ +import unittest + from django import forms +from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.core.exceptions import ImproperlyConfigured @@ -205,9 +208,8 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 1) - self.assertEqual(users.first().email, 'test@user.com') @override_settings( WAGTAIL_USER_CREATION_FORM='wagtail.users.tests.CustomUserCreationForm', @@ -229,9 +231,8 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 1) - self.assertEqual(users.first().email, 'test@user.com') self.assertEqual(users.first().country, 'testcountry') self.assertEqual(users.first().attachment.read(), b"Uploaded file") @@ -252,7 +253,7 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertTrue(response.context['form'].errors['password2']) # Check that the user was not created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 0) @override_settings( @@ -286,7 +287,7 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertEqual(errors['password2'][0].code, 'password_too_similar') # Check that the user was not created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 0) def test_create_with_missing_password(self): @@ -307,7 +308,7 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertTrue(response.context['form'].errors['password1']) # Check that the user was not created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 0) @override_settings(WAGTAILUSERS_PASSWORD_REQUIRED=False) @@ -335,9 +336,8 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 1) - self.assertEqual(users.first().email, 'test@user.com') self.assertEqual(users.first().password, '') @override_settings(WAGTAILUSERS_PASSWORD_REQUIRED=False) @@ -359,7 +359,7 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertTrue(response.context['form'].errors['password2']) # Check that the user was not created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 0) @override_settings(WAGTAILUSERS_PASSWORD_REQUIRED=False) @@ -378,9 +378,8 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 1) - self.assertEqual(users.first().email, 'test@user.com') self.assertTrue(users.first().check_password('banana')) @override_settings(WAGTAILUSERS_PASSWORD_ENABLED=False) @@ -408,9 +407,8 @@ class TestUserCreateView(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was created - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='test@user.com') self.assertEqual(users.count(), 1) - self.assertEqual(users.first().email, 'test@user.com') self.assertEqual(users.first().password, '') def test_before_create_user_hook(self): @@ -503,7 +501,7 @@ class TestUserDeleteView(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was deleted - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='testuser@email.com') self.assertEqual(users.count(), 0) def test_user_cannot_delete_self(self): @@ -524,7 +522,7 @@ class TestUserDeleteView(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was deleted - users = get_user_model().objects.filter(username='testsuperuser') + users = get_user_model().objects.filter(email='testsuperuser@email.com') self.assertEqual(users.count(), 0) def test_before_delete_user_hook(self): @@ -603,7 +601,7 @@ class TestUserDeleteViewForNonSuperuser(TestCase, WagtailTestUtils): self.assertRedirects(response, reverse('wagtailusers_users:index')) # Check that the user was deleted - users = get_user_model().objects.filter(username='testuser') + users = get_user_model().objects.filter(email='testuser@email.com') self.assertEqual(users.count(), 0) def test_user_cannot_delete_self(self): @@ -871,6 +869,7 @@ class TestUserEditView(TestCase, WagtailTestUtils): # Check that the user is still active self.assertEqual(user.is_active, True) + @unittest.skipUnless(settings.AUTH_USER_MODEL == 'customuser.CustomUser', "Only applicable to CustomUser") @override_settings( WAGTAIL_USER_EDIT_FORM='wagtail.users.tests.CustomUserEditForm', ) @@ -895,6 +894,7 @@ class TestUserEditView(TestCase, WagtailTestUtils): self.assertEqual(user.country, 'testcountry') self.assertEqual(user.attachment.read(), b"Uploaded file") + @unittest.skipIf(settings.AUTH_USER_MODEL == 'emailuser.EmailUser', "Not applicable to EmailUser") def test_edit_validation_error(self): # Leave "username" field blank. This should give a validation error response = self.post({