def test_deployer_returns_deployed_resources(sample_app): cfg = Config.create( chalice_stage='dev', chalice_app=sample_app, project_dir='.', ) lambda_deploy = mock.Mock(spec=LambdaDeployer) apig_deploy = mock.Mock(spec=APIGatewayDeployer) apig_deploy.deploy.return_value = ('api_id', 'region', 'stage') lambda_deploy.deploy.return_value = { 'api_handler_name': 'lambda_function', 'api_handler_arn': 'my_lambda_arn', } d = Deployer(apig_deploy, lambda_deploy) deployed_values = d.deploy(cfg) assert deployed_values == { 'dev': { 'backend': 'api', 'api_handler_arn': 'my_lambda_arn', 'api_handler_name': 'lambda_function', 'rest_api_id': 'api_id', 'api_gateway_stage': 'stage', 'region': 'region', 'chalice_version': chalice_version, } }
def test_can_deploy_apig_and_lambda(sample_app): lambda_deploy = mock.Mock(spec=LambdaDeployer) apig_deploy = mock.Mock(spec=APIGatewayDeployer) apig_deploy.deploy.return_value = ('api_id', 'region', 'stage') d = Deployer(apig_deploy, lambda_deploy) cfg = Config({'chalice_app': sample_app}) result = d.deploy(cfg) assert result == ('api_id', 'region', 'stage') lambda_deploy.deploy.assert_called_with(cfg) apig_deploy.deploy.assert_called_with(cfg)
def test_deployer_does_not_call_delete_when_no_resources(capsys): # If there is nothing to clean up the deployer should not call delete. lambda_deploy = mock.Mock(spec=LambdaDeployer) apig_deploy = mock.Mock(spec=APIGatewayDeployer) cfg = mock.Mock(spec=Config) deployed_resources = None cfg.deployed_resources.return_value = deployed_resources d = Deployer(apig_deploy, lambda_deploy) d.delete(cfg) out, _ = capsys.readouterr() assert 'No existing resources found for stage dev' in out lambda_deploy.delete.assert_not_called() apig_deploy.delete.assert_not_called()
def test_can_deploy_apig_and_lambda(sample_app): lambda_deploy = mock.Mock(spec=LambdaDeployer) apig_deploy = mock.Mock(spec=APIGatewayDeployer) lambda_deploy.deploy.return_value = { 'api_handler_name': 'lambda_function', 'api_handler_arn': 'my_lambda_arn', } apig_deploy.deploy.return_value = ('api_id', 'region', 'stage') d = Deployer(apig_deploy, lambda_deploy) cfg = Config.create(chalice_stage='dev', chalice_app=sample_app, project_dir='.') d.deploy(cfg) lambda_deploy.deploy.assert_called_with(cfg, None, 'dev') apig_deploy.deploy.assert_called_with(cfg, None, 'my_lambda_arn')
def create_deployer(self): return Deployer( self.resource_builder, self.deps_builder, self.build_stage, self.plan_stage, self.sweeper, self.executor, self.recorder, )
def test_deployer_delete_calls_deletes(): # Check that athe deployer class calls other deployer classes delete # methods. lambda_deploy = mock.Mock(spec=LambdaDeployer) apig_deploy = mock.Mock(spec=APIGatewayDeployer) cfg = mock.Mock(spec=Config) deployed_resources = DeployedResources.from_dict({ 'backend': 'api', 'api_handler_arn': 'lambda_arn', 'api_handler_name': 'lambda_name', 'rest_api_id': 'rest_id', 'api_gateway_stage': 'dev', 'region': 'us-west-2', 'chalice_version': '0', }) cfg.deployed_resources.return_value = deployed_resources d = Deployer(apig_deploy, lambda_deploy) d.delete(cfg) lambda_deploy.delete.assert_called_with(deployed_resources) apig_deploy.delete.assert_called_with(deployed_resources)