Пример #1
0
    def test_new_config_file_already_exists(self, env: Environment) -> None:
        env.prepare(project_dir_name="basic", config_file_name="basic")

        assert (env.project_dir_path / DEFAULT_CONFIG_PATH).exists()

        with pytest.raises(NewConfigException, match=r"exists"):
            env.run_wap("new-config")
Пример #2
0
def test_validate(
    env: Environment,
) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="basic",
    )

    result = env.run_wap("validate", "--json")

    assert not contains_warn_error(result.stderr)

    config_json = json.loads(result.stdout)

    assert config_json["name"] == "MyAddon"
    assert set(config_json["wow-versions"]) == {"9.0.2", "1.13.6"}
    assert config_json["curseforge"]["project-id"] == "123456"
    assert config_json["curseforge"]["changelog-file"] == "CHANGELOG.md"
    assert config_json["curseforge"]["project-slug"] == "myaddon"
    assert config_json["addons"][0]["path"] == "Dir1"
    assert config_json["addons"][0]["toc"]["tags"] == {
        "Title": "MyAddon Dir1",
        "X-Custom-Tag": "foobar",
    }
    assert config_json["addons"][0]["toc"]["files"] == ["Dir1.lua", "Sub/Another.lua"]

    assert result.exit_code == 0

    assert "is valid" in result.stderr
Пример #3
0
def test_upload_changelog_extensions(
    env: Environment,
    config_file_name: str,
    changelog_file_name: str,
    expected_changelog_type: str,
) -> None:
    env.prepare(
        project_dir_name="basic-built",
        config_file_name=config_file_name,
    )

    # rename the changelog file
    orig_changelog = env.project_dir_path / "CHANGELOG.md"
    assert orig_changelog.exists(
    )  # make sure this file is here before we test
    orig_changelog.rename(env.project_dir_path / changelog_file_name)

    env.run_wap(
        "upload",
        "--version",
        DEFAULT_PROJECT_VERSION,
        "--curseforge-token",
        "abc123",
    )

    decoded_req = decode_file_upload_multipart_request(
        env.requests_mock.request_history[1])

    json_metadata = decoded_req.json_metadata
    assert json_metadata["changelogType"] == expected_changelog_type
Пример #4
0
    def test_quickstart_dir_exists(self, env: Environment) -> None:
        env.prepare(project_dir_name="empty", )

        project_dir_path = env.project_dir_path / "exists"
        project_dir_path.mkdir()

        with pytest.raises(QuickstartException, match=r"exists"):
            env.run_wap("quickstart", str(project_dir_path))
Пример #5
0
    def test_config_path_not_file(
        self, env: Environment, run_args: Iterable[str]
    ) -> None:
        env.prepare(project_dir_name="basic", wow_dir_name="retail")
        env.config_file_path.unlink()

        with pytest.raises(ConfigFileException, match=r"No such config file"):
            env.run_wap(*run_args)
Пример #6
0
def test_package_dir_path_not_dir(env: Environment, config_name: str) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name=config_name,
        wow_dir_name="retail",
    )

    with pytest.raises(PackageException, match=r"is not a directory"):
        env.run_wap("package")
Пример #7
0
def test_package_toc_file_does_not_exist(env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="toc_file_does_not_exist",
        wow_dir_name="retail",
    )

    with pytest.raises(TocException, match=r"but it is not a file"):
        env.run_wap("package")
Пример #8
0
def test_commands_config_no_curseforge_required(env: Environment) -> None:
    # curseforge section is optional for package and dev-install
    env.prepare(
        project_dir_name="basic",
        config_file_name="no_curseforge",
        wow_dir_name="retail",
    )

    env.run_wap("package")
    env.run_wap("dev-install", "--wow-addons-path", str(env.wow_dir_path))
Пример #9
0
    def test_config_non_utf_8(self, env: Environment, run_args: Iterable[str]) -> None:
        # curseforge section is optional for package and dev-install
        env.prepare(
            project_dir_name="basic",
            config_file_name="toc_tags_non_utf_8",
            wow_dir_name="retail",
        )

        with pytest.raises(ConfigFileException, match=r"cannot be decoded to utf-8"):
            env.run_wap(*run_args)
Пример #10
0
def test_dev_install_overwrites(env: Environment, ) -> None:
    env.prepare(
        project_dir_name="basic-built",
        config_file_name="basic",
        wow_dir_name="retail",
    )

    # runs two consecutive invocations. the second will overwrite files from the first.
    env.run_wap("dev-install", "--wow-addons-path", str(env.wow_dir_path))
    env.run_wap("dev-install", "--wow-addons-path", str(env.wow_dir_path))
