Introduce the packager_bugzilla_sync toddler

This toddler is meant to be triggered by playtime at regular intervals
and will sync the packager accounts to bugzilla so they can edit flags
on Fedora bugs (for example).

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2020-06-26 17:22:22 +02:00
parent 18a3d50029
commit 03810630ce
12 changed files with 1119 additions and 1 deletions

View file

@ -0,0 +1,142 @@
from unittest.mock import patch, Mock
import pytest
import toddlers.plugins.packager_bugzilla_sync
class TestPackagerBugzillaSyncToddler:
def test_accepts_topic_invalid(self):
assert (
toddlers.plugins.packager_bugzilla_sync.PackagerBugzillaSync.accepts_topic(
"foo.bar"
)
is False
)
@pytest.mark.parametrize(
"topic",
[
"org.fedoraproject.*.toddlers.trigger.packager_bugzilla_sync",
"org.fedoraproject.prod.toddlers.trigger.packager_bugzilla_sync",
"org.fedoraproject.stg.toddlers.trigger.packager_bugzilla_sync",
],
)
def test_accepts_topic_valid(self, topic):
assert toddlers.plugins.packager_bugzilla_sync.PackagerBugzillaSync.accepts_topic(
topic
)
def test_process_no_email_override(self, capsys):
with pytest.raises(KeyError, match=r"'email_overrides_file'"):
toddlers.plugins.packager_bugzilla_sync.PackagerBugzillaSync.process(
config={}, message=None, username=False, dry_run=True
)
out, err = capsys.readouterr()
assert out == "Failed to load the file containing the email-overrides\n"
assert err == ""
def test_process_no_email_override_file(self, capsys):
with pytest.raises(
FileNotFoundError, match=r"No such file or directory: 'test'"
):
toddlers.plugins.packager_bugzilla_sync.PackagerBugzillaSync.process(
config={"email_overrides_file": "test"},
message=None,
username=False,
dry_run=True,
)
out, err = capsys.readouterr()
assert out == "Failed to load the file containing the email-overrides\n"
assert err == ""
@patch("toddlers.utils.fedora_account.set_fas", new=Mock(return_value=True))
@patch("toddlers.utils.bugzilla_system.set_bz", new=Mock(return_value=True))
@patch("toddlers.utils.fedora_account.get_group_member")
@patch("toddlers.utils.fedora_account.get_bz_email_user")
@patch("toddlers.utils.bugzilla_system.get_group_member")
@patch("toddlers.utils.bugzilla_system.add_user_to_group")
@patch("toml.load")
def test_process(
self, toml_load, bz_user_grp, get_bz_grp_mbr, get_bz_email, get_fas_grp_mbr
):
toml_load.return_value = {}
get_fas_grp_mbr.return_value = ["pingou", "nils"]
get_bz_email.side_effect = ["pingou@fp.o", "nils@fp.o"]
get_bz_grp_mbr.return_value = ["pingou@fp.o", "nphilipp@fp.o"]
toddlers.plugins.packager_bugzilla_sync.PackagerBugzillaSync.process(
config={"email_overrides_file": "test", "bugzilla_group": "fedora_contrib"},
message=None,
username=False,
dry_run=False,
)
toml_load.assert_called_with("test")
get_fas_grp_mbr.assert_called_with("packager")
get_bz_email.assert_called_with("pingou", {})
get_bz_grp_mbr.assert_called_with("fedora_contrib")
bz_user_grp.assert_called_with(
user_email="nils@fp.o",
bz_group="fedora_contrib",
no_bz_account=[],
dry_run=False,
)
@patch("toddlers.utils.fedora_account.set_fas", new=Mock(return_value=True))
@patch("toddlers.utils.bugzilla_system.set_bz", new=Mock(return_value=True))
@patch("toddlers.utils.fedora_account.get_bz_email_user")
@patch("toddlers.utils.bugzilla_system.get_group_member")
@patch("toddlers.utils.bugzilla_system.add_user_to_group")
@patch("toml.load")
def test_process_username(
self, toml_load, bz_user_grp, get_bz_grp_mbr, get_bz_email
):
toml_load.return_value = {}
get_bz_email.side_effect = ["nils@fp.o"]
get_bz_grp_mbr.return_value = ["pingou@fp.o"]
toddlers.plugins.packager_bugzilla_sync.PackagerBugzillaSync.process(
config={"email_overrides_file": "test", "bugzilla_group": "fedora_contrib"},
message=None,
username="nils",
dry_run=False,
)
toml_load.assert_called_with("test")
get_bz_email.assert_called_with("nils", {})
get_bz_grp_mbr.assert_called_with("fedora_contrib")
bz_user_grp.assert_called_with(
user_email="nils@fp.o",
bz_group="fedora_contrib",
no_bz_account=[],
dry_run=False,
)
def test_main_no_args(self, capsys):
with pytest.raises(SystemExit):
toddlers.plugins.packager_bugzilla_sync.main([])
out, err = capsys.readouterr()
exp = """usage: pytest [-h] [--dry-run] [-q | --debug] conf [username]
pytest: error: the following arguments are required: conf
"""
assert out == ""
assert err == exp
@patch("toml.load", new=Mock(return_value={}))
def test_main_debug(self, capsys):
with pytest.raises(KeyError, match=r"'email_overrides_file'"):
toddlers.plugins.packager_bugzilla_sync.main(["test.cfg", "--debug"])
out, err = capsys.readouterr()
assert out == "Failed to load the file containing the email-overrides\n"
assert err == ""
@patch("toml.load", new=Mock(return_value={}))
def test_main(self, capsys):
with pytest.raises(KeyError, match=r"'email_overrides_file'"):
toddlers.plugins.packager_bugzilla_sync.main(["test.cfg"])
out, err = capsys.readouterr()
assert out == "Failed to load the file containing the email-overrides\n"
assert err == ""