def test_parse_testing_farm_notification_error(self, testing_farm_notification, testing_farm_results_error): request_id = "129bd474-e4d3-49e0-9dec-d994a99feebc" flexmock(TestingFarmJobHelper).should_receive( "get_request_details").with_args(request_id).and_return( testing_farm_results_error) flexmock(TFTTestRunModel).should_receive( "get_by_pipeline_id").and_return( flexmock( job_trigger=flexmock().should_receive( "get_trigger_object").and_return( PullRequestModel(pr_id=10)).once().mock(), data={ "base_project_url": "https://github.com/packit/packit" }, )) event_object = Parser.parse_event(testing_farm_notification) assert isinstance(event_object, TestingFarmResultsEvent) assert event_object.pipeline_id == request_id assert event_object.result == TestingFarmResult.error assert event_object.project_url == "https://github.com/packit/packit" assert event_object.commit_sha == "e7e3c8b688403048e7aefa64c19b79e89fe764df" assert event_object.summary == "something went wrong" assert event_object.compose == "Fedora-32" assert event_object.copr_build_id == "1810530" assert event_object.copr_chroot == "fedora-32-x86_64" assert event_object.tests assert event_object.db_trigger assert isinstance(event_object.project, GithubProject) assert event_object.project.full_repo_name == "packit/packit"
def test_parse_testing_farm_results(self, testing_farm_results): flexmock(TFTTestRunModel).should_receive( "get_by_pipeline_id").and_return( flexmock(job_trigger=flexmock().should_receive( "get_trigger_object").and_return(PullRequestModel( pr_id=10)).once().mock())) event_object = Parser.parse_event(testing_farm_results) assert isinstance(event_object, TestingFarmResultsEvent) assert event_object.trigger == TheJobTriggerType.testing_farm_results assert event_object.pipeline_id == "43e310b6-c1f1-4d3e-a95c-6c1eca235296" assert event_object.result == TestingFarmResult.passed assert event_object.repo_namespace == "packit-service" assert event_object.repo_name == "hello-world" assert event_object.git_ref == "pull/10/head" assert (event_object.project_url == "https://github.com/packit-service/hello-world") assert event_object.commit_sha == "46597d9b66a1927b50376f73bdb1ec1a5757c330" assert event_object.message == "Error or info message to display" assert event_object.environment == "Fedora-Cloud-Base-29-1.2.x86_64.qcow2" assert event_object.copr_repo_name == "packit/packit-service-hello-world-10-stg" assert event_object.copr_chroot == "fedora-29-x86_64" assert event_object.tests assert { TestResult( name="test1", result=TestingFarmResult.failed, log_url="https://somewhere.com/43e310b6/artifacts/test1.log", ), TestResult( name="test2", result=TestingFarmResult.passed, log_url="https://somewhere.com/43e310b6/artifacts/test2.log", ), } == set(event_object.tests) assert event_object.db_trigger assert isinstance(event_object.project, GithubProject) assert event_object.project.full_repo_name == "packit-service/hello-world" assert (not event_object. base_project # With Github app, we cannot work with fork repo ) flexmock(PackageConfigGetter).should_receive( "get_package_config_from_repo").with_args( base_project=None, project=event_object.project, pr_id=10, reference="46597d9b66a1927b50376f73bdb1ec1a5757c330", fail_when_missing=False, spec_file_path=None, ).and_return(flexmock()).once() assert event_object.package_config
def test_get_logs(client): chroot = "foo-1-x86_64" state = "pending" build_id = 2 project = GitProjectModel() project.namespace = "john-foo" project.repo_name = "bar" pr = PullRequestModel() pr.pr_id = 234 pr.project = project srpm_build = SRPMBuildModel() srpm_build.logs = "asd<br>qwe" c = CoprBuildModel() c.target = chroot c.build_id = str(build_id) c.srpm_build = srpm_build c.status = state c.web_url = ( "https://copr.fedorainfracloud.org/coprs/john-foo-bar/john-foo-bar/build/2/" ) c.build_logs_url = "https://localhost:5000/build/2/foo-1-x86_64/logs" flexmock(CoprBuildModel).should_receive("get_by_id").and_return(c) flexmock(CoprBuildModel).should_receive("get_project").and_return(project) flexmock(CoprBuildModel).should_receive("job_trigger").and_return( flexmock(get_trigger_object=lambda: pr)) url = f"/copr-build/1/logs" logs_url = get_copr_build_log_url_from_flask(1) assert logs_url.endswith(url) resp = client.get(url) expected = ( "<html><head>" f"<title>COPR build {project.namespace}/{project.repo_name}:" f" PR #{pr.pr_id}</title></head><body>" f"COPR build ID: {c.build_id}<br>" f"Submitted: {optional_time(c.build_submitted_time)}<br>" f"State: {c.status}<br><br>" f'Build web interface URL: <a href="{c.web_url}">{c.web_url}</a><br>' f'Build logs: <a href="{c.build_logs_url}">{c.build_logs_url}</a><br>' "SRPM creation logs:<br><br>" f"<pre>{c.srpm_build.logs}</pre>" "<br></body></html>") assert resp.data == expected.encode()
def test_get_logs(client): chroot = "foo-1-x86_64" state = "success" build_id = 2 project = GitProjectModel() project.namespace = "john-foo" project.repo_name = "bar" pr = PullRequestModel() pr.pr_id = 234 pr.project = project srpm = SRPMBuildModel() srpm.url = "https://some.random.copr.subdomain.org/my_srpm.srpm" c = CoprBuildModel() c.target = chroot c.build_id = str(build_id) c.srpm_build_id = 11 c.status = state c.srpm_build = srpm c.web_url = ( "https://copr.fedorainfracloud.org/coprs/john-foo-bar/john-foo-bar/build/2/" ) c.build_logs_url = "https://localhost:5000/build/2/foo-1-x86_64/logs" c.owner = "packit" c.project_name = "example_project" flexmock(CoprBuildModel).should_receive("get_by_id").and_return(c) flexmock(CoprBuildModel).should_receive("get_project").and_return(project) flexmock(CoprBuildModel).should_receive("job_trigger").and_return( flexmock(get_trigger_object=lambda: pr)) url = "/copr-build/1" logs_url = get_copr_build_info_url_from_flask(1) assert logs_url.endswith(url) resp = client.get(url).data.decode() assert f"srpm-build/{c.srpm_build_id}/logs" in resp assert c.web_url in resp assert c.build_logs_url in resp assert c.target in resp assert "Status: success" in resp assert "You can install" in resp assert "Download SRPM" in resp assert srpm.url in resp
def mock_pr_functionality(request): packit_yaml = ( "{'specfile_path': 'the-specfile.spec', 'synced_files': [], 'jobs':" + str(request.param) + "}" ) flexmock( GithubProject, full_repo_name="packit/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"), ) 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 = JobTriggerModel(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(JobTriggerModel).should_receive("get_by_id").with_args(123456).and_return( trigger ) flexmock(trigger).should_receive("get_trigger_object").and_return( PullRequestModel(pr_id=123) ) flexmock(PullRequestModel).should_receive("get_or_create").with_args( pr_id=123, namespace="packit", repo_name="hello-world", project_url="https://github.com/packit/hello-world", ).and_return( flexmock(id=12, job_config_trigger_type=JobConfigTriggerType.pull_request) ) flexmock(JobTriggerModel).should_receive("get_or_create").and_return( flexmock(id=123456) )
def test_get_logs(client): chroot = "foo-1-x86_64" state = "pending" build_id = 2 project = GitProjectModel() project.namespace = "john-foo" project.repo_name = "bar" pr = PullRequestModel() pr.pr_id = 234 pr.project = project c = CoprBuildModel() c.target = chroot c.build_id = str(build_id) c.srpm_build_id = 11 c.status = state c.web_url = ( "https://copr.fedorainfracloud.org/coprs/john-foo-bar/john-foo-bar/build/2/" ) c.build_logs_url = "https://localhost:5000/build/2/foo-1-x86_64/logs" flexmock(CoprBuildModel).should_receive("get_by_id").and_return(c) flexmock(CoprBuildModel).should_receive("get_project").and_return(project) flexmock(CoprBuildModel).should_receive("job_trigger").and_return( flexmock(get_trigger_object=lambda: pr)) url = "/copr-build/1" logs_url = get_copr_build_info_url_from_flask(1) assert logs_url.endswith(url) resp = client.get(url).data.decode() assert f"srpm-build/{c.srpm_build_id}/logs" in resp assert c.web_url in resp assert c.build_logs_url in resp assert c.target in resp