Skip to content

Commit

Permalink
Increase test coverage and extend the fix for #829 also for the WSGI (#…
Browse files Browse the repository at this point in the history
…833)

publisher
  • Loading branch information
ale-rt committed May 17, 2020
1 parent e952da1 commit 2182f1e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/ZPublisher/HTTPResponse.py
Expand Up @@ -782,7 +782,7 @@ def debugError(self, entry):
"Debugging Notice",
(
"Zope has encountered a problem publishing your object. "
"<p>%r</p>" % entry
"<p>%s</p>" % repr(entry)
)
))

Expand Down Expand Up @@ -950,8 +950,9 @@ def debugError(self, entry):
exc = NotFound(entry)
exc.title = 'Debugging Notice'
exc.detail = (
'Zope has encountered a problem publishing your object.<p>'
'\n%s</p>' % entry)
"Zope has encountered a problem publishing your object. "
"<p>%s</p>" % repr(entry)
)
raise exc

def badRequestError(self, name):
Expand Down
26 changes: 24 additions & 2 deletions src/ZPublisher/tests/testHTTPResponse.py
Expand Up @@ -872,8 +872,30 @@ def test_debugError(self):
response.debugError('testing')
except NotFound as raised:
self.assertEqual(response.status, 200)
self.assertTrue("Zope has encountered a problem publishing "
"your object. <p>'testing'</p>" in str(raised))
self.assertIn(
"Zope has encountered a problem publishing your object. <p>'testing'</p>", # noqa: E501
str(raised),
)
else:
self.fail("Didn't raise NotFound")
try:
response.debugError(("testing",))
except NotFound as raised:
self.assertEqual(response.status, 200)
self.assertIn(
"Zope has encountered a problem publishing your object. <p>(\'testing\',)</p>", # noqa: E501
str(raised),
)
else:
self.fail("Didn't raise NotFound")
try:
response.debugError(("foo", "bar"))
except NotFound as raised:
self.assertEqual(response.status, 200)
self.assertIn(
"Zope has encountered a problem publishing your object. <p>(\'foo\', \'bar\')</p>", # noqa: E501
str(raised),
)
else:
self.fail("Didn't raise NotFound")

Expand Down
34 changes: 34 additions & 0 deletions src/ZPublisher/tests/test_WSGIPublisher.py
Expand Up @@ -19,6 +19,7 @@
from Testing.ZopeTestCase import FunctionalTestCase
from Testing.ZopeTestCase import ZopeTestCase
from Testing.ZopeTestCase import user_name
from zExceptions import NotFound
from ZODB.POSException import ConflictError
from zope.interface.common.interfaces import IException
from zope.publisher.interfaces import INotFound
Expand Down Expand Up @@ -172,6 +173,39 @@ def test_exception_calls_unauthorized(self):
response.exception(info=(Unauthorized, Unauthorized('fail'), None))
self.assertEqual(_unauthorized._called_with, ((), {}))

def test_debugError(self):
response = self._makeOne()
try:
response.debugError('testing')
except NotFound as raised:
self.assertEqual(response.status, 404)
self.assertIn(
"Zope has encountered a problem publishing your object. <p>'testing'</p>", # noqa: E501
raised.detail,
)
else:
self.fail("Didn't raise NotFound")
try:
response.debugError(("testing",))
except NotFound as raised:
self.assertEqual(response.status, 404)
self.assertIn(
"Zope has encountered a problem publishing your object. <p>(\'testing\',)</p>", # noqa: E501
raised.detail,
)
else:
self.fail("Didn't raise NotFound")
try:
response.debugError(("foo", "bar"))
except NotFound as raised:
self.assertEqual(response.status, 404)
self.assertIn(
"Zope has encountered a problem publishing your object. <p>(\'foo\', \'bar\')</p>", # noqa: E501
raised.detail,
)
else:
self.fail("Didn't raise NotFound")


class TestPublish(unittest.TestCase):

Expand Down

0 comments on commit 2182f1e

Please sign in to comment.