def test_cant_have_options_with_cors(self, sample_app): @sample_app.route('/badcors', methods=['GET', 'OPTIONS'], cors=True) def badview(): pass with pytest.raises(ValueError): validate_routes(sample_app.routes)
def test_can_have_same_custom_cors_configurations(self, sample_app): custom_cors = CORSConfig(allow_origin='https://foo.example.com', allow_headers=['X-Special-Header'], max_age=600, expose_headers=['X-Special-Header'], allow_credentials=True) @sample_app.route('/cors', methods=['GET'], cors=custom_cors) def cors(): pass same_custom_cors = CORSConfig(allow_origin='https://foo.example.com', allow_headers=['X-Special-Header'], max_age=600, expose_headers=['X-Special-Header'], allow_credentials=True) @sample_app.route('/cors', methods=['PUT'], cors=same_custom_cors) def same_cors(): pass try: validate_routes(sample_app.routes) except ValueError: pytest.fail('A ValueError was unexpectedly thrown. Applications ' 'may have multiple view functions that share the same ' 'route and CORS configuration.')
def test_can_have_same_custom_cors_configurations(self, sample_app): custom_cors = CORSConfig( allow_origin='https://foo.example.com', allow_headers=['X-Special-Header'], max_age=600, expose_headers=['X-Special-Header'], allow_credentials=True ) @sample_app.route('/cors', methods=['GET'], cors=custom_cors) def cors(): pass same_custom_cors = CORSConfig( allow_origin='https://foo.example.com', allow_headers=['X-Special-Header'], max_age=600, expose_headers=['X-Special-Header'], allow_credentials=True ) @sample_app.route('/cors', methods=['PUT'], cors=same_custom_cors) def same_cors(): pass try: validate_routes(sample_app.routes) except ValueError: pytest.fail( 'A ValueError was unexpectedly thrown. Applications ' 'may have multiple view functions that share the same ' 'route and CORS configuration.' )
def create_local_server(factory, host, port, stage): # type: (CLIFactory, str, int, str) -> LocalDevServer config = factory.create_config_obj(chalice_stage_name=stage) app_obj = config.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) server = factory.create_local_server(app_obj, config, host, port) return server
def create_local_server(factory: CliFactory, host: str, port: int, stage: str) -> LocalDevServer: config = factory.create_config_obj(chalice_stage_name=stage) session = factory.create_botocore_session() LocalLayerDownloader(config, session) app_obj = config.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) server = factory.create_local_server(app_obj, config, host, port) return server
def create_local_server(factory, host, port, stage): # type: (CLIFactory, str, int, str) -> LocalDevServer config = factory.create_config_obj( chalice_stage_name=stage ) app_obj = config.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) server = factory.create_local_server(app_obj, config, host, port) return server
def test_can_have_one_cors_configured_and_others_not(self, sample_app): @sample_app.route('/cors', methods=['GET'], cors=True) def cors(): pass @sample_app.route('/cors', methods=['PUT']) def no_cors(): pass try: validate_routes(sample_app.routes) except ValueError: pytest.fail('A ValueError was unexpectedly thrown. Applications ' 'may have multiple view functions that share the same ' 'route but only one is configured for CORS.')
def test_can_have_same_cors_configurations(self, sample_app): @sample_app.route('/cors', methods=['GET'], cors=True) def cors(): pass @sample_app.route('/cors', methods=['PUT'], cors=True) def same_cors(): pass try: validate_routes(sample_app.routes) except ValueError: pytest.fail('A ValueError was unexpectedly thrown. Applications ' 'may have multiple view functions that share the same ' 'route and CORS configuration.')
def test_cant_have_differing_cors_configurations(self, sample_app): custom_cors = CORSConfig(allow_origin='https://foo.example.com', allow_headers=['X-Special-Header'], max_age=600, expose_headers=['X-Special-Header'], allow_credentials=True) @sample_app.route('/cors', methods=['GET'], cors=True) def cors(): pass @sample_app.route('/cors', methods=['PUT'], cors=custom_cors) def different_cors(): pass with pytest.raises(ValueError): validate_routes(sample_app.routes)
def test_can_have_one_cors_configured_and_others_not(self, sample_app): @sample_app.route('/cors', methods=['GET'], cors=True) def cors(): pass @sample_app.route('/cors', methods=['PUT']) def no_cors(): pass try: validate_routes(sample_app.routes) except ValueError: pytest.fail( 'A ValueError was unexpectedly thrown. Applications ' 'may have multiple view functions that share the same ' 'route but only one is configured for CORS.' )
def test_can_have_same_cors_configurations(self, sample_app): @sample_app.route('/cors', methods=['GET'], cors=True) def cors(): pass @sample_app.route('/cors', methods=['PUT'], cors=True) def same_cors(): pass try: validate_routes(sample_app.routes) except ValueError: pytest.fail( 'A ValueError was unexpectedly thrown. Applications ' 'may have multiple view functions that share the same ' 'route and CORS configuration.' )
def run_local_server(factory, host, port, stage): # type: (CLIFactory, str, int, str) -> None config = factory.create_config_obj( chalice_stage_name=stage ) app_obj = config.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()
def test_cant_have_differing_cors_configurations(self, sample_app): custom_cors = CORSConfig( allow_origin='https://foo.example.com', allow_headers=['X-Special-Header'], max_age=600, expose_headers=['X-Special-Header'], allow_credentials=True ) @sample_app.route('/cors', methods=['GET'], cors=True) def cors(): pass @sample_app.route('/cors', methods=['PUT'], cors=custom_cors) def different_cors(): pass with pytest.raises(ValueError): validate_routes(sample_app.routes)
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()
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()