Skip to content

Commit 21ed277

Browse files
committed
Add a test for onboarding
Signed-off-by: Nikola Forró <nforro@redhat.com>
1 parent 4af02b4 commit 21ed277

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"package": "packit",
3+
"token": "secret-token",
4+
"source": "onboarding"
5+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright Contributors to the Packit project.
2+
# SPDX-License-Identifier: MIT
3+
4+
import json
5+
6+
import pytest
7+
from celery.canvas import Signature
8+
from flexmock import flexmock
9+
from ogr.services.pagure import PagureProject
10+
from packit.api import PackitAPI
11+
from packit.config import Deployment
12+
from packit.distgit import DistGit
13+
14+
from packit_service.config import ServiceConfig
15+
from packit_service.worker.jobs import SteveJobs
16+
from packit_service.worker.monitoring import Pushgateway
17+
from packit_service.worker.tasks import (
18+
run_onboarding_request_handler,
19+
)
20+
from tests.spellbook import DATA_DIR, first_dict_value, get_parameters_from_results
21+
22+
23+
@pytest.fixture()
24+
def onboarding_request_event():
25+
return json.loads((DATA_DIR / "webhooks" / "onboarding" / "request.json").read_text())
26+
27+
28+
def test_onboarding(onboarding_request_event, tmp_path):
29+
dg_project = (
30+
flexmock(PagureProject(namespace="rpms", repo="packit", service=flexmock(read_only=False)))
31+
.should_receive("is_private")
32+
.and_return(False)
33+
.mock()
34+
.should_receive("get_files")
35+
.and_return(["packit.spec", "sources"])
36+
.mock()
37+
)
38+
service_config = (
39+
flexmock(deployment=Deployment.stg)
40+
.should_receive("get_project")
41+
.and_return(dg_project)
42+
.mock()
43+
)
44+
flexmock(ServiceConfig).should_receive("get_service_config").and_return(service_config)
45+
46+
flexmock(PackitAPI).should_receive("init_kerberos_ticket")
47+
48+
git_repo = tmp_path / "dist-git"
49+
git_repo.mkdir()
50+
51+
dg = (
52+
flexmock(local_project=flexmock(working_dir=git_repo))
53+
.should_receive("create_branch")
54+
.twice()
55+
.mock()
56+
.should_receive("update_branch")
57+
.once()
58+
.mock()
59+
.should_receive("switch_branch")
60+
.twice()
61+
.mock()
62+
.should_receive("reset_workdir")
63+
.once()
64+
.mock()
65+
.should_receive("commit")
66+
.once()
67+
.mock()
68+
)
69+
flexmock(DistGit).new_instances(dg)
70+
71+
flexmock(PackitAPI).should_receive("push_and_create_pr").once()
72+
73+
flexmock(Signature).should_receive("apply_async").once()
74+
flexmock(Pushgateway).should_receive("push").twice().and_return()
75+
76+
processing_results = SteveJobs().process_message(onboarding_request_event)
77+
event_dict, _, job_config, package_config = get_parameters_from_results(
78+
processing_results[:1],
79+
)
80+
assert json.dumps(event_dict)
81+
results = run_onboarding_request_handler(
82+
package_config=package_config,
83+
event=event_dict,
84+
job_config=job_config,
85+
)
86+
87+
assert first_dict_value(results["job"])["success"]
88+
89+
generated_config = (git_repo / ".packit.yaml").read_text()
90+
91+
assert "pull_from_upstream" in generated_config
92+
assert "koji_build" in generated_config
93+
assert "bodhi_update" in generated_config

0 commit comments

Comments
 (0)