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)
Example #2
0
from flask.ext import restful
from werkzeug.contrib.fixers import ProxyFix
from popsapi.models.pops import *
from popsapi.components.common import logger, cfg
from popsapi.resources import EnvironmentResource, QueueResource, TaskResource, SlackResource, SlackCommandResource

try:
    app = Flask(__name__)

    app.config["MONGODB_SETTINGS"] = {
        "db": cfg["mongo"]["name"],
        "host": cfg["mongo"]["host"],
        "port": cfg["mongo"]["port"],
    }

    app.config["BUNDLE_ERRORS"] = True

    db.init_app(app)

    api = restful.Api(app)
    # load endpoints
    # Environment
    environment_endpoints = ["/%s/environment/<target_environment>" % os.environ["POPS_VERSION"]]
    api.add_resource(EnvironmentResource, *environment_endpoints)

    # Queue
    queue_endpoints = ["/%s/queue/<target_environment>" % os.environ["POPS_VERSION"]]
    api.add_resource(QueueResource, *queue_endpoints)

    # Tasks
    task_endpoints = ["/%s/task/<target_environment>" % os.environ["POPS_VERSION"]]