Ejemplo n.º 1
0
def project(tmpdir):
    project = Project(root=tmpdir)
    with patch.dict(
            "rpdk.core.plugin_registry.PLUGIN_REGISTRY",
        {"test": lambda: JavaLanguagePlugin},
            clear=True,
    ), patch(
            "rpdk.java.codegen.input_with_validation",
            autospec=True,
            return_value=("software", "amazon", "foo", RESOURCE.lower()),
    ):
        project.init("AWS::Foo::{}".format(RESOURCE), "test")
    return project
Ejemplo n.º 2
0
def project(tmp_path):
    project = Project(root=tmp_path)

    patch_plugins = patch.dict(
        "rpdk.core.plugin_registry.PLUGIN_REGISTRY",
        {PythonLanguagePlugin.NAME: lambda: PythonLanguagePlugin},
        clear=True,
    )
    patch_wizard = patch("rpdk.python.codegen.input_with_validation",
                         autospec=True,
                         side_effect=[False])
    with patch_plugins, patch_wizard:
        project.init(TYPE_NAME, PythonLanguagePlugin.NAME)
    return project
Ejemplo n.º 3
0
def project(tmpdir, request):
    def mock_input_with_validation(prompt, validate):  # pylint: disable=unused-argument
        if prompt.startswith("Enter a package name"):
            return ("software", "amazon", "foo", RESOURCE.lower())
        if prompt.startswith("Choose codegen model"):
            return request.param
        return ""

    project = Project(root=tmpdir)
    mock_cli = MagicMock(side_effect=mock_input_with_validation)
    with patch.dict(
            "rpdk.core.plugin_registry.PLUGIN_REGISTRY",
        {"test": lambda: JavaLanguagePlugin},
            clear=True,
    ), patch("rpdk.java.codegen.input_with_validation", new=mock_cli):
        project.init("AWS::Foo::{}".format(RESOURCE), "test")
    return project
Ejemplo n.º 4
0
def project(tmp_path: str):
    project = Project(root=tmp_path)

    patch_plugins = patch.dict(
        "rpdk.core.plugin_registry.PLUGIN_REGISTRY",
        {TypescriptLanguagePlugin.NAME: lambda: TypescriptLanguagePlugin},
        clear=True,
    )
    patch_wizard = patch(
        "rpdk.typescript.codegen.input_with_validation",
        autospec=True,
        side_effect=[False],
    )
    with patch_plugins, patch_wizard:
        current_path = os.path.abspath(__file__)
        lib_abspath = os.path.abspath(os.path.join(current_path, "..", "..", ".."))
        TypescriptLanguagePlugin.SUPPORT_LIB_URI = f"file:{lib_abspath}"
        project.init(TYPE_NAME, TypescriptLanguagePlugin.NAME)
    return project
def test_generate_with_type_configuration(tmp_path):
    type_name = "schema::with::typeconfiguration"
    project = Project(root=tmp_path)

    patch_plugins = patch.dict(
        "rpdk.core.plugin_registry.PLUGIN_REGISTRY",
        {PythonLanguagePlugin.NAME: lambda: PythonLanguagePlugin},
        clear=True,
    )
    patch_wizard = patch("rpdk.python.codegen.input_with_validation",
                         autospec=True,
                         side_effect=[False])
    with patch_plugins, patch_wizard:
        project.init(type_name, PythonLanguagePlugin.NAME)

    copyfile(
        str(Path.cwd() / "tests/data/schema-with-typeconfiguration.json"),
        str(project.root / "schema-with-typeconfiguration.json"),
    )
    project.type_info = ("schema", "with", "typeconfiguration")
    project.load_schema()
    project.load_configuration_schema()
    project.generate()

    # assert TypeConfigurationModel is added to generated directory
    models_path = project.root / "src" / "schema_with_typeconfiguration" / "models.py"

    # this however loads the module
    spec = importlib.util.spec_from_file_location("foo_bar_baz.models",
                                                  models_path)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)

    assert hasattr(module.ResourceModel, "_serialize")
    assert hasattr(module.ResourceModel, "_deserialize")
    assert hasattr(module.TypeConfigurationModel, "_serialize")
    assert hasattr(module.TypeConfigurationModel, "_deserialize")

    type_configuration_schema_file = (
        project.root / "schema-with-typeconfiguration-configuration.json")
    assert type_configuration_schema_file.is_file()