def test_basic_local_update_direct_push(upstream_distgit_remote, mock_remote_functionality_upstream): """ basic propose-update test: mock remote API, use local upstream and dist-git """ upstream, distgit, remote_dir = upstream_distgit_remote with cwd(upstream): c = get_test_config() pc = get_local_package_config(str(upstream)) pc.upstream_project_url = str(upstream) pc.dist_git_clone_path = str(distgit) up_lp = LocalProject(working_dir=str(upstream)) api = PackitAPI(c, pc, up_lp) api.sync_release("master", "0.1.0", create_pr=False) remote_dir_clone = Path(f"{remote_dir}-clone") subprocess.check_call( ["git", "clone", remote_dir, str(remote_dir_clone)], cwd=str(remote_dir_clone.parent), ) spec = get_specfile(str(remote_dir_clone / "beer.spec")) assert spec.get_version() == "0.1.0" assert (remote_dir_clone / "README.packit").is_file()
def test_single_message(github_release_fedmsg, mock_remote_functionality_upstream): u, d = mock_remote_functionality_upstream conf = get_test_config() api = PackitBotAPI(conf) flexmock(Repo).should_receive("clone_from").and_return(git.Repo(str(u))) api.sync_upstream_release_with_fedmsg(github_release_fedmsg) assert (d / TARBALL_NAME).is_file() spec = get_specfile(str(d / "beer.spec")) assert spec.get_version() == "0.1.0"
def test_basic_local_update_from_downstream( downstream_n_distgit, mock_downstream_remote_functionality): flexmock(LocalProject, _parse_namespace_from_git_url=lambda: None) u, d = downstream_n_distgit with cwd(u): c = get_test_config() pc = get_local_package_config(str(u)) pc.upstream_project_url = str(u) pc.downstream_project_url = str(d) up_lp = LocalProject(path_or_url=str(u)) api = PackitAPI(c, pc, up_lp) api.sync_from_downstream("master", "master", True) assert (u / "beer.spec").is_file() spec = get_specfile(str(u / "beer.spec")) assert spec.get_version() == "0.0.0"
def test_basic_local_update_without_patching( sourcegit_n_distgit, mock_patching, mock_remote_functionality_sourcegit, api_instance_source_git, ): """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """ sourcegit, distgit = sourcegit_n_distgit api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0") assert (distgit / TARBALL_NAME).is_file() spec = get_specfile(str(distgit / "beer.spec")) assert spec.get_version() == "0.1.0"
def test_basic_local_update(upstream_n_distgit, mock_remote_functionality_upstream): """ basic propose-update test: mock remote API, use local upstream and dist-git """ u, d = upstream_n_distgit with cwd(u): c = get_test_config() pc = get_local_package_config(str(u)) pc.upstream_project_url = str(u) pc.downstream_project_url = str(d) up_lp = LocalProject(path_or_url=str(u)) api = PackitAPI(c, pc, up_lp) api.sync_release("master", "0.1.0") assert (d / TARBALL_NAME).is_file() spec = get_specfile(str(d / "beer.spec")) assert spec.get_version() == "0.1.0"
def test_basic_local_update_empty_patch(sourcegit_n_distgit, mock_remote_functionality_sourcegit, api_instance_source_git): """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """ sourcegit, distgit = sourcegit_n_distgit api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0") assert (distgit / TARBALL_NAME).is_file() spec = get_specfile(str(distgit / "beer.spec")) assert spec.get_version() == "0.1.0" spec_package_section = "\n".join(spec.spec_content.sections["%package"]) assert "# PATCHES FROM SOURCE GIT" not in spec_package_section assert not spec.patches["applied"] assert not spec.patches["not_applied"]
def test_basic_local_update(upstream_n_distgit, mock_remote_functionality_upstream): """ basic propose-update test: mock remote API, use local upstream and dist-git """ u, d = upstream_n_distgit with cwd(u): c = get_test_config() pc = get_local_package_config(str(u)) pc.upstream_project_url = str(u) pc.dist_git_clone_path = str(d) up_lp = LocalProject(working_dir=str(u)) api = PackitAPI(c, pc, up_lp) api.sync_release("master", "0.1.0") assert (d / TARBALL_NAME).is_file() spec = get_specfile(str(d / "beer.spec")) assert spec.get_version() == "0.1.0" 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
def test_basic_local_update_patch_content(sourcegit_n_distgit, mock_remote_functionality_sourcegit, api_instance_source_git): """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """ sourcegit, distgit = sourcegit_n_distgit source_file = sourcegit / "big-source-file.txt" source_file.write_text("new changes") git_add_and_commit(directory=sourcegit, message="source change") api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0") spec = get_specfile(str(distgit / "beer.spec")) spec_package_section = "\n".join(spec.spec_content.sections["%package"]) assert "Patch0001: 0001" in spec_package_section assert "Patch0002: 0002" not in spec_package_section # no empty patches git_diff = subprocess.check_output(["git", "diff", "HEAD~", "HEAD"], cwd=distgit).decode() assert "-Version: 0.0.0\n+Version: 0.1.0" in git_diff assert "+# PATCHES FROM SOURCE GIT:" in git_diff assert ( "-* Mon Feb 24 2019 Tomas Tomecek <*****@*****.**> - 0.0.0-1\n" "-- No brewing, yet.\n" "+* Mon Feb 25 2019 Tomas Tomecek <*****@*****.**> - 0.1.0-1\n" "+- Initial brewing" in git_diff) # direct diff in the synced file assert ("diff --git a/.packit.yaml b/.packit.yaml\n" "new file mode 100644" in git_diff) assert "--- /dev/null\n" "+++ b/.packit.yaml" in git_diff # diff of the synced file should not be in the patch assert ("+diff --git a/.packit.yaml b/.packit.yaml\n" "+new file mode 100644\n" not in git_diff) # diff of the source file (not synced) has to be in the patch assert ("patch\n" "@@ -0,0 +1,9 @@\n" "+diff --git a/big-source-file.txt b/big-source-file.txt\n" in git_diff) assert ("+--- a/big-source-file.txt\n" "++++ b/big-source-file.txt\n" "+@@ -1,2 +1 @@\n" "+-This is a testing file\n" "+-containing some text.\n" "++new changes\n" in git_diff) # diff of the source files (not synced) should not be directly in the git diff assert ("--- a/big-source-file.txt\n" "+++ b/big-source-file.txt\n" "@@ -1,2 +1 @@\n" "-This is a testing file\n" "-containing some text.\n" "+new changes\n" not in git_diff)