def test_parse_error_bundling_w_parser_arg(self): app = Flask(__name__) app.config["BUNDLE_ERRORS"] = False with app.app_context(): req = Request.from_values("/bubble") parser = RequestParser(bundle_errors=True) parser.add_argument("foo", required=True, location="values") parser.add_argument("bar", required=True, location=["values", "cookies"]) message = "" try: parser.parse_args(req) except exceptions.BadRequest as e: message = e.data["message"] error_message = { "foo": "Missing required parameter in the post " "body or the query string", "bar": "Missing required parameter in the post " "body or the query string or the request's " "cookies", } self.assertEquals(message, error_message)
from myhvac_service.wsgi import system import logging LOG = logging.getLogger(__name__) opts = [ cfg.BoolOpt("debug", default=False, help="Enables debug mode for the flask rest api"), cfg.IntOpt("port", default=8080, help="Http port of the webserver"), ] CONF = cfg.CONF CONF.register_opts(opts, "rest_api") app = Flask(__name__) app.config["BUNDLE_ERRORS"] = True api = Api(app) api.add_resource(sensors.Sensors, "/sensors") api.add_resource(sensors.Sensor, "/sensors/<sensor_id>") api.add_resource(measurements.SensorTempuratures, "/sensors/<sensor_id>/measurements/temperatures") api.add_resource(measurements.SensorMeasurements, "/sensors/<sensor_id>/measurements") api.add_resource(system.SystemState, "/system/state") api.add_resource(system.SystemPing, "/system/ping") def run(): LOG.info("Starting web server...") LOG.debug("Enable flask debug: %s", CONF.rest_api.debug) LOG.debug("Enable port: %s", CONF.rest_api.port)