[v2,1/2,PW3] tests: Fix escaping in bundle tests on Django 3.0
diff mbox series

Message ID 20191024032639.14707-1-ajd@linux.ibm.com
State New
Headers show
Series
  • [v2,1/2,PW3] tests: Fix escaping in bundle tests on Django 3.0
Related show

Commit Message

Andrew Donnellan Oct. 24, 2019, 3:26 a.m. UTC
Django 3.0 switches to using Python 3's built-in HTML escaper, which
prefers to escape entities using hex rather than decimal.

Some of our tests check rendered HTML output against pre-escaped strings,
and fail because ''' is now '''.

Fix this by using the escape function so we get consistent escaping no
matter which Django version..

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
---
 patchwork/tests/test_bundles.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py
index 63f943c033d6..c5e7ee62f435 100644
--- a/patchwork/tests/test_bundles.py
+++ b/patchwork/tests/test_bundles.py
@@ -10,6 +10,7 @@  import unittest
 from django.conf import settings
 from django.test import TestCase
 from django.urls import reverse
+from django.utils.html import escape
 from django.utils.http import urlencode
 
 from patchwork.models import Bundle
@@ -548,8 +549,8 @@  class BundleAddFromListTest(BundleTestBase):
                 'project_id': self.project.linkname}),
             params)
 
-        self.assertContains(response, 'Patch &#39;%s&#39; already in bundle'
-                            % patch.name, count=1, status_code=200)
+        expected = escape(f"Patch '{patch.name}' already in bundle")
+        self.assertContains(response, expected, count=1, status_code=200)
 
         self.assertEqual(count, self.bundle.patches.count())
 
@@ -570,11 +571,12 @@  class BundleAddFromListTest(BundleTestBase):
                 'project_id': self.project.linkname}),
             params)
 
-        self.assertContains(response, 'Patch &#39;%s&#39; already in bundle'
-                            % patch.name, count=1, status_code=200)
-        self.assertContains(response, 'Patch &#39;%s&#39; added to bundle'
-                            % self.patches[1].name, count=1,
+        expected_already = escape(f"Patch '{patch.name}' already in bundle")
+        expected_added = escape(
+            f"Patch '{self.patches[1].name}' added to bundle")
+        self.assertContains(response, expected_already, count=1,
                             status_code=200)
+        self.assertContains(response, expected_added, count=1, status_code=200)
         self.assertEqual(count + 1, self.bundle.patches.count())