def test_set_physical_resource_id(self): properties = {} event = ccr_utils.generate_request( 'create', 'Custom::CustomResourcePhysicalResourceId', properties, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT) id_to_set = 'foo' obj = self.CustomResourcePhysicalResourceId(id_to_set, self) obj.handle(event, ccr_utils.MockLambdaContext()) self.assertEqual(obj.physical_resource_id, id_to_set)
def test_update_text_moved(self): key1 = self.key('test_update_text_moved1') properties1 = { 'Bucket': self.bucket, 'Key': key1, 'Text': 'Value1', } event1 = ccr_utils.generate_request( 'create', 'Custom::S3Object', properties1, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT) obj1 = S3Object() obj1.handle(event1, ccr_utils.MockLambdaContext()) key2 = self.key('test_update_text_moved2') properties2 = { 'Bucket': self.bucket, 'Key': key2, 'Text': 'Value2', } event2 = ccr_utils.generate_request( 'update', 'Custom::S3Object', properties2, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT, old_properties=properties1) obj2 = S3Object() obj2.handle(event2, ccr_utils.MockLambdaContext()) client = boto3.client('s3') response = client.head_object(Bucket=self.bucket, Key=key2) with self.assertRaises(botocore.exceptions.ClientError): response = client.head_object(Bucket=self.bucket, Key=key1)
def test_delete(self): properties = {} event = ccr_utils.generate_request( 'delete', 'Custom::CustomResourceBasicTest', properties, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT) outputs = {'output_key': 'output_value'} obj = self.CustomResourceBasicTest(outputs) obj.handle(event, ccr_utils.MockLambdaContext()) self.assertTrue(obj.delete_called) self.assertEqual(obj.resource_outputs, outputs)
def test_response_content(self): properties = {} event = ccr_utils.generate_request( 'create', 'Custom::CustomResourceBasicTest', properties, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT) outputs = {'output_key': 'output_value'} obj = self.CustomResourceBasicTest(outputs) obj.handle(event, ccr_utils.MockLambdaContext()) self.assertEqual(obj.test_response_content['Status'], CloudFormationCustomResource.STATUS_SUCCESS) self.assertEqual(obj.test_response_content['Data'], outputs)
def test_create_string(self): properties = { 'Name': self.param_string_name, } event = ccr_utils.generate_request( 'create', 'Custom::SSMParameterInput', properties, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT) obj = SSMParameterInput() capturer = ccr_utils.ResponseCapturer() capturer.set(obj) obj.handle(event, ccr_utils.MockLambdaContext()) self.assertEqual(obj.physical_resource_id, self.param_string_value)
def test_decorator(self): @decorator.create def create(resource): pass @decorator.update def update(resource): pass @decorator.delete def delete(resource): pass properties = {} event = ccr_utils.generate_request( 'create', 'Custom::DecoratorTest', properties, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT) decorator.handler(event, ccr_utils.MockLambdaContext())
def test_sns_update(self): properties = {} old_properties = {} cfn_event = ccr_utils.generate_request( 'update', 'Custom::CustomResourceBasicTest', properties, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT, old_properties=old_properties) event = ccr_utils.generate_sns_event(json.dumps(cfn_event)) outputs = {'output_key': 'output_value'} obj = self.CustomResourceBasicTest(outputs) obj.handle(event, ccr_utils.MockLambdaContext()) self.assertTrue(obj.update_called) self.assertEqual(obj.resource_outputs, outputs)
def test_create_text(self): key = self.key('test_create_text') properties = { 'Bucket': self.bucket, 'Key': key, 'Text': 'Foobar', } event = ccr_utils.generate_request( 'create', 'Custom::S3Object', properties, CloudFormationCustomResource.DUMMY_RESPONSE_URL_SILENT) obj = S3Object() capturer = ccr_utils.ResponseCapturer() capturer.set(obj) now = datetime.datetime.now(tzlocal()) obj.handle(event, ccr_utils.MockLambdaContext()) client = boto3.client('s3') response = client.head_object(Bucket=self.bucket, Key=key) self.assertLess(now, response['LastModified'])