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 ``` '<p>\n Go to http://www.plone.org\n</p>' != '<p>Go to http://www.plone.org</p>' - <p> - Go to http://www.plone.org ? ^ ^ + <p>Go to http://www.plone.org</p>? ^^^ ^^^^ - </p> 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) ```
This commit is contained in:
parent
93f92fadcd
commit
266d87b3b9
3
news/49.bugfix
Normal file
3
news/49.bugfix
Normal file
@ -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]
|
@ -18,6 +18,22 @@ logger = logging.getLogger("plone.app.discussion.tests")
|
|||||||
logger.addHandler(logging.StreamHandler())
|
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 to<a href' instead of 'Go to <a href'.
|
||||||
|
lines = []
|
||||||
|
for line in value.splitlines():
|
||||||
|
line = line.strip()
|
||||||
|
if (
|
||||||
|
line.startswith("<")
|
||||||
|
and not line.startswith("</")
|
||||||
|
and not line.startswith("<br")
|
||||||
|
):
|
||||||
|
line = " " + line
|
||||||
|
lines.append(line)
|
||||||
|
return "".join(lines).strip()
|
||||||
|
|
||||||
|
|
||||||
class CommentTest(unittest.TestCase):
|
class CommentTest(unittest.TestCase):
|
||||||
|
|
||||||
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
@ -156,7 +172,7 @@ class CommentTest(unittest.TestCase):
|
|||||||
comment1 = createObject("plone.Comment")
|
comment1 = createObject("plone.Comment")
|
||||||
comment1.text = "First paragraph\n\nSecond_paragraph"
|
comment1.text = "First paragraph\n\nSecond_paragraph"
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"".join(comment1.getText().split()),
|
normalize(comment1.getText()),
|
||||||
"<p>First paragraph<br><br>Second_paragraph</p>",
|
"<p>First paragraph<br><br>Second_paragraph</p>",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -164,7 +180,7 @@ class CommentTest(unittest.TestCase):
|
|||||||
comment1 = createObject("plone.Comment")
|
comment1 = createObject("plone.Comment")
|
||||||
comment1.text = "<b>Got HTML?</b>"
|
comment1.text = "<b>Got HTML?</b>"
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
comment1.getText(),
|
normalize(comment1.getText()),
|
||||||
"<p><b>Got HTML?</b></p>",
|
"<p><b>Got HTML?</b></p>",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -172,13 +188,13 @@ class CommentTest(unittest.TestCase):
|
|||||||
comment1 = createObject("plone.Comment")
|
comment1 = createObject("plone.Comment")
|
||||||
comment1.text = "Umlaute sind ä, ö und ü."
|
comment1.text = "Umlaute sind ä, ö und ü."
|
||||||
out = b"<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>"
|
out = b"<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>"
|
||||||
self.assertEqual(comment1.getText(), out.decode("utf8"))
|
self.assertEqual(normalize(comment1.getText()), out.decode("utf8"))
|
||||||
|
|
||||||
def test_getText_doesnt_link(self):
|
def test_getText_doesnt_link(self):
|
||||||
comment1 = createObject("plone.Comment")
|
comment1 = createObject("plone.Comment")
|
||||||
comment1.text = "Go to http://www.plone.org"
|
comment1.text = "Go to http://www.plone.org"
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
comment1.getText(),
|
normalize(comment1.getText()),
|
||||||
"<p>Go to http://www.plone.org</p>",
|
"<p>Go to http://www.plone.org</p>",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -187,7 +203,7 @@ class CommentTest(unittest.TestCase):
|
|||||||
comment1.text = "Go to http://www.plone.org"
|
comment1.text = "Go to http://www.plone.org"
|
||||||
comment1.mime_type = "text/x-web-intelligent"
|
comment1.mime_type = "text/x-web-intelligent"
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
comment1.getText(),
|
normalize(comment1.getText()),
|
||||||
'Go to <a href="http://www.plone.org" '
|
'Go to <a href="http://www.plone.org" '
|
||||||
+ 'rel="nofollow">http://www.plone.org</a>',
|
+ 'rel="nofollow">http://www.plone.org</a>',
|
||||||
)
|
)
|
||||||
@ -197,7 +213,7 @@ class CommentTest(unittest.TestCase):
|
|||||||
comment1.text = 'Go to <a href="http://www.plone.org">plone.org</a>'
|
comment1.text = 'Go to <a href="http://www.plone.org">plone.org</a>'
|
||||||
comment1.mime_type = "text/html"
|
comment1.mime_type = "text/html"
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
comment1.getText(),
|
normalize(comment1.getText()),
|
||||||
'Go to <a href="http://www.plone.org">plone.org</a>',
|
'Go to <a href="http://www.plone.org">plone.org</a>',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user