Пример #11
0
def test_package_config_toc_tag_secure(env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="toc_tags_secure",
        wow_dir_name="retail",
    )

    result = env.run_wap("package")

    assert "Only Blizzard-signed addons" in result.stderr
Пример #12
0
def test_package_toc_custom_tag_without_prefix(env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="toc_custom_tag_without_prefix",
        wow_dir_name="retail",
    )

    result = env.run_wap("package")

    assert "TOC user-specified tag" in result.stderr
Пример #13
0
def test_package_config_toc_tag_with_localizations(env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="toc_tags_localized",
        wow_dir_name="retail",
    )

    result = env.run_wap("package")

    assert not contains_warn_error(result.stderr)
Пример #14
0
def test_package_config_toc_tag_too_long(env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="toc_custom_tag_too_long",
        wow_dir_name="retail",
    )

    result = env.run_wap("package")

    assert "Line length for TOC tag" in result.stderr
Пример #15
0
    def test_new_config(self, env: Environment,
                        use_default_config_path: bool) -> None:
        env.prepare(project_dir_name="new_config", )
        env.config_file_path.unlink()

        addon_name = "foo"
        author = "John Doe"
        description = "My description"

        input_lines = [
            addon_name,  # addon name (default)
            author,  # author name
            description,  # notes
            "N",  # no to retail wow, therefore, classic
            "no",  # no to having a curseforge project
        ]

        run_wap_args = ["new-config"]
        additional_args = []

        if not use_default_config_path:
            config_path = env.project_dir_path / ".wap.custom.yml"
            additional_args = ["--config-path", str(config_path.name)]
        else:
            config_path = env.project_dir_path / DEFAULT_CONFIG_PATH

        result = env.run_wap(*run_wap_args,
                             *additional_args,
                             input_lines=input_lines)

        assert not contains_warn_error(result.stderr)

        assert config_path.exists()

        # test the config made
        validation_result = env.run_wap(
            "validate",
            "--json",
            "--config-path",
            str(config_path),
        )
        config_json = json.loads(validation_result.stdout)

        assert config_json["name"] == addon_name
        assert set(config_json["wow-versions"]) == {
            LATEST_CLASSIC_VERSION.dot_version(),
        }
        assert "curseforge" not in config_json
        assert config_json["addons"][0]["path"] == addon_name
        assert config_json["addons"][0]["toc"]["tags"] == {
            "Title": addon_name,
            "Author": author,
            "Notes": description,
        }
        assert config_json["addons"][0]["toc"]["files"] == ["Init.lua"]
Пример #16
0
def test_dev_install_wow_addons_dir_is_not_dir(
    env: Environment,
    wow_dir_path: str,
) -> None:
    env.prepare(
        project_dir_name="basic-built",
        config_file_name="basic",
    )

    with pytest.raises(BadParameter, match=r"is not a directory"):
        env.run_wap("dev-install", "--wow-addons-path", wow_dir_path)
Пример #17
0
def test_package_toc_file_exists(env: Environment,
                                 project_dir_name: str) -> None:
    env.prepare(
        project_dir_name=project_dir_name,
        config_file_name="basic",
        wow_dir_name="retail",
    )

    result = env.run_wap("package")

    assert "will be overwritten" in result.stderr
Пример #18
0
    def test_config_dir_paths_not_unique(
        self, env: Environment, run_args: Iterable[str]
    ) -> None:
        env.prepare(
            project_dir_name="basic",
            config_file_name="dir_paths_not_unique",
            wow_dir_name="retail",
        )

        with pytest.raises(ConfigSemanticException, match=r"must have unique paths"):
            env.run_wap(*run_args)
Пример #19
0
def test_package_overwrites_existing(env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="basic",
        wow_dir_name="retail",
    )

    # runs two consecutive invocations. the second will overwrite files from the
    # first.
    env.run_wap("package")
    env.run_wap("package")
Пример #20
0
    def test_config_toc_file_not_relative(
        self, env: Environment, run_args: Iterable[str]
    ) -> None:
        env.prepare(
            project_dir_name="basic",
            config_file_name="toc_file_not_relative",
            wow_dir_name="retail",
        )

        with pytest.raises(ConfigSemanticException, match=r"must be relative"):
            env.run_wap(*run_args)
Пример #21
0
    def test_config_does_not_follow_schema(
        self, env: Environment, run_args: Iterable[str]
    ) -> None:
        env.prepare(
            project_dir_name="basic",
            config_file_name="does_not_follow_schema",
            wow_dir_name="retail",
        )

        with pytest.raises(ConfigSchemaException):
            env.run_wap(*run_args)
