MCPcopy
hub / github.com/cherrypy/cherrypy / assertErrorPage

Method assertErrorPage

cherrypy/test/helper.py:318–352  ·  view source on GitHub ↗

Compare the response body with a built in error page. The function will optionally look for the regexp pattern, within the exception embedded in the error page.

(self, status, message=None, pattern='')

Source from the content-addressed store, hash-verified

316 pytest.skip(msg)
317
318 def assertErrorPage(self, status, message=None, pattern=''):
319 """Compare the response body with a built in error page.
320
321 The function will optionally look for the regexp pattern, within
322 the exception embedded in the error page.
323 """
324
325 # This will never contain a traceback
326 page = cherrypy._cperror.get_error_page(status, message=message)
327
328 # First, test the response body without checking the traceback.
329 # Stick a match-all group (.*) in to grab the traceback.
330 def esc(text):
331 return re.escape(ntob(text))
332 epage = re.escape(page)
333 epage = epage.replace(
334 esc('<pre id="traceback"></pre>'),
335 esc('<pre id="traceback">') + b'(.*)' + esc('</pre>'))
336 m = re.match(epage, self.body, re.DOTALL)
337 if not m:
338 self._handlewebError(
339 'Error page does not match; expected:\n' + page)
340 return
341
342 # Now test the pattern against the traceback
343 if pattern is None:
344 # Special-case None to mean that there should be *no* traceback.
345 if m and m.group(1):
346 self._handlewebError('Error page contains traceback')
347 else:
348 if (m is None) or (
349 not re.search(ntob(re.escape(pattern), self.encoding),
350 m.group(1))):
351 msg = 'Error page does not contain %s in traceback'
352 self._handlewebError(msg % repr(pattern))
353
354 date_tolerance = 2
355

Callers 15

testHookErrorsMethod · 0.80
testGuaranteedHooksMethod · 0.80
testErrorHandlingMethod · 0.80
testRefererMethod · 0.80
test_Accept_ToolMethod · 0.80
test_accept_selectionMethod · 0.80
test_5_Error_pathsMethod · 0.80
test_0_SessionMethod · 0.80
test_5_Error_pathsMethod · 0.80
test_decode_toolMethod · 0.80

Calls 2

ntobFunction · 0.90
get_error_pageMethod · 0.80

Tested by 15

testHookErrorsMethod · 0.64
testGuaranteedHooksMethod · 0.64
testErrorHandlingMethod · 0.64
testRefererMethod · 0.64
test_Accept_ToolMethod · 0.64
test_accept_selectionMethod · 0.64
test_5_Error_pathsMethod · 0.64
test_0_SessionMethod · 0.64
test_5_Error_pathsMethod · 0.64
test_decode_toolMethod · 0.64