-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_bot.py
More file actions
113 lines (95 loc) · 3.76 KB
/
test_bot.py
File metadata and controls
113 lines (95 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import pathlib
import pytest
import yaml
from bci_build.package import ALL_NONBASE_OS_VERSIONS
from bci_build.package import OsVersion
from staging.bot import StagingBot
@pytest.fixture(autouse=True)
def run_in_tmp_path(tmp_path: pathlib.Path):
cwd = os.getcwd()
os.chdir(tmp_path)
yield tmp_path
os.chdir(cwd)
@pytest.mark.parametrize("os_version", ALL_NONBASE_OS_VERSIONS)
@pytest.mark.parametrize("branch", ["", "something"])
@pytest.mark.parametrize("packages", [None, ["pcp-image"]])
@pytest.mark.parametrize(
"repositories", [None, ["images"], ["images", "containerfile", "ports"]]
)
@pytest.mark.asyncio
async def test_load_from_env(
os_version: OsVersion,
branch: str,
packages: list[str] | None,
repositories: list[str] | None,
):
kwargs = {"os_version": os_version, "osc_username": "foobar", "branch_name": branch}
if repositories:
kwargs["repositories"] = repositories
bot = StagingBot(**kwargs)
bot.package_names = packages
await bot.setup()
assert await StagingBot.from_env_file() == bot
_osc_user = "defolos"
@pytest.mark.parametrize(
"comment,bot",
[
(
"""Rendered the templates for 4
Changes pushed to branch [`sle15-sp4-AVeMj`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp4-AVeMj)
Created a staging project on OBS: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-AVeMj](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-AVeMj)""",
StagingBot(
os_version=OsVersion.SP4,
branch_name="sle15-sp4-AVeMj",
osc_username=_osc_user,
),
),
(
"""Rendered the templates for Tumbleweed
Changes pushed to branch [`tumbleweed-EqgiS`](https://github.com/SUSE/BCI-dockerfile-generator/tree/tumbleweed-EqgiS)
Created a staging project on OBS: [home:defolos:BCI:Staging:Tumbleweed:tumbleweed-EqgiS](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:Tumbleweed:tumbleweed-EqgiS)""",
StagingBot(
os_version=OsVersion.TUMBLEWEED,
branch_name="tumbleweed-EqgiS",
osc_username=_osc_user,
),
),
(
"""Rendered the templates for 3
Changes pushed to branch [`sle15-sp3-OZGYa`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp3-OZGYa)
Created a staging project on OBS: [home:defolos:BCI:Staging:SLE-15-SP3:sle15-sp3-OZGYa](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:SLE-15-SP3:sle15-sp3-OZGYa)""",
StagingBot(
os_version=OsVersion.SP3,
branch_name="sle15-sp3-OZGYa",
osc_username=_osc_user,
),
),
(
"""Rendered the templates for 6
Changes pushed to branch [`sle15-sp6-1337`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp6-1337)
""",
StagingBot(
os_version=OsVersion.SP6,
branch_name="sle15-sp6-1337",
osc_username=_osc_user,
),
),
],
)
def test_from_github_comment(comment: str, bot: StagingBot):
assert bot == StagingBot.from_github_comment(
comment_text=comment, osc_username=_osc_user
)
def test_from_empty_github_comment():
with pytest.raises(ValueError) as val_err_ctx:
StagingBot.from_github_comment("", "irrelevant")
assert "Received empty github comment, cannot create the bot" in str(
val_err_ctx.value
)
_bot = StagingBot(os_version=OsVersion.SP5, osc_username=_osc_user)
@pytest.mark.parametrize(
"action", [_bot.changelog_check_github_action, _bot.find_missing_packages_action]
)
def test_github_actions_valid_yaml(action: str) -> None:
assert yaml.safe_load(action)