예제 #1
0
 def test_validate_class_or_template(self, enabled: bool,
                                     locked: bool) -> None:
     """Test _validate_class_or_template."""
     assert CfnginStackDefinitionModel(class_path="something",
                                       enabled=enabled,
                                       locked=locked,
                                       name="test-stack")
     assert CfnginStackDefinitionModel(
         enabled=enabled,
         locked=locked,
         name="test-stack",
         template_path="./something.yml",
     )
예제 #2
0
    def from_stack_name(
        cls,
        stack_name: str,
        context: CfnginContext,
        requires: Optional[Union[List[str], Set[str]]] = None,
        fn: Optional[Callable[..., Status]] = None,
        watch_func: Optional[Callable[..., Any]] = None,
    ) -> Step:
        """Create a step using only a stack name.

        Args:
            stack_name: Name of a CloudFormation stack.
            context: Context object. Required to initialize a "fake"
                :class:`runway.cfngin.stack.Stack`.
            requires: Stacks that this stack depends on.
            fn: The function to run to execute the step.
                This function will be ran multiple times until the step is "done".
            watch_func: an optional function that will be called to "tail" the
                step action.

        """
        # pylint: disable=import-outside-toplevel
        from runway.config.models.cfngin import CfnginStackDefinitionModel

        stack_def = CfnginStackDefinitionModel.construct(name=stack_name,
                                                         requires=requires
                                                         or [])
        stack = Stack(stack_def, context)
        return cls(stack, fn=fn, watch_func=watch_func)
예제 #3
0
 def test_required_fields_w_class_path(self) -> None:
     """Test required fields."""
     with pytest.raises(ValidationError) as excinfo:
         CfnginStackDefinitionModel(class_path="something")
     errors = excinfo.value.errors()
     assert len(errors) == 1
     assert errors[0]["loc"] == ("name", )
     assert errors[0]["msg"] == "field required"
예제 #4
0
 def test_resolve_path_fields(self) -> None:
     """Test _resolve_path_fields."""
     obj = CfnginStackDefinitionModel(
         name="test-stack",
         stack_policy_path="./policy.json",
         template_path="./template.yml",
     )
     assert obj.stack_policy_path.is_absolute()  # type: ignore
     assert obj.template_path.is_absolute()  # type: ignore
예제 #5
0
 def test_required_fields(self) -> None:
     """Test required fields."""
     with pytest.raises(ValidationError) as excinfo:
         CfnginStackDefinitionModel()
     errors = excinfo.value.errors()
     assert len(errors) == 1
     assert errors[0]["loc"] == ("__root__", )
     assert errors[0][
         "msg"] == "either class_path or template_path must be defined"
예제 #6
0
 def test_extra(self) -> None:
     """Test extra fields."""
     with pytest.raises(ValidationError) as excinfo:
         CfnginStackDefinitionModel(class_path="something",
                                    invalid="something",
                                    name="stack-name")
     errors = excinfo.value.errors()
     assert len(errors) == 1
     assert errors[0]["loc"] == ("invalid", )
     assert errors[0]["msg"] == "extra fields not permitted"
예제 #7
0
 def test_validate_class_or_template_invalid(self) -> None:
     """Test _validate_class_or_template invalid."""
     with pytest.raises(ValidationError) as excinfo:
         CfnginStackDefinitionModel(enabled=True,
                                    locked=False,
                                    name="stack-name")
     errors = excinfo.value.errors()
     assert len(errors) == 1
     assert errors[0]["loc"] == ("__root__", )
     assert errors[0][
         "msg"] == "either class_path or template_path must be defined"
예제 #8
0
 def test_validate_class_and_template(self) -> None:
     """Test _validate_class_and_template."""
     with pytest.raises(ValidationError) as excinfo:
         CfnginStackDefinitionModel(
             class_path="something",
             name="stack-name",
             template_path="./something.yml",
         )
     errors = excinfo.value.errors()
     assert len(errors) == 1
     assert errors[0]["loc"] == ("__root__", )
     assert (errors[0]["msg"] ==
             "only one of class_path or template_path can be defined")
예제 #9
0
 def test_field_defaults(self) -> None:
     """Test field default values."""
     obj = CfnginStackDefinitionModel(class_path="something",
                                      name="stack-name")
     assert obj.class_path == "something"
     assert not obj.description
     assert obj.enabled
     assert not obj.in_progress_behavior
     assert not obj.locked
     assert obj.name == "stack-name"
     assert not obj.protected
     assert obj.required_by == []
     assert obj.requires == []
     assert not obj.stack_name
     assert not obj.stack_policy_path
     assert obj.tags == {}
     assert not obj.template_path
     assert not obj.termination_protection
     assert obj.variables == {}