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='')
| 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 |