From 1dc826484e74db18fffd131e013cd7eecbf03b07 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Feb 28 2024 17:53:34 +0000 Subject: cid_to_event: better error when compose failed Thanks to @coremodule for reporting this. Signed-off-by: Adam Williamson --- diff --git a/src/wikitcms/helpers.py b/src/wikitcms/helpers.py index 4315fc7..7e901a2 100644 --- a/src/wikitcms/helpers.py +++ b/src/wikitcms/helpers.py @@ -23,6 +23,7 @@ any particular class or even in another file but outside of a class.""" import re from decimal import Decimal +import fedfind.const import fedfind.helpers import fedfind.release @@ -203,6 +204,8 @@ def cid_to_event(cid): # we need to get the label and parse that ffrel = fedfind.release.get_release(cid=cid) if not ffrel.label: + if ffrel.status not in fedfind.const.PUNGI_SUCCESS: + raise ValueError(f"Compose {cid} failed, cannot determine event.") raise ValueError( f"{cid} looks like a production compose, but found " "no label! Cannot determine event." diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 460acc8..17a1a21 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -152,12 +152,25 @@ class TestHelpers: @mock.patch("fedfind.helpers.get_current_release", return_value=23, autospec=True) @mock.patch("fedfind.release.Production.cid", "Fedora-24-20160314.1") @mock.patch("fedfind.release.Production.label", "") - def test_cid_to_event_fail(self, fakecurr): + @mock.patch("fedfind.release.Production.status", "FINISHED") + def test_cid_to_event_fail_no_label(self, fakecurr): """Test to check cid_to_event fails if we cannot determine - label for production compose. + label for production compose (no label case). """ - with pytest.raises(ValueError): + with pytest.raises(ValueError) as excinfo: + hl.cid_to_event("Fedora-24-20160314.1") + assert "found no label" in str(excinfo.value) + + @mock.patch("fedfind.helpers.get_current_release", return_value=23, autospec=True) + @mock.patch("fedfind.release.Production.cid", "Fedora-24-20160314.1") + @mock.patch("fedfind.release.Production.status", "DOOMED") + def test_cid_to_event_fail_doomed(self, fakecurr): + """Test to check cid_to_event fails if we cannot determine + label for production compose (compose failed case). + """ + with pytest.raises(ValueError) as excinfo: hl.cid_to_event("Fedora-24-20160314.1") + assert "Compose Fedora-24-20160314.1 failed" in str(excinfo.value) # vim: set textwidth=100 ts=8 et sw=4: