Skip to content

Commit 1549ed6

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

File tree

2 files changed

+97
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)