From 266d87b3b92a4d08765e6a92020029eefad43153 Mon Sep 17 00:00:00 2001
From: Maurits van Rees
Date: Fri, 10 Jun 2022 13:50:16 +0200
Subject: [PATCH] Test-only fix: normalize white space when comparing output of
comment.getText().
Needed to not fail with newer `plone.outputfilters` from this PR: https://github.com/plone/plone.outputfilters/pull/49
Comments go through the outputfilters, and the new branch calls `soup.prettify()` from `Beautifulsoup`, leading to more white space.
Sample test failures on Jenkins, see https://jenkins.plone.org/job/plip-plip-image-srcsets-3.8/5/#showFailuresLink
```
'\n Go to http://www.plone.org\n
' != 'Go to http://www.plone.org
'
-
- Go to http://www.plone.org
? ^ ^
+
Go to http://www.plone.org
? ^^^ ^^^^
-
File "/srv/python3.8/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
yield
File "/srv/python3.8/lib/python3.8/unittest/case.py", line 676, in run
self._callTestMethod(testMethod)
File "/srv/python3.8/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
method()
File "/home/jenkins/.buildout/eggs/cp38/plone.app.discussion-4.0.0a7-py3.8.egg/plone/app/discussion/tests/test_comment.py", line 180, in test_getText_doesnt_link
self.assertEqual(
File "/srv/python3.8/lib/python3.8/unittest/case.py", line 912, in assertEqual
assertion_func(first, second, msg=msg)
File "/srv/python3.8/lib/python3.8/unittest/case.py", line 1292, in assertMultiLineEqual
self.fail(self._formatMessage(msg, standardMsg))
File "/srv/python3.8/lib/python3.8/unittest/case.py", line 753, in fail
raise self.failureException(msg)
```
---
news/49.bugfix | 3 +++
plone/app/discussion/tests/test_comment.py | 30 +++++++++++++++++-----
2 files changed, 26 insertions(+), 7 deletions(-)
create mode 100644 news/49.bugfix
diff --git a/news/49.bugfix b/news/49.bugfix
new file mode 100644
index 0000000..99c8263
--- /dev/null
+++ b/news/49.bugfix
@@ -0,0 +1,3 @@
+Test-only fix: normalize white space when comparing output of ``comment.getText()``.
+Needed to not fail with newer ``plone.outputfilters``.
+[maurits]
diff --git a/plone/app/discussion/tests/test_comment.py b/plone/app/discussion/tests/test_comment.py
index 17bcb64..a0a0669 100644
--- a/plone/app/discussion/tests/test_comment.py
+++ b/plone/app/discussion/tests/test_comment.py
@@ -18,6 +18,22 @@ logger = logging.getLogger("plone.app.discussion.tests")
logger.addHandler(logging.StreamHandler())
+def normalize(value):
+ # Strip all white spaces of every line, then join on one line.
+ # But try to avoid getting 'Go toFirstparagraph
Second_paragraph",
+ normalize(comment1.getText()),
+ "First paragraph
Second_paragraph
",
)
def test_getText_escapes_HTML(self):
comment1 = createObject("plone.Comment")
comment1.text = "Got HTML?"
self.assertEqual(
- comment1.getText(),
+ normalize(comment1.getText()),
"<b>Got HTML?</b>
",
)
@@ -172,13 +188,13 @@ class CommentTest(unittest.TestCase):
comment1 = createObject("plone.Comment")
comment1.text = "Umlaute sind ä, ö und ü."
out = b"Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.
"
- self.assertEqual(comment1.getText(), out.decode("utf8"))
+ self.assertEqual(normalize(comment1.getText()), out.decode("utf8"))
def test_getText_doesnt_link(self):
comment1 = createObject("plone.Comment")
comment1.text = "Go to http://www.plone.org"
self.assertEqual(
- comment1.getText(),
+ normalize(comment1.getText()),
"Go to http://www.plone.org
",
)
@@ -187,7 +203,7 @@ class CommentTest(unittest.TestCase):
comment1.text = "Go to http://www.plone.org"
comment1.mime_type = "text/x-web-intelligent"
self.assertEqual(
- comment1.getText(),
+ normalize(comment1.getText()),
'Go to http://www.plone.org',
)
@@ -197,7 +213,7 @@ class CommentTest(unittest.TestCase):
comment1.text = 'Go to plone.org'
comment1.mime_type = "text/html"
self.assertEqual(
- comment1.getText(),
+ normalize(comment1.getText()),
'Go to plone.org',
)