def test_aws_lambda_describe_success():
    def mock_cf_response(_self, op_name, _kwarg):
        if op_name == 'DescribeStacks':
            return {
                'Stacks': [{
                    'StackStatus':
                    'CREATE_COMPLETE',
                    'Outputs': [{
                        'OutputKey':
                        'EndpointUrl',
                        'OutputValue':
                        'https://somefakelink.amazonaws.com'
                        '/prod/predict',
                    }],
                }]
            }
        else:
            raise Exception(
                'This test does not handle operation {}'.format(op_name))

    yatai_service_mock = create_yatai_service_mock()
    test_deployment_pb = generate_lambda_deployment_pb()
    with patch(
            'bentoml.yatai.deployment.aws_lambda.operator.get_default_aws_region',
            MagicMock(return_value='mock_region'),
    ):
        with patch('botocore.client.BaseClient._make_api_call',
                   new=mock_cf_response):
            deployment_operator = AwsLambdaDeploymentOperator(
                yatai_service_mock)
            result_pb = deployment_operator.describe(test_deployment_pb)
            assert result_pb.status.status_code == status_pb2.Status.OK
            assert result_pb.state.state == DeploymentState.RUNNING
def test_aws_lambda_describe_still_in_progress():
    def mock_cf_response(_self, op_name, _kwarg):
        if op_name == 'DescribeStacks':
            return {'Stacks': [{'StackStatus': 'CREATE_IN_PROGRESS'}]}
        else:
            raise Exception('This test does not handle operation {}'.format(op_name))

    yatai_service_mock = create_yatai_service_mock()
    test_deployment_pb = generate_lambda_deployment_pb()
    with patch(
        'bentoml.yatai.deployment.aws_lambda.operator.get_default_aws_region',
        MagicMock(return_value='mock_region'),
    ):
        with patch('botocore.client.BaseClient._make_api_call', new=mock_cf_response):
            deployment_operator = AwsLambdaDeploymentOperator(yatai_service_mock)
            result_pb = deployment_operator.describe(test_deployment_pb)
            assert result_pb.status.status_code == status_pb2.Status.OK
            assert result_pb.state.state == DeploymentState.PENDING