Пример #22
0
    def test_config_version_too_many_of_same_type(
        self, env: Environment, config_file_name: str, run_args: Iterable[str]
    ) -> None:
        env.prepare(
            project_dir_name="basic",
            config_file_name=config_file_name,
            wow_dir_name="retail",
        )

        with pytest.raises(ConfigSemanticException, match=r"at most one \w+ version"):
            env.run_wap(*run_args)
Пример #23
0
def test_package_toc_tag_overwritten(env: Environment,
                                     config_file_name: str) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name=config_file_name,
        wow_dir_name="retail",
    )

    result = env.run_wap("package")

    assert "Overwriting wap-provided tag" in result.stderr
Пример #24
0
def test_dev_install_without_package(env: Environment,
                                     wow_dir_name: str) -> None:
    env.prepare(project_dir_name="basic",
                config_file_name="basic",
                wow_dir_name=wow_dir_name)

    assert env.wow_dir_path

    with pytest.raises(DevInstallException,
                       match=r"Package directory .+ not found"):
        env.run_wap("dev-install", "--wow-addons-path", str(env.wow_dir_path))
Пример #25
0
def test_package_config_toc_tag_with_unknown_localizations(
        env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="toc_tags_unknown_localizations",
        wow_dir_name="retail",
    )

    result = env.run_wap("package")

    assert "TOC user-specified tag" in result.stderr
Пример #26
0
def test_dev_install_bad_wow_addons_dir_format(
    env: Environment,
    wow_dir_name: str,
) -> None:
    env.prepare(
        project_dir_name="basic-built",
        config_file_name="basic",
        wow_dir_name=wow_dir_name,
    )

    with pytest.raises(BadParameter, match=r"does not look like a WoW addons"):
        env.run_wap("dev-install", "--wow-addons-path", str(env.wow_dir_path))
Пример #27
0
def test_dev_install(
    env: Environment,
    wow_dir_name: str,
    wow_type: str,
    wow_addons_path_from_cli: bool,
    config_path_from_cli: bool,
    use_addon_default_version: bool,
) -> None:

    if use_addon_default_version:
        addon_version = "dev"
        project_dir_name = "basic-built"
    else:
        addon_version = "1.2.3"
        project_dir_name = "basic_built_version_1.2.3"

    env.prepare(
        project_dir_name=project_dir_name,
        config_file_name="basic",
        wow_dir_name=wow_dir_name,
    )

    run_wap_args = ["dev-install", "--json"]
    env_vars: dict[str, str] = {}

    if wow_addons_path_from_cli:
        run_wap_args.extend(["--wow-addons-path", str(env.wow_dir_path)])
    else:
        env_vars[WAP_WOW_ADDONS_PATH_ENVVAR_NAME] = str(env.wow_dir_path)

    if config_path_from_cli:
        run_wap_args.extend(["--config-path", str(DEFAULT_CONFIG_PATH)])
    else:
        env_vars[WAP_CONFIG_PATH_ENVVAR_NAME] = str(DEFAULT_CONFIG_PATH)

    if not use_addon_default_version:
        run_wap_args.extend(["--version", addon_version])

    result = env.run_wap(*run_wap_args, env_vars=env_vars)

    assert not contains_warn_error(result.stderr)

    actual_json_output = json.loads(result.stdout)

    # check the stdout json
    assert set(actual_json_output[wow_type]["installed_dir_paths"]) == {
        (ps(str(env.wow_dir_path / "Dir1")))
    }

    assert fileset(env.project_dir_path / "dist" /
                   f"MyAddon-{addon_version}-{wow_type}") == fileset(
                       env.wow_dir_path)
Пример #28
0
    def test_config_wow_version_bad_format(
        self, env: Environment, run_args: Iterable[str]
    ) -> None:
        env.prepare(
            project_dir_name="basic",
            config_file_name="version_bad_format",
            wow_dir_name="retail",
        )

        with pytest.raises(
            ConfigSemanticException, match=r"WoW versions must be of form"
        ):
            env.run_wap(*run_args)
Пример #29
0
def test_validate_fail(
    env: Environment,
) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="does_not_follow_schema",
    )

    result = env.run_wap("validate", "--json", catch_exceptions=True)

    assert result.exit_code != 0

    assert "is not valid" in result.stderr
Пример #30
0
def test_package_cleanup_on_exception(env: Environment) -> None:
    env.prepare(
        project_dir_name="basic",
        config_file_name="multi_dir_one_not_exist",
        wow_dir_name="retail",
    )

    with pytest.raises(PackageException, match=r"it is not a directory"):
        env.run_wap("package")

    dist_dir = env.project_dir_path / "dist"
    dist_dir_files = list(dist_dir.iterdir())
    assert len(dist_dir_files) == 0