def test_must_update_relative_metadata_paths(self, resource_type, properties): for propname in properties: for path in [ self.s3path, self.abspath, self.curpath, self.s3_full_url_https, self.s3_full_url_http ]: template_dict = { "Metadata": { resource_type: { propname: path }, "AWS::Ec2::Instance": { propname: path } }, "Parameters": { "a": "b" }, } expected_template_dict = copy.deepcopy(template_dict) if path == self.curpath: expected_template_dict["Metadata"][resource_type][ propname] = self.expected_result result = _update_relative_paths(template_dict, self.src, self.dest) self.maxDiff = None self.assertEqual(result, expected_template_dict)
def test_must_update_relative_resource_paths(self, resource_type, properties): for propname in properties: template_dict = { "Resources": { "MyResourceWithRelativePath": { "Type": resource_type, "Properties": { propname: self.curpath } }, "MyResourceWithS3Path": { "Type": resource_type, "Properties": { propname: self.s3path } }, "MyResourceWithAbsolutePath": { "Type": resource_type, "Properties": { propname: self.abspath } }, "MyResourceWithInvalidPath": { "Type": resource_type, "Properties": { # Path is not a string propname: { "foo": "bar" } }, }, "MyResourceWithoutProperties": { "Type": resource_type }, "UnsupportedResourceType": { "Type": "AWS::Ec2::Instance", "Properties": { "Code": "bar" } }, "ResourceWithoutType": { "foo": "bar" }, }, "Parameters": { "a": "b" }, } expected_template_dict = copy.deepcopy(template_dict) expected_template_dict["Resources"]["MyResourceWithRelativePath"][ "Properties"][propname] = self.expected_result result = _update_relative_paths(template_dict, self.src, self.dest) self.maxDiff = None self.assertEqual(result, expected_template_dict)
def test_must_update_relative_metadata_paths(self, resource_type, properties): for propname in properties: for path in [self.s3path, self.abspath, self.curpath]: template_dict = { "Metadata": { resource_type: { propname: path }, "AWS::Ec2::Instance": { propname: path } }, "Parameters": { "a": "b" } } expected_template_dict = copy.deepcopy(template_dict) if path == self.curpath: expected_template_dict["Metadata"][resource_type][propname] = \ self.expected_result result = _update_relative_paths(template_dict, self.src, self.dest) self.maxDiff = None self.assertEquals(result, expected_template_dict)
def test_must_update_aws_include_also(self): template_dict = { "Resources": {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.curpath}}}, "list_prop": [ "a", 1, 2, 3, {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.curpath}}}, # S3 path {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.s3path}}}, ], "Fn::Transform": {"Name": "AWS::OtherTransform"}, "key1": {"Fn::Transform": "Invalid value"}, "key2": {"Fn::Transform": {"no": "name"}} } expected_template_dict = { "Resources": {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.expected_result}}}, "list_prop": [ "a", 1, 2, 3, {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.expected_result}}}, # S3 path {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.s3path}}}, ], "Fn::Transform": {"Name": "AWS::OtherTransform"}, "key1": {"Fn::Transform": "Invalid value"}, "key2": {"Fn::Transform": {"no": "name"}} } result = _update_relative_paths(template_dict, self.src, self.dest) self.maxDiff = None self.assertEquals(result, expected_template_dict)
def test_must_update_relative_resource_paths(self, resource_type, properties): for propname in properties: template_dict = { "Resources": { "MyResourceWithRelativePath": { "Type": resource_type, "Properties": { propname: self.curpath } }, "MyResourceWithS3Path": { "Type": resource_type, "Properties": { propname: self.s3path } }, "MyResourceWithAbsolutePath": { "Type": resource_type, "Properties": { propname: self.abspath } }, "MyResourceWithInvalidPath": { "Type": resource_type, "Properties": { # Path is not a string propname: {"foo": "bar"} } }, "MyResourceWithoutProperties": { "Type": resource_type }, "UnsupportedResourceType": { "Type": "AWS::Ec2::Instance", "Properties": { "Code": "bar" } }, "ResourceWithoutType": {"foo": "bar"}, }, "Parameters": { "a": "b" } } expected_template_dict = copy.deepcopy(template_dict) expected_template_dict["Resources"]["MyResourceWithRelativePath"]["Properties"][propname] = \ self.expected_result result = _update_relative_paths(template_dict, self.src, self.dest) self.maxDiff = None self.assertEquals(result, expected_template_dict)
def test_must_update_aws_include_also(self): template_dict = { "Resources": {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.curpath}}}, "list_prop": [ "a", 1, 2, 3, {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.curpath}}}, # S3 path {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.s3path}}}, ], "Fn::Transform": {"Name": "AWS::OtherTransform"}, "key1": {"Fn::Transform": "Invalid value"}, "key2": {"Fn::Transform": {"no": "name"}}, } expected_template_dict = { "Resources": {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.expected_result}}}, "list_prop": [ "a", 1, 2, 3, {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.expected_result}}}, # S3 path {"Fn::Transform": {"Name": "AWS::Include", "Parameters": {"Location": self.s3path}}}, ], "Fn::Transform": {"Name": "AWS::OtherTransform"}, "key1": {"Fn::Transform": "Invalid value"}, "key2": {"Fn::Transform": {"no": "name"}}, } result = _update_relative_paths(template_dict, self.src, self.dest) self.maxDiff = None self.assertEqual(result, expected_template_dict)