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_allowed_gpg_keys_not_allowed(
allowed_gpg_keys, api_instance_source_git: PackitAPI, gnupg_key_fingerprint: str
):
api_instance_source_git.up.local_project.git_repo.git.commit(
message="signed commit", gpg_sign=gnupg_key_fingerprint, allow_empty=True
)
api_instance_source_git.up.allowed_gpg_keys = allowed_gpg_keys
with pytest.raises(PackitException) as ex:
api_instance_source_git.up.check_last_commit()
assert "not signed" in str(ex)
def mocked_new_sources(sources=None):
if not Path(sources).is_file():
raise RuntimeError("archive does not exist")
flexmock(FedPKG, new_sources=mocked_new_sources)
flexmock(PackitAPI, init_kerberos_ticket=lambda: None)
flexmock(
DistGit,
push_to_fork=lambda *args, **kwargs: None,
is_archive_in_lookaside_cache=lambda archive_path: False,
upload_to_lookaside_cache=lambda path: None,
download_upstream_archive=lambda: "the-archive",
)
flexmock(
PackitAPI,
push_and_create_pr=lambda pr_title, pr_description, dist_git_branch: None,
)
pc = get_local_package_config(str(upstream_path))
up_lp = LocalProject(working_dir=str(upstream_path))
c = get_test_config()
api = PackitAPI(c, pc, up_lp)
api._dg = DistGit(c, pc)
api._dg._local_project = LocalProject(working_dir=dist_git_path)
with cwd(upstream_path):
api.sync_release(
"master",
use_local_content=False,
version="179",
force_new_sources=False,
(ActionName.fix_spec, "true", {}, False),
(ActionName.fix_spec, "git this-is-not-a-command", {}, True),
(ActionName.fix_spec, "printenv E", {"E": "e"}, False),
(ActionName.fix_spec, "printenv E", {"X": "e"}, True),
),
)
def test_with_action(
upstream_instance, action: ActionName, command, env_vars: Dict, should_raise
):
_, upstream = upstream_instance
upstream.package_config.actions = {action: command}
try:
upstream.with_action(action, env=env_vars)
except PackitException as ex:
if should_raise:
assert "Command " in str(ex)
assert command.split(" ")[0] in str(ex)
def distgit_with_actions():
return DistGit(
config=flexmock(Config()),
package_config=flexmock(
PackageConfig(
downstream_package_name="beer",
actions={
ActionName.pre_sync: "command --a",
ActionName.get_current_version: "command --b",
},
def call_packit(fnc=None, parameters=None, envs=None, working_dir=None):
working_dir = working_dir or "."
fnc = fnc or packit_base
runner = CliRunner()
envs = envs or {}
parameters = parameters or []
# catch exceptions enables debugger
with cwd(working_dir):
return runner.invoke(fnc, args=parameters, env=envs, catch_exceptions=False)
def test_srpm_command_for_path(upstream_or_distgit_path, tmp_path):
with cwd(tmp_path):
call_real_packit(parameters=["--debug", "srpm", str(upstream_or_distgit_path)])
srpm_path = list(Path.cwd().glob("*.src.rpm"))[0]
assert srpm_path.exists()
build_srpm(srpm_path)
upload_to_lookaside_cache=lambda path: None,
download_upstream_archive=lambda: "the-archive",
)
flexmock(
PackitAPI,
push_and_create_pr=lambda pr_title, pr_description, dist_git_branch: None,
)
pc = get_local_package_config(str(upstream_path))
up_lp = LocalProject(working_dir=str(upstream_path))
c = get_test_config()
api = PackitAPI(c, pc, up_lp)
api._dg = DistGit(c, pc)
api._dg._local_project = LocalProject(working_dir=dist_git_path)
with cwd(upstream_path):
api.sync_release(
"master",
use_local_content=False,
version="179",
force_new_sources=False,
create_pr=True,
)
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git):
sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
mock_spec_download_remote_s(sg_path / "fedora")
create_merge_commit_in_source_git(sg_path)
with cwd(sg_path):
api_instance_source_git.create_srpm(upstream_ref="0.1.0")
srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
assert srpm_path.is_file()
build_srpm(srpm_path)
branches = subprocess.check_output(
["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"], cwd=sg_path
).split(b"\n")
for b in branches:
if b and b.startswith(b"packit-patches-"):
raise AssertionError(
"packit-patches- branch was found - the history shouldn't have been linearized"
)
assert set([x.name for x in sg_path.joinpath("fedora").glob("*.patch")]) == {
"0001-switching-to-amarillo-hops.patch",
"0002-actually-let-s-do-citra.patch",
}
def test_generate_pass(upstream_without_config):
with cwd(upstream_without_config):
assert not (upstream_without_config / ".packit.yaml").is_file()
# This test requires packit on pythonpath
result = call_packit(parameters=["generate"])
assert result.exit_code == 0
assert (upstream_without_config / ".packit.yaml").is_file()
def test_basic_local_update_using_distgit(
cwd_upstream, api_instance, mock_remote_functionality_upstream
):
""" basic propose-update test: mock remote API, use local upstream and dist-git """
u, d, api = api_instance
mock_spec_download_remote_s(d)
api.sync_release("master", "0.1.0")
assert (d / TARBALL_NAME).is_file()
spec = Specfile(d / "beer.spec")
assert spec.get_version() == "0.1.0"
package_section = spec.spec_content.section("%package")
assert package_section[2] == "# some change"
assert package_section[4] == "Name: beer"
assert package_section[5] == "Version: 0.1.0"
assert package_section[6] == "Release: 1%{?dist}"
assert package_section[7] == "Summary: A tool to make you happy"
assert (d / "README.packit").is_file()
# assert that we have changelog entries for both versions
changelog = "\n".join(spec.spec_content.section("%changelog"))
assert "0.0.0" in changelog
assert "0.1.0" in changelog