def test_trapping_of_all_http_exceptions(): app = Flak(__name__) app.testing = True app.config['TRAP_HTTP_EXCEPTIONS'] = True @app.route('/fail') def fail(cx): flak.abort(404) c = app.test_client() with pytest.raises(NotFound): c.get('/fail')
def test_trapping_of_bad_request_key_errors(): app = Flak(__name__) app.testing = True @app.route('/fail') def fail(cx): cx.request.form['missing_key'] c = app.test_client() assert c.get('/fail').status_code == 400 app.config['TRAP_BAD_REQUEST_ERRORS'] = True c = app.test_client() try: c.get('/fail') except KeyError as e: assert isinstance(e, BadRequest) else: assert False, 'Expected exception'