def test_default(self): setup() create_physical_resource_id = '' if True: event = cfntest.get_create_event({ "Parameters": { "Name": "test", "Value": "1", }, "TemplateURL": "https://hixi.s3.amazonaws.com/resource.yaml", "Region": "us-east-1", }) c = Stack(event, cfntest.get_context()) c.run() create_physical_resource_id = c.response.physical_resource_id self.assertEqual(c.response.get_data('Outputs.OutputName'), 'test') self.assertEqual(c.response.get_data('Outputs.OutputValue'), '1') update_phycical_resource_id = '' if True: event = cfntest.get_update_event({ "ParentStackName": "Parent", "ParentStackRegion": "ap-northeast-1", "Parameters": { "Name": "test2", "Value": "1", }, "TemplateURL": "https://hixi.s3.amazonaws.com/resource.yaml", "Region": "us-east-1", }) c = Stack(event, cfntest.get_context()) c.run() update_physical_resource_id = c.response.physical_resource_id create_physical_resource_id = c.response.physical_resource_id self.assertEqual(c.response.get_data('Outputs.OutputName'), 'test2') self.assertEqual(c.response.get_data('Outputs.OutputValue'), '1') self.assertEqual(create_physical_resource_id, update_physical_resource_id) if True: event = cfntest.get_delete_event({ "ParentStackName": "Parent", "ParentStackRegion": "ap-northeast-1", "Parameters": { "Name": "test2", "Value": "1", }, "TemplateURL": "https://hixi.s3.amazonaws.com/resource.yaml", "Region": "us-east-1", }) c = Stack(event, cfntest.get_context()) c.run()
def test_pagination(self): STACK_NAME = 'test-pagination-stack' client = boto3.client('cloudformation') client.create_stack(StackName=STACK_NAME, TemplateBody=TEMPLATE) for i in range(100): client.create_stack(StackName='{}-{}'.format(STACK_NAME, i), TemplateBody=TEMPLATE) context = cfntest.get_context() create_event = cfntest.get_create_event({"Name": STACK_NAME}) update_event = cfntest.get_update_event( {"Name": STACK_NAME}, cfntest.get_properties(create_event)) delete_event = cfntest.get_delete_event( cfntest.get_properties(update_event), cfntest.get_properties(create_event)) if True: c = ImportValue(create_event, context) c.run() self.assertEqual(c.response.get_data('Value'), "test-pagination-stack-bucket") if True: c = ImportValue(update_event, context) c.run() self.assertEqual(c.response.get_data('Value'), "test-pagination-stack-bucket") if True: c = ImportValue(delete_event, context) c.run()
def test_default(self): context = cfntest.get_context() create_event = cfntest.get_create_event({"Name": "/test/demo"}) update_event = cfntest.get_update_event({"Name": "/test/demo", "Length": "12"}, cfntest.get_properties(create_event)) delete_event = cfntest.get_delete_event(cfntest.get_properties(update_event), cfntest.get_properties(update_event)) physical_resource_id = '' if True: c = Secret(create_event, context) c.run() self.assertEqual(get_ssm("/test/demo"), c.response.get_data("Secret")) self.assertEqual(len(get_ssm("/test/demo")), 32) physical_resource_id = c.response.physical_resource_id if True: c = Secret(update_event, context) c.run() self.assertEqual(c.response.physical_resource_id, physical_resource_id) self.assertEqual(len(get_ssm("/test/demo")), 12) if True: c = Secret(delete_event, context) c.run() self.assertEqual(c.response.physical_resource_id, physical_resource_id) with self.assertRaises(Exception): get_ssm("/test/demo")
def test_initialize(self): setup() context = cfntest.get_context() event = cfntest.get_create_event({ "Parameters": { "Name": "test", "Value": "1", }, "TemplateURL": "https://hixi.s3.amazonaws.com/resource.yaml", "Region": "us-east-1", }) c = Stack(event, context) print(c.stack_name) self.assertEqual(len(c.unique_key), 12) self.assertEqual(c.id, "us-east-1:https://hixi.s3.amazonaws.com/resource.yaml") self.assertDictEqual(c._parameters, {"Name":"test", "Value":"1"}) self.assertCountEqual(c.parameters, [ { "ParameterKey": "Name", "ParameterValue": "test", }, { "ParameterKey": "Value", "ParameterValue": "1", }, ])
def test_error_not_found(self): context = cfntest.get_context() create_event = cfntest.get_create_event({"Name": 'hogehoge'}) if True: c = ImportValue(create_event, context) with self.assertRaises(Exception): c.run()
def test_default(self): bucket_name = 'test' lambda_arn = 'arn:aws:lambda:us-east-1:123456789012:function:my-function' s3 = boto3.client('s3') s3.create_bucket(Bucket=bucket_name, ) context = cfntest.get_context() create_event = cfntest.get_create_event({ "Bucket": bucket_name, "NotificationConfiguration": { "LambdaFunctionConfigurations": [{ "Events": ["s3:ObjectCreated:*"], "LambdaFunctionArn": lambda_arn, }] } }) update_event = cfntest.get_update_event( { "Bucket": "test", "NotificationConfiguration": { "LambdaFunctionConfigurations": [{ "Events": ["s3:ObjectCreated:Put"], "LambdaFunctionArn": lambda_arn, }] } }, cfntest.get_properties(create_event)) delete_event = cfntest.get_delete_event( cfntest.get_properties(update_event), cfntest.get_properties(create_event)) if True: c = S3BucketNotificationConfiguration(create_event, context) c.run() self.assertEqual( get_bucket_notification_configuration(bucket_name) ['LambdaFunctionConfigurations'][0]['Events'][0], 's3:ObjectCreated:*') if True: c = S3BucketNotificationConfiguration(update_event, context) c.run() self.assertEqual( get_bucket_notification_configuration(bucket_name) ['LambdaFunctionConfigurations'][0]['Events'][0], 's3:ObjectCreated:Put') if True: c = S3BucketNotificationConfiguration(delete_event, context) c.run() self.assertNotIn( 'LambdaFunctionConfigurations', get_bucket_notification_configuration(bucket_name))
def test_default(self): context = cfntest.get_context() create_event = cfntest.get_create_event({"Name":"/test/demo", "Type":"SecureString", "Value": "secret"}) update_event = cfntest.get_update_event({"Name":"/test/demo", "Type":"SecureString", "Value": "secret2"}, cfntest.get_properties(create_event)) delete_event = cfntest.get_delete_event(cfntest.get_properties(update_event), cfntest.get_properties(create_event)) if True: c = Ssm(create_event, context) c.run() self.assertEqual(get_ssm("/test/demo"), "secret") if True: c = Ssm(update_event, context) c.run() self.assertEqual(get_ssm("/test/demo"), "secret2") if True: c = Ssm(delete_event, context) c.run() with self.assertRaises(Exception): get_ssm("/test/demo")
def test_default(self): context = cfntest.get_context() create_event = cfntest.get_create_event({"Value": "AAA"}) update_event = cfntest.get_update_event( {"Value": "BBB"}, cfntest.get_properties(create_event)) delete_event = cfntest.get_delete_event( cfntest.get_properties(update_event), cfntest.get_properties(update_event)) physical_resource_id = '' if True: c = Value(create_event, context) c.run() self.assertEqual(c.response.get_data("Value"), "AAA") self.assertEqual(c.response.physical_resource_id, "AAA") if True: c = Value(update_event, context) c.run() self.assertEqual(c.response.get_data("Value"), "BBB") self.assertEqual(c.response.physical_resource_id, "BBB")
def test_one_case(self): context = cfntest.get_context() event = cfntest.get_create_event({"Values": ["dEv"]}) c = Strings(event, context) c.run() self.assertEqual(get(c, "Upper"), "DEV") self.assertEqual(get(c, "Lower"), "dev") self.assertEqual(get(c, "Camelize"), "Dev") self.assertEqual(get(c, "CamelizeLower"), "dev") self.assertEqual(get(c, "Dasherize"), "dEv") self.assertEqual(get(c, "DasherizeLower"), "dev") self.assertEqual(get(c, "DasherizeUpper"), "DEV") self.assertEqual(get(c, "Snakelize"), "dEv") self.assertEqual(get(c, "SnakelizeLower"), "dev") self.assertEqual(get(c, "SnakelizeUpper"), "DEV") self.assertEqual(get(c, "Titlize"), "Dev") self.assertEqual(get(c, "Dotize"), "dEv") self.assertEqual(get(c, "DotizeLower"), "dev") self.assertEqual(get(c, "DotizeUpper"), "DEV")
def test_complex_three_case(self): context = cfntest.get_context() event = cfntest.get_create_event({"Values": ["dEv", "hIxi", "tEmp"]}) c = Strings(event, context) c.run() self.assertEqual(get(c, "Upper"), "DEVHIXITEMP") self.assertEqual(get(c, "Lower"), "devhixitemp") self.assertEqual(get(c, "Camelize"), "DevHixiTemp") self.assertEqual(get(c, "CamelizeLower"), "devHixiTemp") self.assertEqual(get(c, "Dasherize"), "dEv-hIxi-tEmp") self.assertEqual(get(c, "DasherizeLower"), "dev-hixi-temp") self.assertEqual(get(c, "DasherizeUpper"), "DEV-HIXI-TEMP") self.assertEqual(get(c, "Snakelize"), "dEv_hIxi_tEmp") self.assertEqual(get(c, "SnakelizeLower"), "dev_hixi_temp") self.assertEqual(get(c, "SnakelizeUpper"), "DEV_HIXI_TEMP") self.assertEqual(get(c, "Titlize"), "Dev Hixi Temp") self.assertEqual(get(c, "Dotize"), "dEv.hIxi.tEmp") self.assertEqual(get(c, "DotizeLower"), "dev.hixi.temp") self.assertEqual(get(c, "DotizeUpper"), "DEV.HIXI.TEMP")
def test_complex_two_case(self): context = cfntest.get_context() event = cfntest.get_create_event({"Values": ["dEv", "hIxi"]}) c = Strings(event, context) c.run() self.assertEqual(get(c, "Upper"), "DEVHIXI") self.assertEqual(get(c, "Lower"), "devhixi") self.assertEqual(get(c, "Camelize"), "DevHixi") self.assertEqual(get(c, "CamelizeLower"), "devHixi") self.assertEqual(get(c, "Dasherize"), "dEv-hIxi") self.assertEqual(get(c, "DasherizeLower"), "dev-hixi") self.assertEqual(get(c, "DasherizeUpper"), "DEV-HIXI") self.assertEqual(get(c, "Snakelize"), "dEv_hIxi") self.assertEqual(get(c, "SnakelizeLower"), "dev_hixi") self.assertEqual(get(c, "SnakelizeUpper"), "DEV_HIXI") self.assertEqual(get(c, "Titlize"), "Dev Hixi") self.assertEqual(get(c, "Dotize"), "dEv.hIxi") self.assertEqual(get(c, "DotizeLower"), "dev.hixi") self.assertEqual(get(c, "DotizeUpper"), "DEV.HIXI")
def test_default(self): request = cfntest.get_create_event({"Name": "/test/demo"}) c = Secret(request, cfntest.get_context()) c.run() self.assertEqual(get_ssm("/test/demo"), c.response.get_data("Secret"))