def test_prefix_cannot_contain_special_characters(self, prefix): # Setup stack = Stack(Resources={"SomeName": SimpleResource()}) # Exercise & Verify with pytest.raises(ValueError) as excinfo: _ = stack.with_prefixed_names(prefix) assert "alphanumeric" in str(excinfo.value).lower()
def test_prefix_must_be_string(self, prefix): # Setup stack = Stack(Resources={"SomeName": SimpleResource()}) # Exercise & Verify with pytest.raises(TypeError) as excinfo: _ = stack.with_prefixed_names(prefix) assert "string" in str(excinfo.value).lower()
def test_prefix_cannot_be_empty(self): # Setup stack = Stack(Resources={"SomeName": SimpleResource()}) # Exercise & Verify with pytest.raises(ValueError) as excinfo: _ = stack.with_prefixed_names("") assert "empty" in str(excinfo.value).lower()
def test_prefix_must_have_leading_capital(self): # Setup stack = Stack(Resources={"SomeName": SimpleResource()}) # Exercise & Verify with pytest.raises(ValueError) as excinfo: _ = stack.with_prefixed_names( "lowercasedCamelsAreBactrianButInvalid") assert "uppercase" in str(excinfo.value).lower()
def test_return_value_is_a_new_stack(self): # Setup stack = Stack(Resources={"SomeName": SimpleResource()}) # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify assert isinstance(new_stack, Stack) assert new_stack is not stack
def test_dont_create_export_name_for_output_when_it_is_not_set(self): # Setup name = "SomeItemName" stack = Stack(Outputs={name: (Output(Value="HelloWorld"))}) # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify new_output = new_stack.Outputs[self.STACK_PREFIX + name] assert getattr(new_output, "Export", None) is None
def test_modify_content_of_description(self): # Setup stack = Stack(Description=LOREM_IPSUM) # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify assert self.STACK_PREFIX in new_stack.Description assert LOREM_IPSUM in new_stack.Description assert stack.Description == LOREM_IPSUM, "Old stack should not be modified"
def test_create_description_when_it_is_not_set(self): # Setup stack = Stack() # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify assert self.STACK_PREFIX == new_stack.Description assert (not hasattr(stack, "Description") or stack.Description is None), "Old stack should not be modified"
def test_copy_cfn_template_version(self): """AWSTemplateFormatVersion should be a string which we copy across unchanged""" # Setup version_string = "WhatIfThisWaSemanticallyVersioned.1.0" stack = Stack(AWSTemplateFormatVersion=version_string) # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify assert new_stack.AWSTemplateFormatVersion == version_string assert stack.AWSTemplateFormatVersion == version_string, "Old stack should not be modified"
def test_prefix_export_name_for_output(self): # Setup name = "SomeItemName" export_name = "SomeGloballyScopedValue" output = Output(Value="HelloWorld", Export={"Name": export_name}) stack = Stack(Outputs={name: output}) # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify assert new_stack.Outputs[ self.STACK_PREFIX + name]["Export"]["Name"] == self.STACK_PREFIX + export_name
def test_copy_sam_version_in_transform(self): """If set, Transform should be the version of the Serverless Application Model being used, which we copy across unchanged. """ # Setup version_string = "AWS::Serverless-1999-12-31" stack = Stack(Transform=version_string) # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify assert new_stack.Transform == version_string assert stack.Transform == version_string, "Old stack should not be modified"
def test_item_is_not_removed_from_original_stack(self, stack_attribute, item): # Setup item_name = "SomeItemName" stack = Stack() stack[stack_attribute] = {item_name: item} # Exercise _ = stack.with_prefixed_names(self.STACK_PREFIX) # Verify assert len(stack[stack_attribute]) == 1 assert stack[stack_attribute][item_name] is item assert stack[stack_attribute][item_name] == item
def test_item_is_prefixed_in_the_new_stack(self, stack_attribute, item): # Setup item_name = "SomeItemName" stack = Stack() stack[stack_attribute] = {item_name: item} # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify new_name = self.STACK_PREFIX + item_name assert len(new_stack[stack_attribute]) == 1 assert item_name not in new_stack[stack_attribute] assert new_stack[stack_attribute][new_name] is item
def test_output_is_prefixed_in_the_new_stack_but_not_same_object( self, stack_attribute, item): # Setup item_name = "SomeItemName" stack = Stack() stack[stack_attribute] = {item_name: item} # Exercise new_stack = stack.with_prefixed_names(self.STACK_PREFIX) # Verify new_name = self.STACK_PREFIX + item_name assert len(new_stack[stack_attribute]) == 1 assert item_name not in new_stack[stack_attribute] new_item = new_stack[stack_attribute][new_name] assert new_item is not item assert getattr(new_item, "Description", None) == getattr(item, "Description", None) assert getattr(new_item, "Value", None) is getattr(item, "Value", None), \ "This should be the same because it might be a Reference function or some such"
def test_prefix_is_an_underscored_alphanumeric_string(self, prefix): # Setup stack = Stack(Resources={"SomeName": SimpleResource()}) # Exercise & Verify _ = stack.with_prefixed_names(prefix) # Should not throw an error