forked from packit/packit-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish OpenScanHub integration prototype
Fixes packit#2463
- Loading branch information
1 parent
632aea8
commit 2d0da30
Showing
3 changed files
with
270 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,77 @@ | ||
# Copyright Contributors to the Packit project. | ||
# SPDX-License-Identifier: MIT | ||
|
||
from flexmock import flexmock | ||
|
||
from packit.api import PackitAPI | ||
from packit_service.models import CoprBuildTargetModel | ||
from packit_service.worker.handlers import CoprBuildEndHandler | ||
from packit_service.worker.handlers import copr | ||
from packit.config import JobType, JobConfigTriggerType | ||
from packit_service.models import ( | ||
CoprBuildTargetModel, | ||
ProjectEventModelType, | ||
BuildStatus, | ||
) | ||
from packit_service.worker.events import AbstractCoprBuildEvent | ||
from flexmock import flexmock | ||
from packit_service.worker.handlers import copr | ||
from packit_service.worker.handlers.copr import ScanHelper | ||
from packit_service.worker.helpers.build import CoprBuildJobHelper | ||
|
||
|
||
def test_handle_scan(): | ||
srpm_mock = flexmock(url="https://some-url/my-srpm.src.rpm") | ||
flexmock(CoprBuildTargetModel).should_receive("get_by_build_id").and_return( | ||
flexmock( | ||
get_srpm_build=lambda: srpm_mock, | ||
target="fedora-rawhide-x86_64", | ||
get_project_event_model=lambda: None, | ||
) | ||
) | ||
flexmock(AbstractCoprBuildEvent).should_receive("from_event_dict").and_return( | ||
flexmock(chroot="fedora-rawhide-x86_64", build_id="123") | ||
flexmock(chroot="fedora-rawhide-x86_64", build_id="123", pr_id=12) | ||
) | ||
flexmock(copr).should_receive("download_file").twice().and_return(True) | ||
|
||
base_copr_model = flexmock(get_srpm_build=lambda: flexmock(url="base-srpm-url")) | ||
|
||
flexmock(copr).should_receive("download_file").once().and_return(True) | ||
flexmock(PackitAPI).should_receive("run_osh_build").once() | ||
flexmock(CoprBuildTargetModel).should_receive("get_all_by").with_args( | ||
commit_sha="abcdef", | ||
project_name="commit-project", | ||
owner="user-123", | ||
target="fedora-rawhide-x86_64", | ||
status=BuildStatus.success, | ||
).and_return([base_copr_model]) | ||
|
||
CoprBuildEndHandler( | ||
package_config=flexmock(), | ||
job_config=flexmock(osh_diff_scan_after_copr_build=True), | ||
event={}, | ||
flexmock(PackitAPI).should_receive("run_osh_build").once().and_return( | ||
'{"url": "scan-url"}' | ||
) | ||
|
||
flexmock(CoprBuildJobHelper).should_receive("_report") | ||
package_config = flexmock( | ||
get_job_views=lambda: [ | ||
flexmock( | ||
type=JobType.copr_build, | ||
trigger=JobConfigTriggerType.commit, | ||
branch="main", | ||
project="commit-project", | ||
owner="user-123", | ||
) | ||
] | ||
) | ||
|
||
project = flexmock( | ||
get_pr=lambda pr_id: flexmock( | ||
target_branch="main", target_branch_head_commit="abcdef" | ||
) | ||
) | ||
|
||
ScanHelper( | ||
build=flexmock( | ||
id=1, | ||
get_srpm_build=lambda: srpm_mock, | ||
target="fedora-rawhide-x86_64", | ||
get_project_event_model=lambda: flexmock( | ||
type=ProjectEventModelType.pull_request, | ||
get_project_event_object=lambda: flexmock(), | ||
), | ||
), | ||
copr_build_helper=CoprBuildJobHelper( | ||
service_config=flexmock(), | ||
package_config=package_config, | ||
project=project, | ||
metadata=flexmock(pr_id=12), | ||
db_project_event=flexmock(get_project_event_object=lambda: None), | ||
job_config=flexmock(), | ||
), | ||
).handle_scan() |