コード例 #1
0
ファイル: test_validate.py プロジェクト: zoown13/chalice
    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)
コード例 #2
0
ファイル: test_validate.py プロジェクト: zoown13/chalice
    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.')
コード例 #3
0
ファイル: test_validate.py プロジェクト: abhilash1in/chalice
    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.'
            )
コード例 #4
0
ファイル: test_validate.py プロジェクト: abhilash1in/chalice
    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)
コード例 #5
0
ファイル: __init__.py プロジェクト: zhongqiliang/chalice
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
コード例 #6
0
ファイル: __init__.py プロジェクト: crazy-penguins/parfait
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
コード例 #7
0
ファイル: __init__.py プロジェクト: awslabs/chalice
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
コード例 #8
0
ファイル: test_validate.py プロジェクト: zoown13/chalice
    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.')
コード例 #9
0
ファイル: test_validate.py プロジェクト: zoown13/chalice
    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.')
コード例 #10
0
ファイル: test_validate.py プロジェクト: zoown13/chalice
    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)
コード例 #11
0
ファイル: test_validate.py プロジェクト: abhilash1in/chalice
    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.'
            )
コード例 #12
0
ファイル: test_validate.py プロジェクト: abhilash1in/chalice
    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.'
            )
コード例 #13
0
ファイル: __init__.py プロジェクト: npellegrin/chalice
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()
コード例 #14
0
ファイル: test_validate.py プロジェクト: abhilash1in/chalice
    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)
コード例 #15
0
ファイル: __init__.py プロジェクト: hyandell/chalice
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()
コード例 #16
0
ファイル: __init__.py プロジェクト: jamesls/chalice
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()