diff --git a/CHANGELOG.txt b/CHANGELOG.txt index bb265346d..78e1b4fc9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -11,6 +11,7 @@ Changelog * Add ability to insert internal anchor links/links with fragment identifiers in Draftail (rich text) fields (Iman Syed) * Remove need for Elasticsearch `update_all_types` workaround, upgrade minimum release to 6.4.0 or above (Jonathan Liuti) * Upgrade django-modelcluster to>=5.0 and upgrade django-taggit to >=1.0 for Django 3.0 support (Matt Westcott) + * Revise tests to ensure all pass in Django 3.0 (Matt Westcott) * Fix: Added line breaks to long filenames on multiple image / document uploader (Kevin Howbrook) * Fix: Added https support for Scribd oEmbed provider (Rodrigo) * Fix: Changed StreamField group labels color so labels are visible (Catherine Farman) diff --git a/docs/releases/2.7.rst b/docs/releases/2.7.rst index 5807caf1a..cd96fe2e4 100644 --- a/docs/releases/2.7.rst +++ b/docs/releases/2.7.rst @@ -26,6 +26,7 @@ Other features * Add ability to insert internal anchor links/links with fragment identifiers in Draftail (rich text) fields (Iman Syed) * Added Table Block caption for accessibility (Rahmi Pruitt) * Upgrade django-modelcluster to>=5.0 and upgrade django-taggit to >=1.0 for Django 3.0 support (Matt Westcott) + * Revise tests to ensure all pass in Django 3.0 (Matt Westcott) diff --git a/wagtail/admin/tests/test_account_management.py b/wagtail/admin/tests/test_account_management.py index 5473689c8..cda84aef1 100644 --- a/wagtail/admin/tests/test_account_management.py +++ b/wagtail/admin/tests/test_account_management.py @@ -3,6 +3,7 @@ import tempfile import pytz +from django import VERSION as DJANGO_VERSION 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 @@ -309,7 +310,10 @@ class TestAccountSection(TestCase, WagtailTestUtils): # Check that a validation error was raised self.assertTrue('new_password2' in response.context['form'].errors.keys()) - self.assertTrue("The two password fields didn't match." in response.context['form'].errors['new_password2']) + if DJANGO_VERSION >= (3, 0): + self.assertTrue("The two password fields didn’t match." in response.context['form'].errors['new_password2']) + else: + self.assertTrue("The two password fields didn't match." in response.context['form'].errors['new_password2']) # Check that the password was not changed self.assertTrue(get_user_model().objects.get(pk=self.user.pk).check_password('password')) @@ -692,7 +696,12 @@ class TestPasswordReset(TestCase, WagtailTestUtils): self.password_reset_uid = force_text(urlsafe_base64_encode(force_bytes(self.user.pk))) # Create url_args - self.url_kwargs = dict(uidb64=self.password_reset_uid, token=auth_views.INTERNAL_RESET_URL_TOKEN) + if DJANGO_VERSION >= (3, 0): + token = auth_views.PasswordResetConfirmView.reset_url_token + else: + token = auth_views.INTERNAL_RESET_URL_TOKEN + + self.url_kwargs = dict(uidb64=self.password_reset_uid, token=token) # Add token to session object s = self.client.session @@ -772,7 +781,11 @@ class TestPasswordReset(TestCase, WagtailTestUtils): # Check that a validation error was raised self.assertTrue('new_password2' in response.context['form'].errors.keys()) - self.assertTrue("The two password fields didn't match." in response.context['form'].errors['new_password2']) + + if DJANGO_VERSION >= (3, 0): + self.assertTrue("The two password fields didn’t match." in response.context['form'].errors['new_password2']) + else: + self.assertTrue("The two password fields didn't match." in response.context['form'].errors['new_password2']) # Check that the password was not changed self.assertTrue(get_user_model().objects.get(username='test').check_password('password')) diff --git a/wagtail/admin/tests/test_pages_views.py b/wagtail/admin/tests/test_pages_views.py index 99b78d856..32354063c 100644 --- a/wagtail/admin/tests/test_pages_views.py +++ b/wagtail/admin/tests/test_pages_views.py @@ -4,6 +4,7 @@ import os from itertools import chain from unittest import mock +from django import VERSION as DJANGO_VERSION from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission @@ -1916,7 +1917,7 @@ class TestPageEdit(TestCase, WagtailTestUtils): # Check the HTML response self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'tests/simple_page.html') - self.assertContains(response, "I've been edited!") + self.assertContains(response, "I've been edited!", html=True) def test_preview_on_edit_no_session_key(self): preview_url = reverse('wagtailadmin_pages:preview_on_edit', @@ -3002,9 +3003,14 @@ class TestPageCopy(TestCase, WagtailTestUtils): self.assertEqual(response.status_code, 200) # Check that a form error was raised - self.assertFormError( - response, 'form', 'new_slug', "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens." - ) + if DJANGO_VERSION >= (3, 0): + self.assertFormError( + response, 'form', 'new_slug', "Enter a valid “slug” consisting of letters, numbers, underscores or hyphens." + ) + else: + self.assertFormError( + response, 'form', 'new_slug', "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens." + ) def test_page_copy_no_publish_permission(self): # Turn user into an editor who can add pages but not publish them @@ -4354,7 +4360,11 @@ class TestCompareRevisions(TestCase, WagtailTestUtils): response = self.client.get(compare_url) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll give it to someone special') + self.assertContains( + response, + 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll give it to someone special', + html=True + ) def test_compare_revisions_earliest(self): compare_url = reverse( @@ -4364,7 +4374,11 @@ class TestCompareRevisions(TestCase, WagtailTestUtils): response = self.client.get(compare_url) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll give it to someone special') + self.assertContains( + response, + 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll give it to someone special', + html=True + ) def test_compare_revisions_latest(self): compare_url = reverse( @@ -4374,7 +4388,11 @@ class TestCompareRevisions(TestCase, WagtailTestUtils): response = self.client.get(compare_url) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll give it to someone special') + self.assertContains( + response, + 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll give it to someone special', + html=True + ) def test_compare_revisions_live(self): # Mess with the live version, bypassing revisions @@ -4391,7 +4409,11 @@ class TestCompareRevisions(TestCase, WagtailTestUtils): response = self.client.get(compare_url) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll just feed it to the dog') + self.assertContains( + response, + 'Last Christmas I gave you my heart, but the very next day you gave it awayThis year, to save me from tears, I'll just feed it to the dog', + html=True + ) class TestCompareRevisionsWithNonModelField(TestCase, WagtailTestUtils): diff --git a/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py b/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py index 966912455..ec2ac4c4c 100644 --- a/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py +++ b/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py @@ -1,3 +1,4 @@ +from django import VERSION as DJANGO_VERSION from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.test import TestCase @@ -65,13 +66,21 @@ class TestExcludeFromExplorer(TestCase, WagtailTestUtils): def test_attribute_effects_explorer(self): # The two VenuePages should appear in the venuepage list response = self.client.get('/admin/modeladmintest/venuepage/') - self.assertContains(response, "Santa's Grotto") - self.assertContains(response, "Santa's Workshop") + if DJANGO_VERSION >= (3, 0): + self.assertContains(response, "Santa's Grotto") + self.assertContains(response, "Santa's Workshop") + else: + self.assertContains(response, "Santa's Grotto") + self.assertContains(response, "Santa's Workshop") # But when viewing the children of 'Christmas' event in explorer response = self.client.get('/admin/pages/4/') - self.assertNotContains(response, "Santa's Grotto") - self.assertNotContains(response, "Santa's Workshop") + if DJANGO_VERSION >= (3, 0): + self.assertNotContains(response, "Santa's Grotto") + self.assertNotContains(response, "Santa's Workshop") + else: + self.assertNotContains(response, "Santa's Grotto") + self.assertNotContains(response, "Santa's Workshop") # But the other test page should... self.assertContains(response, "Claim your free present!")