def test_config_build(self): """Test config build.""" vpc = Stack({"name": "vpc", "class_path": "blueprints.VPC"}) config = Config({"namespace": "prod", "stacks": [vpc]}) assert config.namespace == 'prod' assert config.stacks[0].name == 'vpc' assert config["namespace"] == 'prod' config.validate()
def test_config_validate_missing_stack_source_when_locked(self): """Test config validate missing stack source when locked.""" config = Config({ "namespace": "prod", "stacks": [ { "name": "bastion", "locked": True}]}) config.validate()
def test_config_validate_missing_name(self): """Test config validate missing name.""" 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] assert error.__str__() == "This field is required."
def test_config_validate_missing_stack_source(self): """Test config validate missing stack source.""" config = Config({"namespace": "prod", "stacks": [{"name": "bastion"}]}) with self.assertRaises(exceptions.InvalidConfig) as ex: config.validate() stack_errors = ex.exception.errors['stacks'][0] assert stack_errors['template_path'][0].__str__() == \ "class_path or template_path is required." assert stack_errors['class_path'][0].__str__() == \ "class_path or template_path is required."
def test_config_validate_duplicate_stack_names(self): """Test config validate duplicate stack names.""" 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] assert error.__str__() == "Duplicate stack bastion found at index 0."
def test_config_validate_stack_class_and_template_paths(self): """Test config validate stack class and template paths.""" 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] assert stack_errors['template_path'][0].__str__() == \ "class_path cannot be present when template_path is provided." assert stack_errors['class_path'][0].__str__() == \ "template_path cannot be present when class_path is provided."