diff --git a/tests/test_cli_functions.py b/tests/test_cli_functions.py index 7ae486c02..977349afe 100644 --- a/tests/test_cli_functions.py +++ b/tests/test_cli_functions.py @@ -4,7 +4,7 @@ import os from pathlib import Path -from typing import Any, Iterable +from typing import Any, Iterable, Type from unittest import mock import pytest @@ -13,6 +13,8 @@ from commodore import cli from commodore.config import Config +from commodore.package import Package +from commodore.package.template import PackageTemplater from test_catalog import cluster_resp from conftest import RunnerFunc @@ -377,7 +379,7 @@ def test_catalog_compile_cli( mock_login.assert_called() -@mock.patch.object(cli, "sync_packages") +@mock.patch.object(cli, "sync_dependencies") @pytest.mark.parametrize("ghtoken", [None, "ghp_fake-token"]) def test_package_sync_cli( mock_sync_packages, ghtoken, tmp_path: Path, cli_runner: RunnerFunc @@ -391,13 +393,21 @@ def test_package_sync_cli( yaml.safe_dump(["projectsyn/package-foo"], f) def sync_pkgs( - config, pkglist: Path, dry_run: bool, pr_branch: str, pr_labels: Iterable[str] + config, + pkglist: Path, + dry_run: bool, + pr_branch: str, + pr_labels: Iterable[str], + deptype: Type, + templater: Type, ): assert config.github_token == ghtoken assert pkglist.absolute() == pkg_list.absolute() assert not dry_run assert pr_branch == "template-sync" assert list(pr_labels) == [] + assert deptype == Package + assert templater == PackageTemplater mock_sync_packages.side_effect = sync_pkgs result = cli_runner(["package", "sync", "pkgs.yaml"]) diff --git a/tests/test_package_sync.py b/tests/test_dependency_sync.py similarity index 91% rename from tests/test_package_sync.py rename to tests/test_dependency_sync.py index dd597f178..de45cc2ef 100644 --- a/tests/test_package_sync.py +++ b/tests/test_dependency_sync.py @@ -20,7 +20,9 @@ from commodore.config import Config from commodore.gitrepo import GitRepo from commodore.package import Package -from commodore.package import sync +from commodore.package.template import PackageTemplater + +from commodore import dependency_syncer DATA_DIR = Path(__file__).parent.absolute() / "testdata" / "github" @@ -60,7 +62,7 @@ def test_ensure_branch(tmp_path: Path, config: Config, sync_branch: str): assert any(h.name == "template-sync" for h in r.heads) == (sync_branch == "local") - sync.ensure_branch(p, "template-sync") + dependency_syncer.ensure_branch(p, "template-sync") hs = [h for h in r.heads if h.name == "template-sync"] assert len(hs) == 1 @@ -200,12 +202,14 @@ def test_ensure_pr(tmp_path: Path, config: Config, dry_run: bool, pr_exists: boo config.github_token = "ghp_fake-token" p = Package.clone(config, f"file://{tmp_path}/foo.git", "foo") pname = "projectsyn/package-foo" - sync.ensure_branch(p, "template-sync") + dependency_syncer.ensure_branch(p, "template-sync") gh = github.Github(config.github_token) gr = gh.get_repo(pname) - msg = sync.ensure_pr(p, pname, gr, dry_run, "template-sync", ["template-sync"]) + msg = dependency_syncer.ensure_pr( + p, pname, gr, dry_run, "template-sync", ["template-sync"] + ) cu = "update" if pr_exists else "create" @@ -240,12 +244,12 @@ def test_ensure_pr_no_permission(tmp_path: Path, config: Config, pr_exists: bool config.github_token = "ghp_fake-token" p = Package.clone(config, f"file://{tmp_path}/foo.git", "foo") pname = "projectsyn/package-foo" - sync.ensure_branch(p, "template-sync") + dependency_syncer.ensure_branch(p, "template-sync") gh = github.Github(config.github_token) gr = gh.get_repo(pname) - msg = sync.ensure_pr(p, pname, gr, False, "template-sync", []) + msg = dependency_syncer.ensure_pr(p, pname, gr, False, "template-sync", []) cu = "update" if pr_exists else "create" assert ( @@ -274,7 +278,15 @@ def test_sync_packages_package_list_parsing( f.write(package_list_contents) with pytest.raises(click.ClickException) as exc: - sync.sync_packages(config, pkg_list, False, "template-sync", []) + dependency_syncer.sync_dependencies( + config, + pkg_list, + False, + "template-sync", + [], + Package, + PackageTemplater, + ) if ghtoken is None: assert str(exc.value) == "Can't continue, missing GitHub API token." @@ -364,8 +376,14 @@ def test_sync_packages( "commodore.dependency_templater.Templater.repo_url", new_callable=lambda: remote_url, ): - sync.sync_packages( - config, pkg_list, dry_run, "template-sync", ["template-sync"] + dependency_syncer.sync_dependencies( + config, + pkg_list, + dry_run, + "template-sync", + ["template-sync"], + Package, + PackageTemplater, ) expected_call_count = 1 @@ -399,7 +417,9 @@ def test_sync_packages_skip(tmp_path: Path, config: Config, capsys): pkg_list = create_pkg_list(tmp_path) - sync.sync_packages(config, pkg_list, True, "template-sync", []) + dependency_syncer.sync_dependencies( + config, pkg_list, True, "template-sync", [], Package, PackageTemplater + ) captured = capsys.readouterr() assert ( @@ -420,7 +440,9 @@ def test_sync_packages_skip_missing(capsys, tmp_path: Path, config: Config): status=404, ) - sync.sync_packages(config, pkg_list, True, "template-sync", []) + dependency_syncer.sync_dependencies( + config, pkg_list, True, "template-sync", [], Package, PackageTemplater + ) captured = capsys.readouterr() @@ -444,4 +466,4 @@ def test_message_body(tmp_path: Path, raw_message: Union[str, bytes], expected: c = git.Commit(r, binsha=b"\0" * 20, message=raw_message) - assert sync.message_body(c) == expected + assert dependency_syncer.message_body(c) == expected