Ejemplo n.º 1
0
 def test_parse_file_find_config_file_value_error(self,
                                                  monkeypatch: MonkeyPatch,
                                                  tmp_path: Path) -> None:
     """Test parse_file with path raise ValueError."""
     mock_find_config_file = MagicMock(
         return_value=[tmp_path / "01.yml", tmp_path / "02.yml"])
     monkeypatch.setattr(CfnginConfig, "find_config_file",
                         mock_find_config_file)
     with pytest.raises(ValueError) as excinfo:
         CfnginConfig.parse_file(path=tmp_path)
     assert str(excinfo.value).startswith("more than one")
Ejemplo n.º 2
0
 def test_parse_file_file_path(self, tmp_path: Path) -> None:
     """Test parse_file with file_path."""
     config_yml = tmp_path / "config.yml"
     data = {"namespace": "test"}
     config_yml.write_text(yaml.dump(data))
     config = CfnginConfig.parse_file(file_path=config_yml)
     assert config.namespace == data["namespace"]
Ejemplo n.º 3
0
def cfngin_config(request: SubRequest, runway_config: RunwayConfig,
                  runway_context: RunwayContext) -> CfnginConfig:
    """Find and return the CFNgin config."""
    runway_config.deployments[0].resolve(runway_context,
                                         variables=runway_config.variables)
    return CfnginConfig.parse_file(
        path=Path(request.fspath).parent / "cfngin.yml",
        parameters=runway_config.deployments[0].parameters,
    )
Ejemplo n.º 4
0
 def test_parse_file_find_config_file(self, monkeypatch: MonkeyPatch,
                                      tmp_path: Path) -> None:
     """Test parse_file with path."""
     file_path = tmp_path / "test.yml"
     file_path.write_text("name: test\n")
     mock_find_config_file = MagicMock(return_value=[file_path])
     mock_parse_raw = MagicMock(return_value=None)
     monkeypatch.setattr(CfnginConfig, "find_config_file",
                         mock_find_config_file)
     monkeypatch.setattr(CfnginConfig, "parse_raw", mock_parse_raw)
     assert not CfnginConfig.parse_file(path=tmp_path)
     mock_find_config_file.assert_called_once_with(tmp_path)
     mock_parse_raw.assert_called_once_with(file_path.read_text(),
                                            path=file_path,
                                            parameters={})
Ejemplo n.º 5
0
 def test_parse_file_value_error(self):
     """Test parse_file raise ValueError."""
     with pytest.raises(ValueError) as excinfo:
         CfnginConfig.parse_file()
     assert str(excinfo.value) == "must provide path or file_path"
Ejemplo n.º 6
0
 def test_parse_file_file_path_missing(self, tmp_path: Path) -> None:
     """Test parse_file with file_path missing."""
     config_yml = tmp_path / "config.yml"
     with pytest.raises(ConfigNotFound) as excinfo:
         CfnginConfig.parse_file(file_path=config_yml)
     assert excinfo.value.path == config_yml