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 <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2020-06-29 17:10:42 +02:00
parent 74c014b6fe
commit 18a3d50029

View file

@ -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):