def test_get_builds(upstream_n_distgit, expected_results, br_list, number_of_builds): u, d = upstream_n_distgit from bodhi.client.bindings import BodhiClient c = get_test_config() pc = get_local_package_config(str(u)) pc.downstream_project_url = str(d) pc.upstream_project_url = str(u) dg = DistGit(c, pc) pc = get_local_package_config(str(u)) flexmock(BodhiClient).should_receive("latest_builds").and_return( BODHI_LATEST_BUILDS ) status = Status(c, pc, u, dg) flexmock( PagureProject, get_git_urls=lambda: {"git": "foo.git"}, fork_create=lambda: None, get_fork=lambda: PagureProject("", "", PagureService()), get_branches=br_list, ) assert status table = status.get_builds(number_of_builds) assert table assert len(table.keys()) == number_of_builds assert table == expected_results
def mock_remote_functionality(distgit: Path, upstream: Path): def mocked_create_pr(*args, **kwargs): return PullRequestReadOnly( title="", id=42, status=PRStatus.open, url="", description="", author="", source_branch="", target_branch="", created=datetime.datetime(1969, 11, 11, 11, 11, 11, 11), ) flexmock(GithubService) github_service = GithubService() flexmock( GithubService, get_project=lambda repo, namespace: GithubProject( "also-not", github_service, "set", github_repo=flexmock() ), ) flexmock( PagureProject, get_git_urls=lambda: {"git": DOWNSTREAM_PROJECT_URL}, fork_create=lambda: None, get_fork=lambda: PagureProject("", "", PagureService()), create_pr=mocked_create_pr, ) flexmock( GithubProject, get_git_urls=lambda: {"git": UPSTREAM_PROJECT_URL}, fork_create=lambda: None, ) flexmock(PagureUser, get_username=lambda: "packito") dglp = LocalProject( working_dir=distgit, git_url="https://packit.dev/rpms/beer", git_service=PagureService(), ) flexmock( DistGit, push_to_fork=lambda *args, **kwargs: None, # let's not hammer the production lookaside cache webserver is_archive_in_lookaside_cache=lambda archive_path: False, local_project=dglp, ) flexmock(DistGit).should_receive("existing_pr").and_return(None) def mocked_new_sources(sources=None): if not Path(sources).is_file(): raise RuntimeError("archive does not exist") flexmock(PkgTool, new_sources=mocked_new_sources) flexmock(PackitAPI, init_kerberos_ticket=lambda: None) pc = get_local_package_config(str(upstream)) pc.dist_git_clone_path = str(distgit) pc.upstream_project_url = str(upstream) return upstream, distgit
def test_set_status_pagure( project, commit_sha, pr_id, pr_object, state, description, check_name, url, state_to_set, uid, ): project = PagureProject(None, None, PagureService()) reporter = StatusReporter.get_instance(project=project, commit_sha=commit_sha, pr_id=pr_id) act_upon = flexmock( pr_object.source_project) if pr_id else flexmock(PagureProject) act_upon.should_receive("set_commit_status").with_args(commit_sha, state_to_set, url, description, check_name, trim=True).once() if pr_id is not None: flexmock(PagureProject).should_receive("get_pr").with_args( pr_id).and_return(pr_object) reporter.set_status(state, description, check_name, url)
def mock_upstream_remote_functionality(upstream_n_distgit): u, d = upstream_n_distgit def mocked_pr_create(*args, **kwargs): return PullRequest( title="", id=42, status=PRStatus.open, url="", description="", author="", source_branch="", target_branch="", created=datetime.datetime(1969, 11, 11, 11, 11, 11, 11), ) flexmock( PagureProject, get_git_urls=lambda: {"git": str(d)}, fork_create=lambda: None, get_fork=lambda: PagureProject("", "", PagureService()), pr_create=mocked_pr_create, ) def mock_download_remote_sources(): """ mock download of the remote archive and place it into dist-git repo """ tarball_path = d / TARBALL_NAME hops_filename = "hops" hops_path = d / hops_filename hops_path.write_text("Cascade\n") subprocess.check_call( ["tar", "-cf", str(tarball_path), hops_filename], cwd=d) flexmock(SpecFile, download_remote_sources=mock_download_remote_sources) flexmock(GithubService, get_project=lambda repo, namespace: flexmock()) flexmock( DistGit, push_to_fork=lambda *args, **kwargs: None, # let's not hammer the production lookaside cache webserver is_archive_in_lookaside_cache=lambda archive_path: False, build=lambda scratch: None, ) def mocked_new_sources(sources=None): if not Path(sources).is_file(): raise RuntimeError("archive does not exist") flexmock(FedPKG, init_ticket=lambda x=None: None, new_sources=mocked_new_sources) pc = get_local_package_config(str(u)) pc.downstream_project_url = str(d) pc.upstream_project_url = str(u) # https://stackoverflow.com/questions/45580215/using-flexmock-on-python-modules flexmock(sys.modules["packit.bot_api"]).should_receive( "get_packit_config_from_repo").and_return(pc) return u, d
def test_downstream_pr(upstream_n_distgit, pr_list, number_prs): u, d = upstream_n_distgit c = get_test_config() pc = get_local_package_config(str(u)) pc.downstream_project_url = str(d) pc.upstream_project_url = str(u) dg = DistGit(c, pc) pc = get_local_package_config(str(u)) status = Status(c, pc, u, dg) flexmock( PagureProject, get_git_urls=lambda: {"git": "foo.git"}, fork_create=lambda: None, get_fork=lambda: PagureProject("", "", PagureService()), get_pr_list=pr_list, ) assert status table = status.get_downstream_prs(number_prs) assert table assert len(table) == number_prs
"https://some-url/packit-service/ogr", {"some-url": GithubService}, None, True, GithubProject( namespace="packit-service", repo="ogr", service=GithubService() ), ), ( "https://github.com/packit-service/ogr", {"github.com": PagureService}, None, True, PagureProject( namespace="packit-service", repo="ogr", service=PagureService(instance_url="https://github.com"), ), ), ( "https://src.fedoraproject.org/rpms/python-ogr", None, None, True, PagureProject( namespace="rpms", repo="python-ogr", service=PagureService(instance_url="https://src.fedoraproject.org"), ), ), (