From 18a3d500298d4fbc3ebc77d16a93be3b21482882 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mon, 29 Jun 2020 17:10:42 +0200 Subject: [PATCH] Add a new test to tests/plugins/test_flag_commit_build.py This tests has a message supposedly coming from koji and where the task_id is None. This brings the coverage of the code to 100%. Signed-off-by: Pierre-Yves Chibon --- tests/plugins/test_flag_commit_build.py | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/plugins/test_flag_commit_build.py b/tests/plugins/test_flag_commit_build.py index 712d38e..c6de4d2 100644 --- a/tests/plugins/test_flag_commit_build.py +++ b/tests/plugins/test_flag_commit_build.py @@ -144,6 +144,55 @@ class TestFlagCommitBuildToddler: ) assert caplog.records[-1].message == "No # in the git_url: foobar" + @patch("toddlers.plugins.flag_commit_build.requests_session") + @patch("toddlers.plugins.flag_commit_build.koji") + def test_process_flag_no_task_id(self, mock_koji, mock_requests, caplog): + mock_requests.request.return_value = MagicMock( + ok=False, status_code=401, text="invalid" + ) + client = Mock() + client.getBuild = Mock( + return_value={ + "extra": { + "source": { + "original_url": "https://src.fedoraproject.org/rpms/" + "guake.git#commit_hash123" + } + } + } + ) + mock_koji.ClientSession = Mock(return_value=client) + caplog.set_level(logging.INFO) + msg = fedora_messaging.api.Message() + msg.id = 123 + msg.topic = "org.fedoraproject.prod.buildsys.build.state.change" + msg.body = { + "owner": "username", + "instance": "primary", + "new": 3, + "build_id": 42, + "epoch": "0", + "version": "1.0.0", + "name": "guake", + "release": "1", + "task_id": None, + } + config = { + "koji_url": "https://koji.fedoraproject.org", + "pagure_url": "https://src.fedoraproject.org", + "pagure_token": "ahah", + } + assert ( + toddlers.plugins.flag_commit_build.FlagCommitBuild.process( + config=config, message=msg + ) + is None + ) + assert ( + caplog.records[-1].message + == "Request to https://src.fedoraproject.org returned: 401" + ) + @patch("toddlers.plugins.flag_commit_build.requests_session") @patch("toddlers.plugins.flag_commit_build.koji") def test_process_flag_failed(self, mock_koji, mock_requests, caplog):