Add `--emailuser` flag to runtests.py to enable the EmailUser model

wagtail.admin.tests.test_password_reset (currently the only test module where EmailUser is in use) has been updated to skip the CustomUser or EmailUser-specific test according to the active AUTH_USER_MODEL, and so this now succeeds with or without the `--emailuser` flag.
pull/6361/head
Matt Westcott 2020-08-13 23:28:33 +01:00 zatwierdzone przez Matt Westcott
rodzic 0b070018f3
commit afb51eafbe
3 zmienionych plików z 21 dodań i 12 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ def make_parser():
parser.add_argument('--elasticsearch5', action='store_true')
parser.add_argument('--elasticsearch6', action='store_true')
parser.add_argument('--elasticsearch7', action='store_true')
parser.add_argument('--emailuser', action='store_true')
parser.add_argument('--bench', action='store_true')
return parser
@ -66,6 +67,8 @@ def runtests():
# forcibly delete the ELASTICSEARCH_URL setting to skip those tests
del os.environ['ELASTICSEARCH_URL']
os.environ['USE_EMAIL_USER_MODEL'] = '1' if args.emailuser else ''
if args.bench:
benchmarks = [
'wagtail.admin.tests.benches',

Wyświetl plik

@ -1,3 +1,6 @@
import unittest
from django.conf import settings
from django.core import mail
from django.test import TestCase, override_settings
from django.urls import reverse
@ -57,6 +60,7 @@ class TestUserPasswordReset(TestCase, WagtailTestUtils):
self.assertEqual(len(mail.outbox), 1)
self.assertIn("mysite.com", mail.outbox[0].body)
@unittest.skipUnless(settings.AUTH_USER_MODEL == 'customuser.CustomUser', "only applicable to CustomUser")
def test_password_reset_email_contains_username(self):
self.client.post(
reverse('wagtailadmin_password_reset'), {'email': 'siteeditor@example.com'}
@ -64,7 +68,7 @@ class TestUserPasswordReset(TestCase, WagtailTestUtils):
self.assertEqual(len(mail.outbox), 1)
self.assertIn("Your username (in case you've forgotten): siteeditor", mail.outbox[0].body)
@override_settings(AUTH_USER_MODEL='emailuser.EmailUser')
@unittest.skipUnless(settings.AUTH_USER_MODEL == 'emailuser.EmailUser', "only applicable to EmailUser")
def test_password_reset_no_username_when_email_is_username(self):
# When the user model is using email as the username, the password reset email
# should not contain "Your username (in case you've forgotten)..."

Wyświetl plik

@ -97,7 +97,7 @@ MIDDLEWARE = (
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
)
INSTALLED_APPS = (
INSTALLED_APPS = [
# Install wagtailredirects with its appconfig
# Theres nothing special about wagtailredirects, we just need to have one
# app which uses AppConfigs to test that hooks load properly
@ -105,8 +105,6 @@ INSTALLED_APPS = (
'wagtail.tests.testapp',
'wagtail.tests.demosite',
'wagtail.tests.customuser',
'wagtail.tests.emailuser',
'wagtail.tests.snippets',
'wagtail.tests.routablepage',
'wagtail.tests.search',
@ -140,7 +138,7 @@ INSTALLED_APPS = (
'django.contrib.messages',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
)
]
# Using DatabaseCache to make sure that the cache is cleared between tests.
@ -165,7 +163,17 @@ WAGTAILSEARCH_BACKENDS = {
}
}
AUTH_USER_MODEL = 'customuser.CustomUser'
if os.environ.get('USE_EMAIL_USER_MODEL'):
INSTALLED_APPS.append('wagtail.tests.emailuser')
AUTH_USER_MODEL = 'emailuser.EmailUser'
else:
INSTALLED_APPS.append('wagtail.tests.customuser')
AUTH_USER_MODEL = 'customuser.CustomUser'
# Extra user field for custom user edit and create form tests. This setting
# needs to here because it is used at the module level of wagtailusers.forms
# when the module gets loaded. The decorator 'override_settings' does not work
# in this scenario.
WAGTAIL_USER_CUSTOM_FIELDS = ['country', 'attachment']
if os.environ.get('DATABASE_ENGINE') == 'django.db.backends.postgresql':
INSTALLED_APPS += ('wagtail.contrib.postgres_search',)
@ -203,12 +211,6 @@ if 'ELASTICSEARCH_URL' in os.environ:
WAGTAIL_SITE_NAME = "Test Site"
# Extra user field for custom user edit and create form tests. This setting
# needs to here because it is used at the module level of wagtailusers.forms
# when the module gets loaded. The decorator 'override_settings' does not work
# in this scenario.
WAGTAIL_USER_CUSTOM_FIELDS = ['country', 'attachment']
WAGTAILADMIN_RICH_TEXT_EDITORS = {
'default': {
'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea'