Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(
dist_git_base_url="https://packit.dev/",
downstream_package_name="packit",
dist_git_namespace="awesome",
synced_files=SyncFilesConfig(
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
def test_package_config_parse_error(raw):
with pytest.raises(Exception):
PackageConfig.get_from_dict(raw_dict=raw)
def test_package_config_validate(raw, is_valid):
if not is_valid:
with pytest.raises((ValidationError, ValueError)):
PackageConfig.get_from_dict(raw)
else:
PackageConfig.get_from_dict(raw)
def test_package_config_overrides(raw, expected):
package_config = PackageConfig.get_from_dict(raw_dict=raw)
assert package_config == expected
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)
def validate(self) -> str:
""" Create output for PackageConfig validation."""
schema_errors = 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"
for field_name, errors in schema_errors.items():
def parse_loaded_config(
loaded_config: dict,
config_file_path: Optional[str] = None,
repo_name: Optional[str] = None,
spec_file_path: Optional[str] = None,
) -> PackageConfig:
"""Tries to parse the config to PackageConfig."""
logger.debug(f"Package config:\n{json.dumps(loaded_config, indent=4)}")
try:
return PackageConfig.get_from_dict(
raw_dict=loaded_config,
config_file_path=config_file_path,
repo_name=repo_name,
spec_file_path=spec_file_path,
)
except Exception as ex:
logger.error(f"Cannot parse package config. {ex}.")
raise PackitConfigException(f"Cannot parse package config: {ex!r}.")