def test_config_build(self): vpc = Stack({"name": "vpc", "class_path": "blueprints.VPC"}) config = Config({"namespace": "prod", "stacks": [vpc]}) self.assertEquals(config.namespace, "prod") self.assertEquals(config.stacks[0].name, "vpc") self.assertEquals(config["namespace"], "prod") config.validate()
def test_config_validate_missing_stack_class_path(self): config = Config({"namespace": "prod", "stacks": [{"name": "bastion"}]}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() error = ex.exception.errors['stacks'][0]['class_path'].errors[0] self.assertEquals(error.__str__(), "This field is required.")
def test_config_validate_missing_stack_source_when_locked(self): config = Config({ "namespace": "prod", "stacks": [ { "name": "bastion", "locked": True}]}) config.validate()
def test_config_validate_no_stacks(self): config = Config({"namespace": "prod"}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() error = ex.exception.errors['stacks'].errors[0] self.assertEquals(error.__str__(), "Should have more than one element.")
def test_config_validate_missing_stack_source(self): config = Config({"namespace": "prod", "stacks": [{"name": "bastion"}]}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() stack_errors = ex.exception.errors['stacks'][0] self.assertEquals(stack_errors['template_path'][0].__str__(), "class_path or template_path is required.") self.assertEquals(stack_errors['class_path'][0].__str__(), "class_path or template_path is required.")
def test_config_validate_missing_name(self): config = Config({ "namespace": "prod", "stacks": [ { "class_path": "blueprints.Bastion"}]}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() error = ex.exception.errors['stacks'][0]['name'].errors[0] self.assertEquals( error.__str__(), "This field is required.")
def test_config_validate_missing_stack_source(self): config = Config({ "namespace": "prod", "stacks": [ { "name": "bastion"}]}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() stack_errors = ex.exception.errors['stacks'][0] self.assertEquals( stack_errors['template_path'][0].__str__(), "class_path or template_path is required.") self.assertEquals( stack_errors['class_path'][0].__str__(), "class_path or template_path is required.")
def test_config_validate_duplicate_stack_names(self): config = Config({ "namespace": "prod", "stacks": [ { "name": "bastion", "class_path": "blueprints.Bastion"}, { "name": "bastion", "class_path": "blueprints.BastionV2"}]}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() error = ex.exception.errors['stacks'][0] self.assertEquals( error.__str__(), "Duplicate stack bastion found at index 0.")
def test_config_validate_stack_class_and_template_paths(self): config = Config({ "namespace": "prod", "stacks": [ { "name": "bastion", "class_path": "foo", "template_path": "bar"}]}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() stack_errors = ex.exception.errors['stacks'][0] self.assertEquals( stack_errors['template_path'][0].__str__(), "class_path cannot be present when template_path is provided.") self.assertEquals( stack_errors['class_path'][0].__str__(), "template_path cannot be present when class_path is provided.")