MCPcopy
hub / github.com/cherrypy/cherrypy / testErrorHandling

Method testErrorHandling

cherrypy/test/test_request_obj.py:551–628  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

549 self.assertTrue('Client Error', self.body)
550
551 def testErrorHandling(self):
552 self.getPage('/error/missing')
553 self.assertStatus(404)
554 self.assertErrorPage(404, "The path '/error/missing' was not found.")
555
556 ignore = helper.webtest.ignored_exceptions
557 ignore.append(ValueError)
558 try:
559 valerr = '\n raise ValueError()\nValueError'
560 self.getPage('/error/page_method')
561 self.assertErrorPage(500, pattern=valerr)
562
563 self.getPage('/error/page_yield')
564 self.assertErrorPage(500, pattern=valerr)
565
566 if (cherrypy.server.protocol_version == 'HTTP/1.0' or
567 getattr(cherrypy.server, 'using_apache', False)):
568 self.getPage('/error/page_streamed')
569 # Because this error is raised after the response body has
570 # started, the status should not change to an error status.
571 self.assertStatus(200)
572 self.assertBody('word up')
573 else:
574 # Under HTTP/1.1, the chunked transfer-coding is used.
575 # The HTTP client will choke when the output is incomplete.
576 self.assertRaises((ValueError, IncompleteRead), self.getPage,
577 '/error/page_streamed')
578
579 # No traceback should be present
580 self.getPage('/error/cause_err_in_finalize')
581 msg = "Illegal response status from server ('ZOO' is non-numeric)."
582 self.assertErrorPage(500, msg, None)
583 finally:
584 ignore.pop()
585
586 # Test HTTPError with a reason-phrase in the status arg.
587 self.getPage('/error/reason_phrase')
588 self.assertStatus("410 Gone fishin'")
589
590 # Test custom error page for a specific error.
591 self.getPage('/error/custom')
592 self.assertStatus(404)
593 self.assertBody('Hello, world\r\n' + (' ' * 499))
594
595 # Test custom error page for a specific error.
596 self.getPage('/error/custom?err=401')
597 self.assertStatus(401)
598 self.assertBody(
599 'Error 401 Unauthorized - '
600 "Well, I'm very sorry but you haven't paid!")
601
602 # Test default custom error page.
603 self.getPage('/error/custom_default')
604 self.assertStatus(500)
605 self.assertBody(
606 'Error 500 Internal Server Error - '
607 "Well, I'm very sorry but you haven't paid!".ljust(513))
608

Callers

nothing calls this directly

Calls 3

getPageMethod · 0.80
assertErrorPageMethod · 0.80
popMethod · 0.80

Tested by

no test coverage detected