Example #1
0
def test_cant_have_options_with_cors(sample_app):
    @sample_app.route('/badcors', methods=['GET', 'OPTIONS'], cors=True)
    def badview():
        pass

    with pytest.raises(ValueError):
        validate_routes(sample_app.routes)
Example #2
0
def run_local_server(factory, host, port, stage, env):
    # type: (CLIFactory, str, int, str, MutableMapping) -> None
    config = factory.create_config_obj(chalice_stage_name=stage)
    # We only load the chalice app after loading the config
    # so we can set any env vars needed before importing the
    # app.
    env.update(config.environment_variables)
    app_obj = factory.load_chalice_app()
    # Check that `chalice deploy` would let us deploy these routes, otherwise
    # there is no point in testing locally.
    routes = config.chalice_app.routes
    validate_routes(routes)
    # When running `chalice local`, a stdout logger is configured
    # so you'll see the same stdout logging as you would when
    # running in lambda.  This is configuring the root logger.
    # The app-specific logger (app.log) will still continue
    # to work.
    logging.basicConfig(stream=sys.stdout)
    server = factory.create_local_server(app_obj, config, host, port)
    server.serve_forever()