예제 #1
0
 def test_convert_stack_definitions(self) -> None:
     """Test _convert_stack_definitions."""
     dict_stack = {"stack-name": {"class_path": "something"}}
     list_stack = [{"class_path": "something", "name": "stack-name"}]
     assert (CfnginConfigDefinitionModel(
         namespace="test", stacks=dict_stack).dict(
             exclude_unset=True)["stacks"] == list_stack)
     assert (CfnginConfigDefinitionModel(
         namespace="test", stacks=list_stack).dict(
             exclude_unset=True)["stacks"] == list_stack)
예제 #2
0
 def test_resolve_path_fields(self) -> None:
     """Test _resolve_path_fields."""
     obj = CfnginConfigDefinitionModel(namespace="test",
                                       cfngin_cache_dir="./cache",
                                       sys_path="./something")
     assert obj.cfngin_cache_dir.is_absolute()
     assert obj.sys_path.is_absolute()  # type: ignore
예제 #3
0
 def test_required_fields(self) -> None:
     """Test required fields."""
     with pytest.raises(ValidationError) as excinfo:
         CfnginConfigDefinitionModel()
     errors = excinfo.value.errors()
     assert len(errors) == 1
     assert errors[0]["loc"] == ("namespace", )
     assert errors[0]["msg"] == "field required"
예제 #4
0
 def test_parse_obj(self, monkeypatch: MonkeyPatch) -> None:
     """Test parse_obj."""
     monkeypatch.setattr(
         MODULE + ".CfnginConfigDefinitionModel.parse_obj",
         lambda x: CfnginConfigDefinitionModel(namespace="success"
                                               ),  # type: ignore
     )
     assert CfnginConfig.parse_obj({}).namespace == "success"
예제 #5
0
 def test_field_defaults(self) -> None:
     """Test field default values."""
     obj = CfnginConfigDefinitionModel(namespace="test")
     assert not obj.cfngin_bucket
     assert not obj.cfngin_bucket_region
     assert obj.cfngin_cache_dir == Path.cwd() / ".runway" / "cache"
     assert obj.log_formats == {}
     assert obj.lookups == {}
     assert obj.mappings == {}
     assert obj.namespace == "test"
     assert obj.namespace_delimiter == "-"
     assert obj.package_sources == CfnginPackageSourcesDefinitionModel()
     assert not obj.persistent_graph_key
     assert obj.post_deploy == []
     assert obj.post_destroy == []
     assert obj.pre_deploy == []
     assert obj.pre_destroy == []
     assert not obj.service_role
     assert obj.stacks == []
     assert not obj.sys_path
     assert not obj.tags
예제 #6
0
    def test_load(
        self,
        mock_sys: MagicMock,
        mock_register_lookup_handler: MagicMock,
        tmp_path: Path,
    ) -> None:
        """Test load."""
        config = CfnginConfig(CfnginConfigDefinitionModel(namespace="test"))

        config.load()
        mock_sys.path.append.assert_not_called()
        mock_register_lookup_handler.assert_not_called()

        config.sys_path = tmp_path
        config.load()
        mock_sys.path.append.assert_called_once_with(str(config.sys_path))
        mock_register_lookup_handler.assert_not_called()

        config.lookups = {"custom-lookup": "path"}
        config.load()
        mock_register_lookup_handler.assert_called_once_with(
            "custom-lookup", "path")
예제 #7
0
 def test_extra(self) -> None:
     """Test extra fields."""
     assert (CfnginConfigDefinitionModel(
         common="something", namespace="test").namespace == "test")