Skip to content

Commit e2471e5

Browse files
ajdlinuxstephenfin
authored andcommitted
tests: Fix escaping in bundle tests on Django 3.0
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 '&#39;' is now '&#x27;'. Fix this by using the escape function so we get consistent escaping no matter which Django version. Signed-off-by: Andrew Donnellan <[email protected]> Reviewed-by: Stephen Finucane <[email protected]>
1 parent 801106e commit e2471e5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

patchwork/tests/test_bundles.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.conf import settings
1111
from django.test import TestCase
1212
from django.urls import reverse
13+
from django.utils.html import escape
1314
from django.utils.http import urlencode
1415

1516
from patchwork.models import Bundle
@@ -548,8 +549,8 @@ def test_add_duplicate(self):
548549
'project_id': self.project.linkname}),
549550
params)
550551

551-
self.assertContains(response, 'Patch &#39;%s&#39; already in bundle'
552-
% patch.name, count=1, status_code=200)
552+
expected = escape(f"Patch '{patch.name}' already in bundle")
553+
self.assertContains(response, expected, count=1, status_code=200)
553554

554555
self.assertEqual(count, self.bundle.patches.count())
555556

@@ -570,11 +571,12 @@ def test_add_new_and_duplicate(self):
570571
'project_id': self.project.linkname}),
571572
params)
572573

573-
self.assertContains(response, 'Patch &#39;%s&#39; already in bundle'
574-
% patch.name, count=1, status_code=200)
575-
self.assertContains(response, 'Patch &#39;%s&#39; added to bundle'
576-
% self.patches[1].name, count=1,
577-
status_code=200)
574+
for expected in (
575+
escape(f"Patch '{patch.name}' already in bundle"),
576+
escape(f"Patch '{self.patches[1].name}' added to bundle"),
577+
):
578+
self.assertContains(response, expected, count=1, status_code=200)
579+
578580
self.assertEqual(count + 1, self.bundle.patches.count())
579581

580582

0 commit comments

Comments
 (0)