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'])
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
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'])
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
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"])
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)
def cloudformation(aws_credentials): """Get mocked API for AWS cloudformation""" with mock_cloudformation(): yield boto3.resource('cloudformation')
def mock_cloudformation(): with moto.mock_cloudformation(): yield
def setup(self): with moto.mock_cloudformation(), moto.mock_dynamodb2(), moto.mock_sts( ): setup = lambda_handler.Setup(logging) yield setup
def apply_moto_mocks(): with mock_cloudformation(), mock_iam(), mock_s3(), mock_lambda(), mock_kms( ): boto3.setup_default_session() yield None
def cloudformation_client(request): with mock_cloudformation(): yield boto3.client('cloudformation', region_name='us-east-1')
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()
def cf(aws_credentials): with moto.mock_cloudformation(): yield boto3.client("cloudformation", region_name="us-east-1")
def cloudformation(): with mock_cloudformation(): mock_client = boto3.client("cloudformation") yield mock_client
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"])