def test_all_errors_email(self): """Should send me email on *any* error from create() or preview_create().""" for i in range(2): self.expect_requests_get('http://foo.com/bar', self.post_html % 'foo') self.mox.StubOutWithMock(mail, 'send_mail') for subject in ('WebmentionHandler None failed: None (FakeSource)', 'PreviewHandler preview new: None (FakeSource)'): mail.send_mail(subject=subject, body=mox.IgnoreArg(), sender=mox.IgnoreArg(), to=mox.IgnoreArg()) self.mox.StubOutWithMock(self.source.gr_source, 'create', use_mock_anything=True) self.source.gr_source.create(mox.IgnoreArg(), include_link=gr_source.INCLUDE_LINK, ignore_formatting=False).AndRaise( exc.HTTPPaymentRequired('fooey')) self.mox.StubOutWithMock(self.source.gr_source, 'preview_create', use_mock_anything=True) self.source.gr_source.preview_create( mox.IgnoreArg(), include_link=gr_source.INCLUDE_LINK, ignore_formatting=False).AndRaise(Exception('bar')) self.mox.ReplayAll() self.assert_error('fooey', status=402) self.assertEquals(500, self.get_response(preview=True).status_int)
def test_create_comment_exception(self): self.expect_mention().AndRaise(exc.HTTPPaymentRequired()) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(402, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(self.mention_html, bw.html)
def code2exception(code, detail): """Transforms a code + detail into a WebOb exception""" if code == 400: return exc.HTTPBadRequest(detail) if code == 401: return exc.HTTPUnauthorized(detail) if code == 402: return exc.HTTPPaymentRequired(detail) if code == 403: return exc.HTTPForbidden(detail) if code == 404: return exc.HTTPNotFound(detail) if code == 405: return exc.HTTPMethodNotAllowed(detail) if code == 406: return exc.HTTPNotAcceptable(detail) if code == 407: return exc.HTTPProxyAuthenticationRequired(detail) if code == 408: return exc.HTTPRequestTimeout(detail) if code == 409: return exc.HTTPConflict(detail) if code == 410: return exc.HTTPGone(detail) if code == 411: return exc.HTTPLengthRequired(detail) if code == 412: return exc.HTTPPreconditionFailed(detail) if code == 413: return exc.HTTPRequestEntityTooLarge(detail) if code == 414: return exc.HTTPRequestURITooLong(detail) if code == 415: return exc.HTTPUnsupportedMediaType(detail) if code == 416: return exc.HTTPRequestRangeNotSatisfiable(detail) if code == 417: return exc.HTTPExpectationFailed(detail) if code == 500: return exc.HTTPInternalServerError(detail) if code == 501: return exc.HTTPNotImplemented(detail) if code == 502: return exc.HTTPBadGateway(detail) if code == 503: return exc.HTTPServiceUnavailable(detail) if code == 504: return exc.HTTPGatewayTimeout(detail) if code == 505: return exc.HTTPVersionNotSupported(detail) raise NotImplementedError(code)