Exemple #1
0
def test_multiple_repos_bad_default() -> None:
    """Check error for prepare_repository_configurations with a missing default_repo."""
    from valiant.config import Config
    from valiant.repositories import RepositoryConfiguration

    with pytest.raises(ValueError):
        Config.prepare_repository_configurations(
            repository_configurations=[
                RepositoryConfiguration(name="test",
                                        base_url="https://www.example.com"),
                RepositoryConfiguration(
                    name="test2", base_url="https://www.differentexample.com"),
            ],
            default_repository="otter",
        )
Exemple #2
0
def test_bad_config_repeated_repos() -> None:
    """Check error for prepare_repository_configurations with repeated repository entries."""
    from valiant.config import Config
    from valiant.repositories import RepositoryConfiguration

    with pytest.raises(ValueError):
        Config.prepare_repository_configurations(
            repository_configurations=[
                RepositoryConfiguration(name="test",
                                        base_url="https://www.example.com"),
                RepositoryConfiguration(
                    name="test", base_url="https://www.differentexample.com"),
            ],
            default_repository="test",
        )
Exemple #3
0
def test_repository_unsupported_config(
        pypi_config: RepositoryConfiguration) -> None:
    """Ensure that config with an unsupported type is booted ."""
    with pytest.raises(ValueError):
        PyPiRepository(
            RepositoryConfiguration(name="broken",
                                    base_url="http://myrepo.com",
                                    repository_type="maven"))
Exemple #4
0
    def get_pypi_config() -> RepositoryConfiguration:
        """Helper for the central repo.

        Returns:
            A config for the PyPi repo
        """
        return RepositoryConfiguration(name="pypi",
                                       base_url="https://pypi.org/pypi",
                                       repository_type="warehouse")
Exemple #5
0
    def _extract_repo_confs(
        confs: Mapping[str, Union[Mapping, RepositoryConfiguration]]
    ) -> Mapping[str, RepositoryConfiguration]:
        from typing import cast

        repo_confs: Dict[str, RepositoryConfiguration] = {}
        for k, v in confs.items():
            if type(v) is RepositoryConfiguration:
                repo_confs[k] = cast(RepositoryConfiguration, v)
            elif issubclass(type(v), MappingType):
                repo_confs[k] = RepositoryConfiguration(**(cast(Mapping, v)))

        return repo_confs
Exemple #6
0
def test_prepare_repository_configurations_auto_default() -> None:
    """Check error for prepare_repository_configurations with no default_repo."""
    from valiant.config import Config
    from valiant.repositories import RepositoryConfiguration

    default, configs = Config.prepare_repository_configurations(
        repository_configurations=[
            RepositoryConfiguration(name="test",
                                    base_url="https://www.example.com"),
        ],
        default_repository=None,
    )

    assert default == "test"
Exemple #7
0
def test_default_config_to_dict(
    tmp_path: Path,
    config_default_builder: ConfigBuilder,
    pypi_repo: RepositoryConfiguration,
    valiant_app_name: str,
    valiant_version: str,
) -> None:
    """Test the to_dict is an accurate representation."""
    d = get_config_instance(config_default_builder).to_dict()["tool"]["valiant"]
    assert d["configuration_dir"] == str(tmp_path / "user_config_dir")
    assert d["cache_dir"] == str(tmp_path / "user_cache_dir")
    assert d["log_dir"] == str(tmp_path / "user_log_dir")

    # Repos
    assert d["default_repository"] == "pypi"
    pypi_dict = pypi_repo.to_dict()
    assert d["repository_configurations"]["pypi"] == pypi_dict
    assert d["repository_configurations"]["pypi"]["base_url"] == pypi_dict["base_url"]
    assert d["repository_configurations"]["pypi"]["name"] == pypi_dict["name"]
    assert (
        d["repository_configurations"]["pypi"]["repository_type"]
        == pypi_dict["repository_type"]
    )
    assert d["repository_configurations"]["pypi"]["username"] == pypi_dict["username"]
    assert d["repository_configurations"]["pypi"]["password"] == pypi_dict["password"]
    assert d["repository_configurations"]["pypi"]["token"] == pypi_dict["token"]

    # Reports
    assert not [i for i in d["default_reports"] if i not in ["basic", "safety", "spdx"]]

    # Logging
    assert not d["logging_configuration_file"]

    # Requests Cache
    assert d["requests_cache"]["backend"] == "sqlite"
    assert d["requests_cache"]["expire_after"] == 86400
    assert (
        d["requests_cache"]["file"]
        == f"$cache_dir/{valiant_app_name}-{valiant_version}-requests-cache"
    )