def test_check_rerun_release_koji_build_handler( mock_release_functionality, check_rerun_event_koji_build ): flexmock(KojiBuildJobHelper).should_receive("run_koji_build").and_return( TaskResults(success=True, details={}) ) flexmock(GithubProject).should_receive("get_files").and_return(["foo.spec"]) flexmock(GithubProject).should_receive("get_web_url").and_return( "https://github.com/the-namespace/the-repo" ) flexmock(GithubProject).should_receive("is_private").and_return(False) flexmock(copr_build).should_receive("get_valid_build_targets").and_return( {"fedora-rawhide-x86_64", "fedora-34-x86_64"} ) flexmock(StatusReporterGithubChecks).should_receive("set_status").with_args( state=BaseCommitStatus.pending, description=TASK_ACCEPTED, check_name="production-build:f34", url="", links_to_external_services=None, markdown_content=None, ).once() flexmock(Signature).should_receive("apply_async").once() flexmock(Pushgateway).should_receive("push").twice().and_return() processing_results = SteveJobs().process_message(check_rerun_event_koji_build) event_dict, job, job_config, package_config = get_parameters_from_results( processing_results ) assert event_dict["targets_override"] == ["f34"] assert json.dumps(event_dict) results = run_koji_build_handler( package_config=package_config, event=event_dict, job_config=job_config, ) assert first_dict_value(results["job"])["success"]
def test_pr_comment_production_build_handler(pr_production_build_comment_event): packit_yaml = str( { "specfile_path": "the-specfile.spec", "synced_files": [], "jobs": [ { "trigger": "pull_request", "job": "production_build", "metadata": {"targets": "fedora-rawhide-x86_64", "scratch": "true"}, } ], } ) comment = flexmock(add_reaction=lambda reaction: None) flexmock( GithubProject, full_repo_name="packit-service/hello-world", get_file_content=lambda path, ref: packit_yaml, get_files=lambda ref, filter_regex: ["the-specfile.spec"], get_web_url=lambda: "https://github.com/the-namespace/the-repo", get_pr=lambda pr_id: flexmock( head_commit="12345", get_comment=lambda comment_id: comment ), ) flexmock(Github, get_repo=lambda full_name_or_id: None) config = ServiceConfig() config.command_handler_work_dir = SANDCASTLE_WORK_DIR flexmock(ServiceConfig).should_receive("get_service_config").and_return(config) trigger = flexmock( job_config_trigger_type=JobConfigTriggerType.pull_request, id=123 ) flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger) flexmock(PullRequestModel).should_receive("get_by_id").with_args(123).and_return( trigger ) flexmock(LocalProject, refresh_the_arguments=lambda: None) flexmock(Allowlist, check_and_report=True) flexmock(PullRequestModel).should_receive("get_or_create").with_args( pr_id=9, namespace="packit-service", repo_name="hello-world", project_url="https://github.com/packit-service/hello-world", ).and_return( flexmock(id=9, job_config_trigger_type=JobConfigTriggerType.pull_request) ) flexmock(KojiBuildJobHelper).should_receive("run_koji_build").and_return( TaskResults(success=True, details={}) ) flexmock(GithubProject, get_files="foo.spec") flexmock(GithubProject).should_receive("is_private").and_return(False) flexmock(KojiBuildJobHelper).should_receive("report_status_to_build").with_args( description=TASK_ACCEPTED, state=BaseCommitStatus.pending, url="", ).once() flexmock(Signature).should_receive("apply_async").once() flexmock(Pushgateway).should_receive("push").twice().and_return() pr = flexmock(head_commit="12345") flexmock(GithubProject).should_receive("get_pr").and_return(pr) comment = flexmock() flexmock(pr).should_receive("get_comment").and_return(comment) flexmock(comment).should_receive("add_reaction").with_args("+1").once() processing_results = SteveJobs().process_message(pr_production_build_comment_event) event_dict, job, job_config, package_config = get_parameters_from_results( processing_results ) assert json.dumps(event_dict) results = run_koji_build_handler( package_config=package_config, event=event_dict, job_config=job_config, ) assert first_dict_value(results["job"])["success"]