Explorar el Código

Fix failing tests due to different HTML escaping in Django 3.0

- Fix password reset tests
- Fix test for invalid-slug message
- Update changelog/release notes
Matt Westcott hace 5 años
padre
commit
dc780c5bb1

+ 1 - 0
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)

+ 1 - 0
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)
 
 
 

+ 16 - 3
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'))

+ 30 - 8
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, '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll give it to someone special</span>')
+        self.assertContains(
+            response,
+            '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll give it to someone special</span>',
+            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, '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll give it to someone special</span>')
+        self.assertContains(
+            response,
+            '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll give it to someone special</span>',
+            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, '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll give it to someone special</span>')
+        self.assertContains(
+            response,
+            '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll give it to someone special</span>',
+            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, '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll just feed it to the dog</span>')
+        self.assertContains(
+            response,
+            '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll just feed it to the dog</span>',
+            html=True
+        )
 
 
 class TestCompareRevisionsWithNonModelField(TestCase, WagtailTestUtils):

+ 13 - 4
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&#39;s Grotto")
-        self.assertContains(response, "Santa&#39;s Workshop")
+        if DJANGO_VERSION >= (3, 0):
+            self.assertContains(response, "Santa&#x27;s Grotto")
+            self.assertContains(response, "Santa&#x27;s Workshop")
+        else:
+            self.assertContains(response, "Santa&#39;s Grotto")
+            self.assertContains(response, "Santa&#39;s Workshop")
 
         # But when viewing the children of 'Christmas' event in explorer
         response = self.client.get('/admin/pages/4/')
-        self.assertNotContains(response, "Santa&#39;s Grotto")
-        self.assertNotContains(response, "Santa&#39;s Workshop")
+        if DJANGO_VERSION >= (3, 0):
+            self.assertNotContains(response, "Santa&#x27;s Grotto")
+            self.assertNotContains(response, "Santa&#x27;s Workshop")
+        else:
+            self.assertNotContains(response, "Santa&#39;s Grotto")
+            self.assertNotContains(response, "Santa&#39;s Workshop")
 
         # But the other test page should...
         self.assertContains(response, "Claim your free present!")