| |
@@ -1,5 +1,5 @@
|
| |
import logging
|
| |
- from unittest.mock import Mock, patch
|
| |
+ from unittest.mock import call, MagicMock, Mock, patch
|
| |
import xmlrpc.client
|
| |
|
| |
import pytest
|
| |
@@ -228,3 +228,694 @@
|
| |
mock_bz.assert_called_with()
|
| |
server.updateperms.assert_not_called()
|
| |
assert output == []
|
| |
+
|
| |
+
|
| |
+ class TestGetProductInfoPackager:
|
| |
+ """Test class for `toddlers.utils.bugzilla_system.get_product_info_packages` function."""
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_get_product_info_packages(self, mock_bz):
|
| |
+ """ Assert that compat_api 'component.get' is handled correctly. """
|
| |
+ server = MagicMock()
|
| |
+ server.product_get.return_value = {
|
| |
+ "components": [
|
| |
+ {
|
| |
+ "name": "foo",
|
| |
+ "default_assigned_to": "default_assignee",
|
| |
+ "description": "description",
|
| |
+ "default_qa_contact": "default_qa_contact",
|
| |
+ "default_cc": "default_cc",
|
| |
+ "is_active": True,
|
| |
+ }
|
| |
+ ]
|
| |
+ }
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ output = toddlers.utils.bugzilla_system.get_product_info_packages(
|
| |
+ collection="Fedora",
|
| |
+ )
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ server.product_get.assert_called_with(
|
| |
+ names=["Fedora"],
|
| |
+ include_fields=[
|
| |
+ "components.name",
|
| |
+ "components.default_assigned_to",
|
| |
+ "components.description",
|
| |
+ "components.default_qa_contact",
|
| |
+ "components.default_cc",
|
| |
+ "components.is_active",
|
| |
+ ],
|
| |
+ )
|
| |
+
|
| |
+ assert output == {
|
| |
+ "foo": {
|
| |
+ "initialowner": "default_assignee",
|
| |
+ "description": "description",
|
| |
+ "initialqacontact": "default_qa_contact",
|
| |
+ "initialcclist": "default_cc",
|
| |
+ "is_active": True,
|
| |
+ }
|
| |
+ }
|
| |
+
|
| |
+
|
| |
+ class TestReassignTicketsToAssignee:
|
| |
+ """Test class for `toddlers.utils.bugzilla_system.reassign_tickets_to_assignee` function."""
|
| |
+
|
| |
+ # Query used in multiple tests
|
| |
+ query = {
|
| |
+ "product": "Fedora",
|
| |
+ "component": "foo",
|
| |
+ "bug_status": [
|
| |
+ "NEW",
|
| |
+ "ASSIGNED",
|
| |
+ "ON_DEV",
|
| |
+ "ON_QA",
|
| |
+ "MODIFIED",
|
| |
+ "POST",
|
| |
+ "FAILS_QA",
|
| |
+ "PASSES_QA",
|
| |
+ "RELEASE_PENDING",
|
| |
+ ],
|
| |
+ "version": ["rpms"],
|
| |
+ }
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_reassign_tickets_to_assignee_dry_run(self, mock_bz):
|
| |
+ """Assert that dry_run doesn't do any change."""
|
| |
+ old_poc = "khorne@fedoraproject.org"
|
| |
+ new_poc = "tzeentch@fedoraproject.org"
|
| |
+ bug = Mock()
|
| |
+ bug.assigned_to = old_poc
|
| |
+
|
| |
+ server = Mock()
|
| |
+ server.query.return_value = [bug]
|
| |
+
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ toddlers.utils.bugzilla_system.reassign_tickets_to_assignee(
|
| |
+ new_poc=new_poc,
|
| |
+ old_poc=old_poc,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ versions=["rpms"],
|
| |
+ dry_run=True,
|
| |
+ )
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ server.query.assert_called_with(query=self.query)
|
| |
+ bug.setassignee.asssert_not_called()
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_reassign_tickets_to_assignee_print_fas_names_no_fas_info(
|
| |
+ self, mock_bz, caplog
|
| |
+ ):
|
| |
+ """Assert that `print_fas_names` parameter is handled correctly
|
| |
+ when the FAS user info is missing.
|
| |
+ """
|
| |
+ old_poc = "khorne@fedoraproject.org"
|
| |
+ new_poc = "tzeentch@fedoraproject.org"
|
| |
+ bug = Mock()
|
| |
+ bug.bug_id = 1
|
| |
+ bug.assigned_to = old_poc
|
| |
+
|
| |
+ server = Mock()
|
| |
+ server.query.return_value = [bug]
|
| |
+
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.reassign_tickets_to_assignee(
|
| |
+ new_poc=new_poc,
|
| |
+ old_poc=old_poc,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ versions=["rpms"],
|
| |
+ dry_run=True,
|
| |
+ print_fas_names=True,
|
| |
+ )
|
| |
+
|
| |
+ assert (
|
| |
+ "Fedora/foo reassigning bug #1 from khorne@... to tzeentch@..."
|
| |
+ in caplog.text
|
| |
+ )
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ server.query.assert_called_with(query=self.query)
|
| |
+ bug.setassignee.asssert_not_called()
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_reassign_tickets_to_assignee_print_fas_names_fas_info(
|
| |
+ self, mock_bz, caplog
|
| |
+ ):
|
| |
+ """Assert that `print_fas_names` parameter is handled correctly
|
| |
+ when the FAS user info is available.
|
| |
+ """
|
| |
+ old_poc = "khorne@fedoraproject.org"
|
| |
+ new_poc = "tzeentch@fedoraproject.org"
|
| |
+ bug = Mock()
|
| |
+ bug.bug_id = 1
|
| |
+ bug.assigned_to = old_poc
|
| |
+
|
| |
+ server = Mock()
|
| |
+ server.query.return_value = [bug]
|
| |
+
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.reassign_tickets_to_assignee(
|
| |
+ new_poc=new_poc,
|
| |
+ old_poc=old_poc,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ versions=["rpms"],
|
| |
+ fas_users_info={
|
| |
+ "khorne@fedoraproject.org": "Blood God",
|
| |
+ "tzeentch@fedoraproject.org": "Master of Fate",
|
| |
+ },
|
| |
+ dry_run=True,
|
| |
+ print_fas_names=True,
|
| |
+ )
|
| |
+
|
| |
+ assert (
|
| |
+ "Fedora/foo reassigning bug #1 from Blood God to Master of Fate"
|
| |
+ in caplog.text
|
| |
+ )
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ server.query.assert_called_with(query=self.query)
|
| |
+ bug.setassignee.asssert_not_called()
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.execute_bugzilla_call")
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_reassign_tickets_to_assignee_xmlrpc_Fault(self, mock_bz, mock_bz_call):
|
| |
+ """Assert that `xmlrpc.client.Fault` is raised correctly."""
|
| |
+ old_poc = "khorne@fedoraproject.org"
|
| |
+ new_poc = "tzeentch@fedoraproject.org"
|
| |
+ bug = Mock()
|
| |
+ bug.bug_id = 1
|
| |
+ bug.assigned_to = old_poc
|
| |
+
|
| |
+ server = Mock()
|
| |
+
|
| |
+ mock_bz.return_value = server
|
| |
+ mock_bz_call.side_effect = ([bug], xmlrpc.client.Fault(50, "Fault"))
|
| |
+
|
| |
+ with pytest.raises(xmlrpc.client.Fault) as exc_info:
|
| |
+ toddlers.utils.bugzilla_system.reassign_tickets_to_assignee(
|
| |
+ new_poc=new_poc,
|
| |
+ old_poc=old_poc,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ versions=["rpms"],
|
| |
+ )
|
| |
+
|
| |
+ assert exc_info.value.args == ("tzeentch@fedoraproject.org", 50, "Fault")
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ mock_bz_call.assert_has_calls(
|
| |
+ [
|
| |
+ call(server.query, {"query": self.query}),
|
| |
+ call(
|
| |
+ bug.setassignee,
|
| |
+ {
|
| |
+ "assigned_to": new_poc,
|
| |
+ "comment": "This package has changed maintainer in Fedora. "
|
| |
+ + "Reassigning to the new maintainer of this component.",
|
| |
+ },
|
| |
+ ),
|
| |
+ ]
|
| |
+ )
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.execute_bugzilla_call")
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_reassign_tickets_to_assignee_xmlrpc_ProtocolError(
|
| |
+ self, mock_bz, mock_bz_call
|
| |
+ ):
|
| |
+ """Assert that `xmlrpc.client.ProtocolError` is raised correctly."""
|
| |
+ old_poc = "khorne@fedoraproject.org"
|
| |
+ new_poc = "tzeentch@fedoraproject.org"
|
| |
+ bug = Mock()
|
| |
+ bug.bug_id = 1
|
| |
+ bug.assigned_to = old_poc
|
| |
+
|
| |
+ server = Mock()
|
| |
+
|
| |
+ mock_bz.return_value = server
|
| |
+ mock_bz_call.side_effect = (
|
| |
+ [bug],
|
| |
+ xmlrpc.client.ProtocolError("Error", 10, "Error message", {}),
|
| |
+ )
|
| |
+
|
| |
+ with pytest.raises(xmlrpc.client.ProtocolError) as exc_info:
|
| |
+ toddlers.utils.bugzilla_system.reassign_tickets_to_assignee(
|
| |
+ new_poc=new_poc,
|
| |
+ old_poc=old_poc,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ versions=["rpms"],
|
| |
+ )
|
| |
+
|
| |
+ assert exc_info.value.args == ("ProtocolError", 10, "Error message")
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ mock_bz_call.assert_has_calls(
|
| |
+ [
|
| |
+ call(server.query, {"query": self.query}),
|
| |
+ call(
|
| |
+ bug.setassignee,
|
| |
+ {
|
| |
+ "assigned_to": new_poc,
|
| |
+ "comment": "This package has changed maintainer in Fedora. "
|
| |
+ + "Reassigning to the new maintainer of this component.",
|
| |
+ },
|
| |
+ ),
|
| |
+ ]
|
| |
+ )
|
| |
+
|
| |
+
|
| |
+ @pytest.fixture
|
| |
+ def owner():
|
| |
+ """Fixture for owner value.
|
| |
+ Used in test classes for both add and edit component.
|
| |
+ """
|
| |
+ return "khorne@fedoraproject.org"
|
| |
+
|
| |
+
|
| |
+ @pytest.fixture
|
| |
+ def data(owner):
|
| |
+ """Fixture for data value.
|
| |
+ Used in test classes for both add and edit component.
|
| |
+ """
|
| |
+ return {
|
| |
+ "product": "Fedora",
|
| |
+ "component": "foo",
|
| |
+ "initialowner": owner,
|
| |
+ "description": "description",
|
| |
+ "initialqacontact": "nurgle@fedoraproject.org",
|
| |
+ "initialcclist": [owner],
|
| |
+ "is_active": True,
|
| |
+ }
|
| |
+
|
| |
+
|
| |
+ class TestAddComponent:
|
| |
+ """Test class for `toddlers.utils.bugzilla_system.add_component` function."""
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_add_component_dry_run(self, mock_bz, caplog, owner):
|
| |
+ """Assert that dry_run doesn't do any change."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.add_component(
|
| |
+ product="Fedora",
|
| |
+ owner=owner,
|
| |
+ package="foo",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ cc_list=[owner],
|
| |
+ dry_run=True,
|
| |
+ )
|
| |
+
|
| |
+ assert (
|
| |
+ caplog.records[0].getMessage()
|
| |
+ == f"[ADDCOMP] Fedora/foo initialowner set to `{owner}`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[1].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo description set to `NA`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[2].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo initialqacontact set to `nurgle@fedoraproject.org`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[3].getMessage()
|
| |
+ == f"[ADDCOMP] Fedora/foo initialcclist set to `['{owner}']`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[4].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo is_active set to `True`"
|
| |
+ )
|
| |
+ server.addcomponent.assert_not_called()
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_add_component_retired(self, mock_bz, caplog, owner):
|
| |
+ """Assert that nothing is done for retired package."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.add_component(
|
| |
+ product="Fedora",
|
| |
+ owner=owner,
|
| |
+ package="foo",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ cc_list=[owner],
|
| |
+ retired=True,
|
| |
+ dry_run=True,
|
| |
+ )
|
| |
+
|
| |
+ assert caplog.records[0].getMessage() == "[NOADD] Fedora/foo is retired"
|
| |
+ server.addcomponent.assert_not_called()
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_add_component_print_fas_names(self, mock_bz, caplog, owner, data):
|
| |
+ """Assert that print_fas_names works correctly."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.add_component(
|
| |
+ product="Fedora",
|
| |
+ owner=owner,
|
| |
+ package="foo",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ cc_list=[owner],
|
| |
+ fas_users_info={
|
| |
+ "khorne@fedoraproject.org": "Blood God",
|
| |
+ "nurgle@fedoraproject.org": "Papa Nurgle",
|
| |
+ },
|
| |
+ print_fas_names=True,
|
| |
+ )
|
| |
+
|
| |
+ assert (
|
| |
+ caplog.records[0].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo initialowner set to FAS name(s) `Blood God`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[1].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo description set to `NA`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[2].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo initialqacontact set to FAS name(s) `Papa Nurgle`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[3].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo initialcclist set to FAS name(s) `['Blood God']`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[4].getMessage()
|
| |
+ == "[ADDCOMP] Fedora/foo is_active set to `True`"
|
| |
+ )
|
| |
+
|
| |
+ data["description"] = "NA"
|
| |
+
|
| |
+ server.addcomponent.assert_called_with(data=data)
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.execute_bugzilla_call")
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_add_component_xmlrpc_Fault(self, mock_bz, mock_bz_call, owner, data):
|
| |
+ """Assert that `xmlrpc.client.Fault` is raised correctly."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+ mock_bz_call.side_effect = xmlrpc.client.Fault(50, "Fault")
|
| |
+
|
| |
+ with pytest.raises(xmlrpc.client.Fault) as exc_info:
|
| |
+ toddlers.utils.bugzilla_system.add_component(
|
| |
+ product="Fedora",
|
| |
+ owner=owner,
|
| |
+ package="foo",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ cc_list=[owner],
|
| |
+ fas_users_info={
|
| |
+ "khorne@fedoraproject.org": "Blood God",
|
| |
+ "nurgle@fedoraproject.org": "Papa Nurgle",
|
| |
+ },
|
| |
+ print_fas_names=True,
|
| |
+ )
|
| |
+
|
| |
+ data["description"] = "NA"
|
| |
+
|
| |
+ assert exc_info.value.args == (data, 50, "Fault")
|
| |
+
|
| |
+ mock_bz_call.assert_called_with(server.addcomponent, {"data": data})
|
| |
+
|
| |
+
|
| |
+ class TestEditComponent:
|
| |
+ """Test class for `toddlers.utils.bugzilla_system.edit_component` function."""
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_edit_component_no_change(self, mock_bz, caplog, owner):
|
| |
+ """Assert that nothing is done when no change occurs."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.edit_component(
|
| |
+ owner=owner,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ component={
|
| |
+ "initialowner": owner,
|
| |
+ "description": "description",
|
| |
+ "initialqacontact": "nurgle@fedoraproject.org",
|
| |
+ "initialcclist": "",
|
| |
+ "is_active": True,
|
| |
+ },
|
| |
+ cc_list=[],
|
| |
+ versions=[],
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ print_no_change=True,
|
| |
+ )
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ assert caplog.records[0].getMessage() == "[NOCHANGE] Fedora/foo"
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_edit_component_change_same_owner_dry_run(self, mock_bz, caplog, owner):
|
| |
+ """Assert that component is not updated when change occurs, but dry run is set."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.edit_component(
|
| |
+ owner=owner,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ component={
|
| |
+ "initialowner": owner,
|
| |
+ "description": "",
|
| |
+ "initialqacontact": "",
|
| |
+ "initialcclist": [],
|
| |
+ "is_active": False,
|
| |
+ },
|
| |
+ cc_list=[owner],
|
| |
+ versions=[],
|
| |
+ description="description",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ dry_run=True,
|
| |
+ )
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ server.editcomponent.assert_not_called()
|
| |
+ assert (
|
| |
+ caplog.records[0].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo description changed from `` to `description`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[1].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo initialqacontact changed from `` "
|
| |
+ "to `nurgle@fedoraproject.org`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[2].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo initialcclist changed from `[]` "
|
| |
+ "to `['khorne@fedoraproject.org']`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[3].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo is_active changed from `False` to `True`"
|
| |
+ )
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.reassign_tickets_to_assignee")
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_edit_component_change_print_fas_names(
|
| |
+ self, mock_bz, mock_set_pkg_owner, caplog, owner, data
|
| |
+ ):
|
| |
+ """Assert that FAS names are printed when the option is enabled."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+
|
| |
+ with caplog.at_level(logging.DEBUG):
|
| |
+ toddlers.utils.bugzilla_system.edit_component(
|
| |
+ owner=owner,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ component={
|
| |
+ "initialowner": "tzeentch@fedoraproject.org",
|
| |
+ "description": "",
|
| |
+ "initialqacontact": "",
|
| |
+ "initialcclist": ["slaanesh@fedoraproject.org"],
|
| |
+ "is_active": False,
|
| |
+ },
|
| |
+ cc_list=[owner],
|
| |
+ versions=[],
|
| |
+ description="description",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ fas_users_info={
|
| |
+ owner: "Blood God",
|
| |
+ "nurgle@fedoraproject.org": "Papa Nurgle",
|
| |
+ "tzeentch@fedoraproject.org": "Master of Fate",
|
| |
+ },
|
| |
+ print_fas_names=True,
|
| |
+ )
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ server.editcomponent.assert_called_with(data=data)
|
| |
+ mock_set_pkg_owner.assert_called_with(
|
| |
+ new_poc=owner,
|
| |
+ old_poc="tzeentch@fedoraproject.org",
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ versions=[],
|
| |
+ fas_users_info={
|
| |
+ owner: "Blood God",
|
| |
+ "nurgle@fedoraproject.org": "Papa Nurgle",
|
| |
+ "tzeentch@fedoraproject.org": "Master of Fate",
|
| |
+ },
|
| |
+ dry_run=False,
|
| |
+ print_fas_names=True,
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[0].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo initialowner changed from `Master of Fate` to "
|
| |
+ "FAS name(s) `Blood God`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[1].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo description changed from `` to `description`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[2].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo initialqacontact changed from `` to FAS name(s) `Papa Nurgle`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[3].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo initialcclist changed from "
|
| |
+ "`['slaanesh@fedoraproject.org']` to FAS name(s) `['Blood God']`"
|
| |
+ )
|
| |
+ assert (
|
| |
+ caplog.records[4].getMessage()
|
| |
+ == "[EDITCOMP] Fedora/foo is_active changed from `False` to `True`"
|
| |
+ )
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.execute_bugzilla_call")
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_edit_component_change_xmlrpc_fault(
|
| |
+ self, mock_bz, mock_bz_call, owner, data
|
| |
+ ):
|
| |
+ """Assert that `xmlrpc.client.Fault` is handled correctly."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+ mock_bz_call.side_effect = xmlrpc.client.Fault(50, "Fault")
|
| |
+
|
| |
+ with pytest.raises(xmlrpc.client.Fault) as exc:
|
| |
+ toddlers.utils.bugzilla_system.edit_component(
|
| |
+ owner=owner,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ component={
|
| |
+ "initialowner": "tzeentch@fedoraproject.org",
|
| |
+ "description": "",
|
| |
+ "initialqacontact": "",
|
| |
+ "initialcclist": [],
|
| |
+ "is_active": False,
|
| |
+ },
|
| |
+ cc_list=[owner],
|
| |
+ versions=[],
|
| |
+ description="description",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ fas_users_info={
|
| |
+ owner: "Blood God",
|
| |
+ "nurgle@fedoraproject.org": "Papa Nurgle",
|
| |
+ "tzeentch@fedoraproject.org": "Master of Fate",
|
| |
+ },
|
| |
+ )
|
| |
+
|
| |
+ assert exc.value.args == (data, 50, "Fault")
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ mock_bz_call.assert_called_with(server.editcomponent, {"data": data})
|
| |
+
|
| |
+ @patch("toddlers.utils.bugzilla_system.execute_bugzilla_call")
|
| |
+ @patch("toddlers.utils.bugzilla_system.get_bz")
|
| |
+ def test_edit_component_change_xmlrpc_ProtocolError(
|
| |
+ self, mock_bz, mock_bz_call, owner, data
|
| |
+ ):
|
| |
+ """Assert that `xmlrpc.client.Fault` is handled correctly."""
|
| |
+ server = Mock()
|
| |
+ mock_bz.return_value = server
|
| |
+ mock_bz_call.side_effect = xmlrpc.client.ProtocolError(
|
| |
+ "Error", 10, "Error message", {}
|
| |
+ )
|
| |
+
|
| |
+ with pytest.raises(xmlrpc.client.ProtocolError) as exc:
|
| |
+ toddlers.utils.bugzilla_system.edit_component(
|
| |
+ owner=owner,
|
| |
+ product="Fedora",
|
| |
+ package="foo",
|
| |
+ component={
|
| |
+ "initialowner": "tzeentch@fedoraproject.org",
|
| |
+ "description": "",
|
| |
+ "initialqacontact": "",
|
| |
+ "initialcclist": [],
|
| |
+ "is_active": False,
|
| |
+ },
|
| |
+ cc_list=[owner],
|
| |
+ versions=[],
|
| |
+ description="description",
|
| |
+ qa_contact="nurgle@fedoraproject.org",
|
| |
+ fas_users_info={
|
| |
+ owner: "Blood God",
|
| |
+ "nurgle@fedoraproject.org": "Papa Nurgle",
|
| |
+ "tzeentch@fedoraproject.org": "Master of Fate",
|
| |
+ },
|
| |
+ )
|
| |
+
|
| |
+ assert exc.value.args == ("ProtocolError", 10, "Error message")
|
| |
+
|
| |
+ mock_bz.assert_called_with()
|
| |
+ mock_bz_call.assert_called_with(server.editcomponent, {"data": data})
|
| |
+
|
| |
+
|
| |
+ class TestExecuteBugzillaCall:
|
| |
+ """Test class for `toddlers.utils.bugzilla_system.execute_bugzilla_call` function."""
|
| |
+
|
| |
+ def test_execute_bugzilla_call(self):
|
| |
+ """Assert that bugzilla call wrapper is working correctly."""
|
| |
+ mock_call = MagicMock()
|
| |
+ mock_call.return_value = {"name": "foo"}
|
| |
+ args = {"product": "Fedora", "data": {"component": "foo"}}
|
| |
+
|
| |
+ output = toddlers.utils.bugzilla_system.execute_bugzilla_call(
|
| |
+ call=mock_call, args=args
|
| |
+ )
|
| |
+
|
| |
+ assert output == {"name": "foo"}
|
| |
+
|
| |
+ mock_call.assert_called_with(product="Fedora", data={"component": "foo"})
|
| |
+
|
| |
+ @patch("time.sleep")
|
| |
+ def test_execute_bugzilla_call_exception(self, mock_time, caplog):
|
| |
+ """Assert that bugzilla call wrapper is working correctly when exception happens."""
|
| |
+ caplog.set_level(logging.DEBUG)
|
| |
+ mock_call = MagicMock()
|
| |
+ mock_call.side_effect = xmlrpc.client.Fault(50, "Error")
|
| |
+ args = {"product": "Fedora", "data": {"component": "foo"}}
|
| |
+
|
| |
+ with pytest.raises(xmlrpc.client.Fault):
|
| |
+ toddlers.utils.bugzilla_system.execute_bugzilla_call(
|
| |
+ call=mock_call, args=args, num_of_attempts=2
|
| |
+ )
|
| |
+
|
| |
+ mock_call.assert_called_with(product="Fedora", data={"component": "foo"})
|
| |
+
|
| |
+ assert caplog.records[0].getMessage() == "ERROR <Fault 50: 'Error'>"
|
| |
+ assert (
|
| |
+ caplog.records[1].getMessage()
|
| |
+ == "Query failed, going to try again in 10 seconds"
|
| |
+ )
|
| |
+
|
| |
+ mock_time.assert_called_with(10)
|
| |
If they are only used by the new toddler, let's not put these in the default configuration key (yet)