| |
@@ -24,6 +24,8 @@
|
| |
"pdc_config": {
|
| |
"server": "https://pdc.fedoraproject.org/rest_api/v1",
|
| |
},
|
| |
+ "pagure_api_key": "some api key",
|
| |
+ "pagure_url": "https://src.fedoraproject.org",
|
| |
# distgit_bugzilla_sync config values
|
| |
"ignorable_accounts": [],
|
| |
"fasjson": False,
|
| |
@@ -66,6 +68,16 @@
|
| |
class TestDistgitBugzillaSyncToddler:
|
| |
toddler_cls = DistgitBugzillaSync
|
| |
|
| |
+ def setup_method(self):
|
| |
+ """
|
| |
+ Initialize toddler.
|
| |
+ """
|
| |
+ #self.toddler = DistgitBugzillaSync
|
| |
+ self.pagure_io = Mock()
|
| |
+ self.dist_git = Mock()
|
| |
+ self.bodhi = Mock()
|
| |
+ self.requests_session = Mock()
|
| |
+
|
| |
def test_accepts_topic_invalid(self, toddler):
|
| |
assert toddler.accepts_topic("foo.bar") is False
|
| |
|
| |
@@ -80,8 +92,26 @@
|
| |
def test_accepts_topic_valid(self, toddler, topic):
|
| |
assert toddler.accepts_topic(topic)
|
| |
|
| |
- def test_process_no_email_override_file(self, toddler):
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.bodhi.set_bodhi")
|
| |
+ def test_process_no_email_override_file(self, toddler, mock_set_pagure, mock_set_bodhi):
|
| |
"""Assert that the exception is raised when e-mail overrides file is not provided."""
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.get_retired_packages.side_effect = (
|
| |
+ ["package01", "package02"],
|
| |
+ ["package01", "package03"],
|
| |
+ )
|
| |
+ mock_dist_git.get_branches.return_value = ["f39", "f40"]
|
| |
+ mock_dist_git.get_project.return_value = {
|
| |
+ "user": {"name": "Gavriel Loken"},
|
| |
+ "access_users": {"admin": ["Fulgrim", "orphan"]},
|
| |
+ "access_groups": {"admin": ["Adeptus Astartes"]},
|
| |
+ }
|
| |
+ mock_set_pagure.return_value = mock_dist_git
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = ["f39", "f40"]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+
|
| |
with pytest.raises(KeyError) as exc:
|
| |
toddler.process(
|
| |
config={},
|
| |
@@ -95,6 +125,8 @@
|
| |
)
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_dry_run_edit_project(
|
| |
self,
|
| |
@@ -234,6 +266,8 @@
|
| |
)
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_dry_run_add_project(
|
| |
self,
|
| |
@@ -370,6 +404,8 @@
|
| |
)
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_dry_run_specific_project(
|
| |
self,
|
| |
@@ -493,6 +529,8 @@
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.notify")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_report_protocol_error(
|
| |
self,
|
| |
@@ -606,6 +644,8 @@
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.notify")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_report_client_error(
|
| |
self,
|
| |
@@ -739,6 +779,8 @@
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.notify")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_report_missing_mails(
|
| |
self,
|
| |
@@ -835,6 +877,8 @@
|
| |
)
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_dry_run_verbose(
|
| |
self,
|
| |
@@ -932,6 +976,8 @@
|
| |
)
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_missing_namespace(
|
| |
self,
|
| |
@@ -984,6 +1030,8 @@
|
| |
)
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load")
|
| |
def test_process_missing_pdc_branches(
|
| |
self,
|
| |
@@ -1041,6 +1089,8 @@
|
| |
@patch(
|
| |
"toddlers.plugins.distgit_bugzilla_sync.PackageSummaries.get_package_summaries"
|
| |
)
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
@patch("toml.load")
|
| |
@@ -1157,6 +1207,8 @@
|
| |
@patch(
|
| |
"toddlers.plugins.distgit_bugzilla_sync.PackageSummaries.get_package_summaries"
|
| |
)
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.bodhi.set_bodhi")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
@patch("toml.load")
|
| |
@@ -1165,6 +1217,10 @@
|
| |
mock_toml,
|
| |
mock_bugzilla,
|
| |
mock_fas,
|
| |
+ mock_dist_git,
|
| |
+ mock_set_pagure,
|
| |
+ mock_set_bodhi,
|
| |
+ mock_bodhi,
|
| |
mock_summaries,
|
| |
config,
|
| |
toddler,
|
| |
@@ -1179,6 +1235,23 @@
|
| |
# Mock package summaries response
|
| |
mock_summaries.return_value = {"foo": "Summary"}
|
| |
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.get_retired_packages.side_effect = (
|
| |
+ ["package01", "package02"],
|
| |
+ ["package01", "package03"],
|
| |
+ )
|
| |
+ mock_dist_git.get_branches.return_value = ["f39", "f40"]
|
| |
+ mock_dist_git.get_project.return_value = {
|
| |
+ "user": {"name": "Gavriel Loken"},
|
| |
+ "access_users": {"admin": ["Fulgrim", "orphan"]},
|
| |
+ "access_groups": {"admin": ["Adeptus Astartes"]},
|
| |
+ }
|
| |
+ mock_set_pagure.return_value = mock_dist_git
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = ["f39", "f40"]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+
|
| |
+
|
| |
# Mock pagure responses
|
| |
toddler.requests_session = Mock()
|
| |
response_pagure_poc = MagicMock()
|
| |
@@ -1252,6 +1325,7 @@
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")
|
| |
@patch("toddlers.plugins.distgit_bugzilla_sync.notify")
|
| |
@patch("toml.load")
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
def test_process_notify_user_cache_exists(
|
| |
self,
|
| |
mock_toml,
|
| |
@@ -1331,9 +1405,29 @@
|
| |
|
| |
class TestMain:
|
| |
"""Test class for `toddler.plugins.distgit_bugzilla_sync.main`."""
|
| |
-
|
| |
- def test_main_no_args(self, capsys):
|
| |
+
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
+ def test_main_no_args(self, capsys, mock_set_pagure,
|
| |
+ mock_set_bodhi):
|
| |
"""Assert that help is printed if no arg is provided."""
|
| |
+ mock_dist_git = MagicMock()
|
| |
+ mock_dist_git.get_retired_packages.side_effect = (
|
| |
+ ["package01", "package02"],
|
| |
+ ["package01", "package03"],
|
| |
+ )
|
| |
+ mock_dist_git.get_branches.return_value = ["f39", "f40"]
|
| |
+ mock_dist_git.get_project.return_value = {
|
| |
+ "user": {"name": "Gavriel Loken"},
|
| |
+ "access_users": {"admin": ["Fulgrim", "orphan"]},
|
| |
+ "access_groups": {"admin": ["Adeptus Astartes"]},
|
| |
+ }
|
| |
+ mock_set_pagure.return_value = mock_dist_git
|
| |
+ mock_bodhi = MagicMock()
|
| |
+ mock_bodhi.get_active_branches.return_value = ["f39", "f40"]
|
| |
+ mock_set_bodhi.return_value = mock_bodhi
|
| |
+
|
| |
+
|
| |
with pytest.raises(SystemExit):
|
| |
main([])
|
| |
|
| |
@@ -1346,13 +1440,17 @@
|
| |
assert err.startswith("usage:")
|
| |
assert "error: the following arguments are required:" in err
|
| |
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load", new=Mock(return_value={}))
|
| |
def test_main_debug(self, caplog):
|
| |
"""Assert that debug is set correctly."""
|
| |
with pytest.raises(KeyError, match=r"'email_overrides_file'"):
|
| |
main(["test.cfg", "--debug"])
|
| |
assert "Failed to load the file containing the email-overrides" in caplog.text
|
| |
-
|
| |
+
|
| |
+ @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")
|
| |
+ @patch("toddlers.utils.bodhi.set_bodhi")
|
| |
@patch("toml.load", new=Mock(return_value={}))
|
| |
def test_main(self, caplog):
|
| |
"""Assert that INFO log level is handled correctly."""
|
| |
Signed-off-by: Tomas Hrcka thrcka@redhat.com