Пример #1
0
    def validate(self) -> str:
        """ Create output for PackageConfig validation."""
        schema_errors: Union[List[Any], Dict[Any, Any]] = None
        try:
            PackageConfig.get_from_dict(
                self.content,
                config_file_path=str(self.config_file_path),
                spec_file_path=str(
                    get_local_specfile_path(self.config_file_path.parent)),
            )
        except ValidationError as e:
            schema_errors = e.messages
        except PackitConfigException as e:
            return str(e)

        if not schema_errors:
            return f"{self.config_file_path.name} is valid and ready to be used"

        output = f"{self.config_file_path.name} does not pass validation:\n"
        if isinstance(schema_errors, list):
            output += "\n".join(map(str, schema_errors))
            return output

        for field_name, errors in schema_errors.items():
            output += self.validate_get_field_output(errors, field_name)
        return output
Пример #2
0
def test_dist_git_package_url():
    di = {
        "dist_git_base_url": "https://packit.dev/",
        "downstream_package_name": "packit",
        "dist_git_namespace": "awesome",
        "synced_files": ["fedora/foobar.spec"],
        "specfile_path": "fedora/package.spec",
        "create_pr": False,
    }
    new_pc = PackageConfig.get_from_dict(di)
    pc = PackageConfig(
        dist_git_base_url="https://packit.dev/",
        downstream_package_name="packit",
        dist_git_namespace="awesome",
        synced_files=SyncFilesConfig(files_to_sync=[
            SyncFilesItem(src="fedora/foobar.spec", dest="fedora/foobar.spec")
        ]),
        specfile_path="fedora/package.spec",
        create_pr=False,
        jobs=get_default_job_config(),
    )
    assert new_pc.specfile_path.endswith("fedora/package.spec")
    assert pc.specfile_path.endswith("fedora/package.spec")
    assert pc == new_pc
    assert pc.dist_git_package_url == "https://packit.dev/awesome/packit.git"
    assert new_pc.dist_git_package_url == "https://packit.dev/awesome/packit.git"
    assert not pc.create_pr
Пример #3
0
def test_package_config_parse(raw, expected):
    package_config = PackageConfig.get_from_dict(raw_dict=raw)
    assert package_config
    # tests for https://github.com/packit-service/packit-service/pull/342
    if expected.jobs:
        for j in package_config.jobs:
            assert j.type
    assert package_config == expected
Пример #4
0
    def validate(self) -> str:
        """Create output for PackageConfig validation."""
        schema_errors: Union[List[Any], Dict[Any, Any]] = None
        config = None
        try:
            config = PackageConfig.get_from_dict(
                self.content,
                config_file_path=str(self.config_file_path),
                spec_file_path=str(
                    get_local_specfile_path(self.config_file_path.parent)),
            )
        except ValidationError as e:
            schema_errors = e.messages
        except PackitConfigException as e:
            return str(e)

        specfile_path = self.content.get("specfile_path", None)
        if specfile_path and not Path(specfile_path).is_file():
            logger.warning(
                f"The spec file you defined ({specfile_path}) is not "
                f"present in the repository. If it's being generated "
                f"dynamically, you can verify the functionality by "
                f"running `packit srpm` to create an SRPM "
                f"from the current checkout. If it's not being generated, "
                f"please make sure the path is correct and "
                f"the file is present.")

        synced_files_errors = []
        if config:
            synced_files_errors = [
                f for f in iter_srcs(config.files_to_sync)
                if not Path(f).exists()
            ]

        output = f"{self.config_file_path.name} does not pass validation:\n"

        if schema_errors:
            if isinstance(schema_errors, list):
                output += "\n".join(map(str, schema_errors))
            else:
                for field_name, errors in schema_errors.items():
                    output += self.validate_get_field_output(
                        errors, field_name)

        if synced_files_errors:
            output += "The following {} configured to be synced but {} not exist: {}\n".format(
                *((
                    "paths are",
                    "do",
                ) if (len(synced_files_errors) > 1) else ("path is", "does")),
                ", ".join(synced_files_errors),
            )

        if schema_errors or synced_files_errors:
            return output
        else:
            return f"{self.config_file_path.name} is valid and ready to be used"
Пример #5
0
def test_notifications_section():
    pc = PackageConfig.get_from_dict({"specfile_path": "package.spec"})
    assert pc.notifications.pull_request.successful_build
Пример #6
0
def test_package_config_upstream_and_downstream_package_names(raw, expected):
    package_config = PackageConfig.get_from_dict(raw_dict=raw,
                                                 repo_name="package")
    assert package_config
    assert package_config == expected
Пример #7
0
def test_package_config_overrides_bad(raw, err_message):
    with pytest.raises(ValidationError) as ex:
        PackageConfig.get_from_dict(raw_dict=raw)
    assert err_message in str(ex)
Пример #8
0
def test_package_config_overrides(raw, expected):
    package_config = PackageConfig.get_from_dict(raw_dict=raw)
    assert package_config == expected
Пример #9
0
def test_package_config_parse_error(raw):
    with pytest.raises(Exception):
        PackageConfig.get_from_dict(raw_dict=raw)
Пример #10
0
def test_package_config_validate_unknown_key(raw, is_valid):
    if not is_valid:
        with pytest.raises((ValidationError, ValueError)):
            PackageConfig.get_from_dict(raw)
    else:
        PackageConfig.get_from_dict(raw)
Пример #11
0
def test_package_config_specilfe_not_present_not_raise(raw):
    assert PackageConfig.get_from_dict(raw_dict=raw)
Пример #12
0
def test_package_config_specfile_not_present_raise(raw):
    with pytest.raises(PackitConfigException):
        PackageConfig.get_from_dict(raw_dict=raw)