Exemplo n.º 1
0
def _deploy_app(temp_dirname):
    factory = CLIFactory(temp_dirname)
    config = factory.create_config_obj(
        chalice_stage_name='dev',
        autogen_policy=True
    )
    d = factory.create_default_deployer(
        factory.create_botocore_session(), None)
    deployed_stages = _deploy_with_retries(d, config)
    deployed = deployed_stages['dev']
    url = (
        "https://{rest_api_id}.execute-api.{region}.amazonaws.com/"
        "{api_gateway_stage}/".format(**deployed))
    application = SmokeTestApplication(
        url=url,
        deployed_values=deployed,
        stage_name='dev',
        app_name='smoketestapp',
        app_dir=temp_dirname,
    )
    record_deployed_values(
        deployed_stages,
        os.path.join(temp_dirname, '.chalice', 'deployed.json')
    )
    return application
Exemplo n.º 2
0
def _delete_app(application, temp_dirname):
    factory = CLIFactory(temp_dirname)
    config = factory.create_config_obj(chalice_stage_name='dev',
                                       autogen_policy=True)
    session = factory.create_botocore_session()
    d = factory.create_deletion_deployer(session, UI())
    _deploy_with_retries(d, config)
Exemplo n.º 3
0
def _deploy_app():
    if not os.path.isdir(CHALICE_DIR):
        os.makedirs(CHALICE_DIR)
    with open(os.path.join(CHALICE_DIR, 'config.json'), 'w') as f:
        f.write('{"app_name": "smoketestapp"}\n')
    factory = CLIFactory(PROJECT_DIR)
    config = factory.create_config_obj(
        chalice_stage_name='dev',
        autogen_policy=True
    )
    d = factory.create_default_deployer(
        factory.create_botocore_session(), None)
    deployed_stages = d.deploy(config)
    deployed = deployed_stages['dev']
    url = (
        "https://{rest_api_id}.execute-api.{region}.amazonaws.com/"
        "{api_gateway_stage}/".format(**deployed))
    application = SmokeTestApplication(
        url=url,
        deployed_values=deployed,
        stage_name='dev',
        app_name='smoketestapp',
    )
    record_deployed_values(deployed_stages, os.path.join(
        PROJECT_DIR, '.chalice', 'deployed.json'))
    return application
Exemplo n.º 4
0
def _deploy_app():
    if not os.path.isdir(CHALICE_DIR):
        os.makedirs(CHALICE_DIR)
    with open(os.path.join(CHALICE_DIR, 'config.json'), 'w') as f:
        f.write('{"app_name": "smoketestapp"}\n')
    factory = CLIFactory(PROJECT_DIR)
    config = factory.create_config_obj(
        chalice_stage_name='dev',
        autogen_policy=True
    )
    d = factory.create_default_deployer(
        factory.create_botocore_session(), None)
    deployed_stages = d.deploy(config)
    deployed = deployed_stages['dev']
    url = (
        "https://{rest_api_id}.execute-api.{region}.amazonaws.com/"
        "{api_gateway_stage}/".format(**deployed))
    application = SmokeTestApplication(
        url=url,
        deployed_values=deployed,
        stage_name='dev',
        app_name='smoketestapp',
    )
    record_deployed_values(deployed_stages, os.path.join(
        PROJECT_DIR, '.chalice', 'deployed.json'))
    return application
Exemplo n.º 5
0
def _delete_app(application, temp_dirname):
    factory = CLIFactory(temp_dirname)
    config = factory.create_config_obj(
        chalice_stage_name='dev',
        autogen_policy=True
    )
    session = factory.create_botocore_session()
    d = factory.create_deletion_deployer(session, UI())
    _deploy_with_retries(d, config)
Exemplo n.º 6
0
def _deploy_app(temp_dirname):
    factory = CLIFactory(temp_dirname)
    config = factory.create_config_obj(chalice_stage_name='dev',
                                       autogen_policy=True)
    session = factory.create_botocore_session()
    d = factory.create_default_deployer(session, config, UI())
    region = session.get_config_variable('region')
    deployed = _deploy_with_retries(d, config)
    application = SmokeTestApplication(
        region=region,
        deployed_values=deployed,
        stage_name='dev',
        app_name=RANDOM_APP_NAME,
        app_dir=temp_dirname,
    )
    return application
Exemplo n.º 7
0
def _deploy_app(temp_dirname):
    factory = CLIFactory(temp_dirname)
    config = factory.create_config_obj(
        chalice_stage_name='dev',
        autogen_policy=True
    )
    session = factory.create_botocore_session()
    d = factory.create_default_deployer(session, config, UI())
    region = session.get_config_variable('region')
    deployed = _deploy_with_retries(d, config)
    application = SmokeTestApplication(
        region=region,
        deployed_values=deployed,
        stage_name='dev',
        app_name=RANDOM_APP_NAME,
        app_dir=temp_dirname,
    )
    return application
def package_app(project_dir,
                output_dir,
                stage,
                chalice_config=None,
                package_format='cloudformation',
                template_format='json'):
    # type: (str, str, str, Dict[str, Any], str, str) -> None
    factory = CLIFactory(project_dir, environ=os.environ)
    if chalice_config is None:
        chalice_config = {}
    config = factory.create_config_obj(stage,
                                       user_provided_params=chalice_config)
    options = factory.create_package_options()
    packager = factory.create_app_packager(config,
                                           options,
                                           package_format=package_format,
                                           template_format=template_format)
    packager.package_app(config, output_dir, stage)
Exemplo n.º 9
0
class Client(object):
    def __init__(self, app, stage_name='dev', project_dir='.'):
        # type: (Chalice, str, str) -> None
        self._app = app
        self._project_dir = project_dir
        self._stage_name = stage_name
        self._http_client = None  # type: Optional[TestHTTPClient]
        self._events_client = None  # type: Optional[TestEventsClient]
        self._lambda_client = None  # type: Optional[TestLambdaClient]
        self._chalice_config_obj = None  # type: Optional[Config]
        # We have to be careful about not passing in the CLIFactory
        # because this is a public interface we're exposing and we don't
        # want the CLIFactory to be part of that.
        self._cli_factory = CLIFactory(project_dir)

    @property
    def _chalice_config(self):
        # type: () -> Config
        if self._chalice_config_obj is None:
            try:
                self._chalice_config_obj = self._cli_factory.create_config_obj(
                    chalice_stage_name=self._stage_name)
            except RuntimeError:
                # Being able to load a valid config is not required to use
                # the test client.  If you don't have one that you just won't
                # get any config related data added to your environment.
                self._chalice_config_obj = Config.create()
        return self._chalice_config_obj

    @property
    def http(self):
        # type: () -> TestHTTPClient
        if self._http_client is None:
            self._http_client = TestHTTPClient(self._app, self._chalice_config)
        return self._http_client

    @property
    def lambda_(self):
        # type: () -> TestLambdaClient
        if self._lambda_client is None:
            self._lambda_client = TestLambdaClient(self._app,
                                                   self._chalice_config)
        return self._lambda_client

    @property
    def events(self):
        # type: () -> TestEventsClient
        if self._events_client is None:
            self._events_client = TestEventsClient(self._app)
        return self._events_client

    def __enter__(self):
        # type: () -> Client
        return self

    def __exit__(
            self,
            exception_type,  # type: Optional[Type[BaseException]]
            exception_value,  # type: Optional[BaseException]
            traceback,  # type: Optional[TracebackType]
    ):
        # type: (...) -> None
        pass