예제 #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_convert_hook_definitions(self, field: str) -> None:
     """Test _convert_hook_definitions."""
     dict_hook = {"name": {"path": "something"}}
     list_hook = [{"path": "something"}]
     assert (CfnginConfigDefinitionModel.parse_obj({
         "namespace": "test",
         field: dict_hook
     }).dict(exclude_unset=True)[field] == list_hook)
     assert (CfnginConfigDefinitionModel.parse_obj({
         "namespace": "test",
         field: list_hook
     }).dict(exclude_unset=True)[field] == list_hook)
예제 #3
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
예제 #4
0
    def test_parse_file(self, tmp_path: Path) -> None:
        """Test parse_file."""
        config_yml = tmp_path / "config.yml"
        config_yml.write_text(yaml.dump({"namespace": "test"}))

        obj = CfnginConfigDefinitionModel.parse_file(config_yml)
        assert obj.namespace == "test"
예제 #5
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"
예제 #6
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"
예제 #7
0
def test_schema_cfngin_output(cd_tmp_path: Path) -> None:
    """Test ``runway schema cfngin --output cfngin-schema.json``."""
    file_path = cd_tmp_path / "cfngin-schema.json"
    result = CliRunner().invoke(
        cli, ["schema", "cfngin", "--output", file_path.name])
    assert result.exit_code == 0
    assert str(file_path) in result.output
    assert file_path.is_file()
    assert (file_path.read_text() == CfnginConfigDefinitionModel.schema_json(
        indent=4) + "\n")
예제 #8
0
 def test_validate_unique_stack_names_invalid(self) -> None:
     """Test _validate_unique_stack_names."""
     with pytest.raises(ValidationError) as excinfo:
         data = {
             "namespace":
             "test",
             "stacks": [
                 {
                     "name": "stack0",
                     "class_path": "stack0"
                 },
                 {
                     "name": "stack0",
                     "class_path": "stack0"
                 },
             ],
         }
         CfnginConfigDefinitionModel.parse_obj(data)
     errors = excinfo.value.errors()
     assert len(errors) == 1
     assert errors[0]["loc"] == ("stacks", )
     assert errors[0]["msg"] == "Duplicate stack stack0 found at index 0"
예제 #9
0
 def test_validate_unique_stack_names(self) -> None:
     """Test _validate_unique_stack_names."""
     data = {
         "namespace":
         "test",
         "stacks": [
             {
                 "name": "stack0",
                 "class_path": "stack0"
             },
             {
                 "name": "stack1",
                 "class_path": "stack1"
             },
         ],
     }
     assert CfnginConfigDefinitionModel.parse_obj(data)
예제 #10
0
def build_schema(cfngin: bool, runway: bool) -> None:
    """Build vscode-runway schemas.

    By default, both schemas are built.

    """
    if not runway:
        click.secho("building CFNgin schema...", fg="yellow")
        CFNGIN_SCHEMA.write_text(
            CfnginConfigDefinitionModel.schema_json(indent=4))
        click.secho(f"successfully output CFNgin schema to {CFNGIN_SCHEMA}",
                    fg="green")
    if not cfngin:
        click.secho("building Runway schema...", fg="yellow")
        RUNWAY_SCHEMA.write_text(
            RunwayConfigDefinitionModel.schema_json(indent=4))
        click.secho(f"successfully output Runway schema to {CFNGIN_SCHEMA}",
                    fg="green")
예제 #11
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
예제 #12
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")
예제 #13
0
def test_schema_cfngin_indent() -> None:
    """Test ``runway schema cfngin --indent 2``."""
    result = CliRunner().invoke(cli, ["schema", "cfngin", "--indent", "2"])
    assert result.exit_code == 0
    assert result.output == CfnginConfigDefinitionModel.schema_json(
        indent=2) + "\n"
예제 #14
0
 def test_extra(self) -> None:
     """Test extra fields."""
     assert (CfnginConfigDefinitionModel(
         common="something", namespace="test").namespace == "test")