|
6 | 6 | from flexmock import flexmock
|
7 | 7 |
|
8 | 8 | from ogr import PagureService
|
9 |
| -from ogr.abstract import AccessLevel |
| 9 | +from ogr.abstract import AccessLevel, PRStatus |
10 | 10 | from ogr.services.pagure import PagureProject
|
11 | 11 | from packit.config import (
|
12 | 12 | CommonPackageConfig,
|
|
18 | 18 | )
|
19 | 19 |
|
20 | 20 | from packit.config.commands import TestCommandConfig
|
| 21 | +from packit.config.requirements import RequirementsConfig, LabelRequirementsConfig |
21 | 22 | from packit_service.config import ServiceConfig
|
22 | 23 | from packit_service.models import CoprBuildTargetModel
|
23 | 24 | from packit_service.worker.checker.copr import (
|
|
27 | 28 | from packit_service.worker.checker.distgit import (
|
28 | 29 | IsUpstreamTagMatchingConfig,
|
29 | 30 | PermissionOnDistgit,
|
| 31 | + LabelsOnDistgitPR, |
30 | 32 | )
|
31 | 33 | from packit_service.worker.checker.koji import (
|
32 | 34 | IsJobConfigTriggerMatching as IsJobConfigTriggerMatchingKoji,
|
@@ -992,3 +994,61 @@ def test_koji_check_allowed_accounts(
|
992 | 994 | package_config, job_config, distgit_push_event.get_dict()
|
993 | 995 | )
|
994 | 996 | assert checker.check_allowed_accounts(allowed_pr_authors, account) == should_pass
|
| 997 | + |
| 998 | + |
| 999 | +@pytest.mark.parametrize( |
| 1000 | + "pr_labels,labels_present,labels_absent,should_pass", |
| 1001 | + ( |
| 1002 | + ([], [], [], True), |
| 1003 | + (["allowed-1"], [], ["skip-ci"], True), |
| 1004 | + (["allowed-1"], ["allowed-1"], ["skip-ci"], True), |
| 1005 | + (["allowed-1"], ["allowed-1"], ["skip-ci"], True), |
| 1006 | + (["allowed-1", "skip-ci"], ["allowed-1"], ["skip-ci"], False), |
| 1007 | + ), |
| 1008 | +) |
| 1009 | +def test_labels_on_distgit_pr( |
| 1010 | + distgit_push_event, |
| 1011 | + pr_labels, |
| 1012 | + labels_present, |
| 1013 | + labels_absent, |
| 1014 | + should_pass, |
| 1015 | +): |
| 1016 | + jobs = [ |
| 1017 | + JobConfig( |
| 1018 | + type=JobType.koji_build, |
| 1019 | + trigger=JobConfigTriggerType.commit, |
| 1020 | + packages={ |
| 1021 | + "package": CommonPackageConfig( |
| 1022 | + dist_git_branches=["f36"], |
| 1023 | + require=RequirementsConfig( |
| 1024 | + LabelRequirementsConfig( |
| 1025 | + absent=labels_absent, |
| 1026 | + present=labels_present, |
| 1027 | + ) |
| 1028 | + ), |
| 1029 | + ) |
| 1030 | + }, |
| 1031 | + ), |
| 1032 | + ] |
| 1033 | + |
| 1034 | + package_config = PackageConfig( |
| 1035 | + jobs=jobs, |
| 1036 | + packages={"package": CommonPackageConfig()}, |
| 1037 | + ) |
| 1038 | + job_config = jobs[0] |
| 1039 | + |
| 1040 | + flexmock(PagureProject).should_receive("get_pr_list").and_return( |
| 1041 | + [ |
| 1042 | + flexmock( |
| 1043 | + id=5, |
| 1044 | + head_commit="ad0c308af91da45cf40b253cd82f07f63ea9cbbf", |
| 1045 | + status=PRStatus.open, |
| 1046 | + labels=pr_labels, |
| 1047 | + ) |
| 1048 | + ] |
| 1049 | + ) |
| 1050 | + |
| 1051 | + checker = LabelsOnDistgitPR( |
| 1052 | + package_config, job_config, distgit_push_event.get_dict() |
| 1053 | + ) |
| 1054 | + assert checker.pre_check() == should_pass |
0 commit comments