示例#1
0
 def test_simple_instance_missing_export(self):
     """Test that we get an exception if a CloudFormation stack tries to imports a non-existent export value"""
     with mock_cloudformation():
         client = boto3.client('cloudformation', region_name=AWS_REGION)
         with self.assertRaises(ClientError) as e:
             client.create_stack(StackName=EC2_STACK_NAME, TemplateBody=EC2_TEMPLATE)
         self.assertIn('Error', e.exception.response)
         self.assertIn('Code', e.exception.response['Error'])
         self.assertEqual('ExportNotFound', e.exception.response['Error']['Code'])
示例#2
0
    def setUp(self):
        # create runner
        self.runner = CliRunner()
        mock = mock_cloudformation()
        mock.start()
        self.mock_client = boto3.client('cloudformation')

        # open template body
        f = open(os.path.join(ROOT_DIR, 'tests', 'mock.json'), 'r')
        self.template_body = f.read()
        f.close()               # use explicit close to suppress moto warning
示例#3
0
 def test_simple_instance(self):
     """Test that we can create a simple CloudFormation stack that imports values from an existing CloudFormation stack"""
     with mock_cloudformation():
         client = boto3.client('cloudformation', region_name=AWS_REGION)
         client.create_stack(StackName=SG_STACK_NAME, TemplateBody=SG_TEMPLATE)
         response = client.create_stack(StackName=EC2_STACK_NAME, TemplateBody=EC2_TEMPLATE)
         self.assertIn('StackId', response)
         response = client.describe_stacks(StackName=response['StackId'])
         self.assertIn('Stacks', response)
         stack_info = response['Stacks']
         self.assertEqual(1, len(stack_info))
         self.assertIn('StackName', stack_info[0])
         self.assertEqual(EC2_STACK_NAME, stack_info[0]['StackName'])
示例#4
0
    def test_class(self):
        with moto.mock_cloudformation():
            allowlist = {}
            settings = {
                "general": {"dry_run": False},
                "services": {"cloudformation": {"stacks": {"clean": True, "ttl": -1}}},
            }
            execution_log = {"AWS": {}}

            test_class = cloudformation_cleanup.CloudFormationCleanup(
                logging, allowlist, settings, execution_log, "ap-southeast-2"
            )
            yield test_class
示例#5
0
 def test_simple_instance(self):
     """Test that we can create a simple CloudFormation stack that imports values from an existing CloudFormation stack"""
     with mock_cloudformation():
         client = boto3.client("cloudformation", region_name=AWS_REGION)
         client.create_stack(StackName=SG_STACK_NAME,
                             TemplateBody=SG_TEMPLATE)
         response = client.create_stack(StackName=EC2_STACK_NAME,
                                        TemplateBody=EC2_TEMPLATE)
         self.assertIn("StackId", response)
         response = client.describe_stacks(StackName=response["StackId"])
         self.assertIn("Stacks", response)
         stack_info = response["Stacks"]
         self.assertEqual(1, len(stack_info))
         self.assertIn("StackName", stack_info[0])
         self.assertEqual(EC2_STACK_NAME, stack_info[0]["StackName"])
示例#6
0
    def setUp(self):
        # create runner
        self.runner = CliRunner()
        mock = mock_cloudformation()
        mock.start()
        self.mock_client = boto3.client('cloudformation')

        # open template body
        self.template_file = os.path.join(ROOT_DIR, 'tests', 'mock.json')
        f = open(os.path.join(self.template_file), 'r')
        self.template_body = f.read()
        f.close()

        # disable error logging during testing
        logger.removeHandler(console_handler)
示例#7
0
def cloudformation(aws_credentials):
    """Get mocked API for AWS cloudformation"""
    with mock_cloudformation():
        yield boto3.resource('cloudformation')
示例#8
0
文件: conftest.py 项目: pior/buddy
def mock_cloudformation():
    with moto.mock_cloudformation():
        yield
示例#9
0
 def setup(self):
     with moto.mock_cloudformation(), moto.mock_dynamodb2(), moto.mock_sts(
     ):
         setup = lambda_handler.Setup(logging)
         yield setup
示例#10
0
def apply_moto_mocks():
    with mock_cloudformation(), mock_iam(), mock_s3(), mock_lambda(), mock_kms(
    ):
        boto3.setup_default_session()
        yield None
示例#11
0
def cloudformation_client(request):
    with mock_cloudformation():
        yield boto3.client('cloudformation', region_name='us-east-1')
示例#12
0
def setup_s3_and_ddb(aws_credentials):
    mock_cloudformation().start()
    mock_dynamodb2().start()
    mock_s3().start()
    mock_ses().start()
    mock_sts().start()
    dynamodb_client = awshelper.get_resource(awshelper.ServiceName.dynamodb)
    table = dynamodb_client.create_table(
        TableName=config.DefaultValue.config_table_name,
        KeySchema=[
            {
                'AttributeName': 'partitionkey',
                'KeyType': 'HASH'
            },
            {
                'AttributeName': 'sortkey',
                'KeyType': 'RANGE'
            }
        ],
        AttributeDefinitions=[
            {
                'AttributeName': 'partitionkey',
                'AttributeType': 'S'
            },
            {
                'AttributeName': 'sortkey',
                'AttributeType': 'S'
            }

        ]
    )

    s3_client = awshelper.get_client(awshelper.ServiceName.s3)
    s3_client.create_bucket(
        Bucket=TestValues.test_bucket_1_name,
        CreateBucketConfiguration={
            'LocationConstraint': 'us-west-2'})

    s3_client.create_bucket(
        Bucket=TestValues.test_bucket_2_name,
        CreateBucketConfiguration={
            'LocationConstraint': 'us-west-2'})

    body = bytes('hello world', 'utf-8')

    s3_client.put_object(
        Bucket=TestValues.test_bucket_1_name,
        Key='sampleobject',
        Body=body)

    s3_client.create_bucket(
        Bucket=config.DeploymentDetails.consolidated_inventory_bucket_name,
        CreateBucketConfiguration={
            'LocationConstraint': 'us-west-2'})

    index = config.ServiceParameters.iterator_count

    ddb.store_iterator_index(
        config.ServiceParameters.inventory_monitor_iterator_name,
        index)

    yield TestResources(table, None, None)
    mock_sts().stop()
    mock_ses().stop()
    mock_s3().stop()
    mock_dynamodb2().stop()
    mock_cloudformation().stop()
示例#13
0
def cf(aws_credentials):
    with moto.mock_cloudformation():
        yield boto3.client("cloudformation", region_name="us-east-1")
示例#14
0
def cloudformation():
    with mock_cloudformation():
        mock_client = boto3.client("cloudformation")
        yield mock_client
示例#15
-2
 def test_simple_instance_missing_export(self):
     """Test that we get an exception if a CloudFormation stack tries to imports a non-existent export value"""
     with mock_cloudformation():
         client = boto3.client("cloudformation", region_name=AWS_REGION)
         with self.assertRaises(ClientError) as e:
             client.create_stack(StackName=EC2_STACK_NAME, TemplateBody=EC2_TEMPLATE)
         self.assertIn("Error", e.exception.response)
         self.assertIn("Code", e.exception.response["Error"])
         self.assertEqual("ExportNotFound", e.exception.response["Error"]["Code"])