diff --git a/fedora_distro_aliases/__init__.py b/fedora_distro_aliases/__init__.py index 79cced6..d6c58b1 100644 --- a/fedora_distro_aliases/__init__.py +++ b/fedora_distro_aliases/__init__.py @@ -44,8 +44,16 @@ def get_distro_aliases(): "name": "Rawhide", "long_name": "Fedora Rawhide", "version": "rawhide", + "branch": "rawhide", }) + # During the window from branching to the final release, things can get + # weird. Bodhi can be lying to us. For example, F40 was branched yesterday, + # therefore Rawhide is F41 now. However bodhi says that Fedora 40 branch is + # `rawhide` and F41 branch is `f41`. + if fedora[-2].branch == "rawhide": + fedora[-2].branch = "f{0}".format(fedora[-2].version) + fedora_stable = [x for x in fedora if x.state == "current"] fedora_devel = [x for x in fedora if x.state == "pending"] diff --git a/tests/data/bodhi-f40-branch-window-current.json b/tests/data/bodhi-f40-branch-window-current.json new file mode 100644 index 0000000..4e1b1b3 --- /dev/null +++ b/tests/data/bodhi-f40-branch-window-current.json @@ -0,0 +1,296 @@ +{ + "releases": [ + { + "name": "EPEL-7", + "long_name": "Fedora EPEL 7", + "version": "7", + "id_prefix": "FEDORA-EPEL", + "branch": "epel7", + "dist_tag": "epel7", + "stable_tag": "epel7", + "testing_tag": "epel7-testing", + "candidate_tag": "epel7-testing-candidate", + "pending_signing_tag": "epel7-signing-pending", + "pending_testing_tag": "epel7-testing-pending", + "pending_stable_tag": "epel7-pending", + "override_tag": "epel7-override", + "mail_template": "fedora_epel_legacy_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": null, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": null + }, + { + "name": "EPEL-8", + "long_name": "Fedora EPEL 8", + "version": "8", + "id_prefix": "FEDORA-EPEL", + "branch": "epel8", + "dist_tag": "epel8", + "stable_tag": "epel8", + "testing_tag": "epel8-testing", + "candidate_tag": "epel8-testing-candidate", + "pending_signing_tag": "epel8-signing-pending", + "pending_testing_tag": "epel8-testing-pending", + "pending_stable_tag": "epel8-pending", + "override_tag": "epel8-override", + "mail_template": "fedora_epel_legacy_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": null + }, + { + "name": "EPEL-8N", + "long_name": "Fedora EPEL 8 Next", + "version": "8", + "id_prefix": "FEDORA-EPEL-NEXT", + "branch": "epel8-next", + "dist_tag": "epel8-next", + "stable_tag": "epel8-next", + "testing_tag": "epel8-next-testing", + "candidate_tag": "epel8-next-testing-candidate", + "pending_signing_tag": "epel8-next-signing-pending", + "pending_testing_tag": "epel8-next-testing-pending", + "pending_stable_tag": "epel8-next-pending", + "override_tag": "epel8-next-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": null + }, + { + "name": "EPEL-9", + "long_name": "Fedora EPEL 9", + "version": "9", + "id_prefix": "FEDORA-EPEL", + "branch": "epel9", + "dist_tag": "epel9", + "stable_tag": "epel9", + "testing_tag": "epel9-testing", + "candidate_tag": "epel9-testing-candidate", + "pending_signing_tag": "epel9-signing-pending", + "pending_testing_tag": "epel9-testing-pending", + "pending_stable_tag": "epel9-pending", + "override_tag": "epel9-override", + "mail_template": "fedora_epel_legacy_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": null + }, + { + "name": "EPEL-9N", + "long_name": "Fedora EPEL 9 Next", + "version": "9", + "id_prefix": "FEDORA-EPEL-NEXT", + "branch": "epel9-next", + "dist_tag": "epel9-next", + "stable_tag": "epel9-next", + "testing_tag": "epel9-next-testing", + "candidate_tag": "epel9-next-testing-candidate", + "pending_signing_tag": "epel9-next-signing-pending", + "pending_testing_tag": "epel9-next-testing-pending", + "pending_stable_tag": "epel9-next-pending", + "override_tag": "epel9-next-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": null + }, + { + "name": "F38", + "long_name": "Fedora 38", + "version": "38", + "id_prefix": "FEDORA", + "branch": "f38", + "dist_tag": "f38", + "stable_tag": "f38-updates", + "testing_tag": "f38-updates-testing", + "candidate_tag": "f38-updates-candidate", + "pending_signing_tag": "f38-signing-pending", + "pending_testing_tag": "f38-updates-testing-pending", + "pending_stable_tag": "f38-updates-pending", + "override_tag": "f38-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "dnf", + "testing_repository": "updates-testing", + "released_on": null, + "eol": "2024-05-14", + "setting_status": null + }, + { + "name": "F38C", + "long_name": "Fedora 38 Containers", + "version": "38", + "id_prefix": "FEDORA-CONTAINER", + "branch": "f38", + "dist_tag": "f38-container", + "stable_tag": "f38-container-updates", + "testing_tag": "f38-container-updates-testing", + "candidate_tag": "f38-container-updates-candidate", + "pending_signing_tag": "", + "pending_testing_tag": "f38-container-updates-testing-pending", + "pending_stable_tag": "f38-container-updates-pending", + "override_tag": "f38-container-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": "2024-05-14", + "setting_status": null + }, + { + "name": "F38F", + "long_name": "Fedora 38 Flatpaks", + "version": "38", + "id_prefix": "FEDORA-FLATPAK", + "branch": "f38", + "dist_tag": "f38-flatpak", + "stable_tag": "f38-flatpak-updates", + "testing_tag": "f38-flatpak-updates-testing", + "candidate_tag": "f38-flatpak-updates-candidate", + "pending_signing_tag": "", + "pending_testing_tag": "f38-flatpak-updates-testing-pending", + "pending_stable_tag": "f38-flatpak-updates-pending", + "override_tag": "f38-flatpak-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": null + }, + { + "name": "F38M", + "long_name": "Fedora 38 Modular", + "version": "38", + "id_prefix": "FEDORA-MODULAR", + "branch": "f38m", + "dist_tag": "f38-modular", + "stable_tag": "f38-modular-updates", + "testing_tag": "f38-modular-updates-testing", + "candidate_tag": "f38-modular-updates-candidate", + "pending_signing_tag": "f38-modular-signing-pending", + "pending_testing_tag": "f38-modular-updates-testing-pending", + "pending_stable_tag": "f38-modular-updates-pending", + "override_tag": "f38-modular-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": "2024-05-14", + "setting_status": null + }, + { + "name": "F39", + "long_name": "Fedora 39", + "version": "39", + "id_prefix": "FEDORA", + "branch": "f39", + "dist_tag": "f39", + "stable_tag": "f39-updates", + "testing_tag": "f39-updates-testing", + "candidate_tag": "f39-updates-candidate", + "pending_signing_tag": "f39-signing-pending", + "pending_testing_tag": "f39-updates-testing-pending", + "pending_stable_tag": "f39-updates-pending", + "override_tag": "f39-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "dnf", + "testing_repository": "updates-testing", + "released_on": null, + "eol": "2024-11-12", + "setting_status": null + }, + { + "name": "F39C", + "long_name": "Fedora 39 Containers", + "version": "39", + "id_prefix": "FEDORA-CONTAINER", + "branch": "f39", + "dist_tag": "f39-container", + "stable_tag": "f39-container-updates", + "testing_tag": "f39-container-updates-testing", + "candidate_tag": "f39-container-updates-candidate", + "pending_signing_tag": "", + "pending_testing_tag": "f39-container-updates-testing-pending", + "pending_stable_tag": "f39-container-updates-pending", + "override_tag": "f39-container-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": "2024-11-12", + "setting_status": null + }, + { + "name": "F39F", + "long_name": "Fedora 39 Flatpaks", + "version": "39", + "id_prefix": "FEDORA-FLATPAK", + "branch": "f39", + "dist_tag": "f39-flatpak", + "stable_tag": "f39-flatpak-updates", + "testing_tag": "f39-flatpak-updates-testing", + "candidate_tag": "f39-flatpak-updates-candidate", + "pending_signing_tag": "", + "pending_testing_tag": "f39-flatpak-updates-testing-pending", + "pending_stable_tag": "f39-flatpak-updates-pending", + "override_tag": "f39-flatpak-override", + "mail_template": "fedora_errata_template", + "state": "current", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": "2024-11-12", + "setting_status": null + } + ], + "page": 1, + "pages": 1, + "rows_per_page": 20, + "total": 12 +} diff --git a/tests/data/bodhi-f40-branch-window-frozen.json b/tests/data/bodhi-f40-branch-window-frozen.json new file mode 100644 index 0000000..2a4f168 --- /dev/null +++ b/tests/data/bodhi-f40-branch-window-frozen.json @@ -0,0 +1,7 @@ +{ + "releases": [], + "page": 1, + "pages": 0, + "rows_per_page": 20, + "total": 0 +} diff --git a/tests/data/bodhi-f40-branch-window-pending.json b/tests/data/bodhi-f40-branch-window-pending.json new file mode 100644 index 0000000..71085f8 --- /dev/null +++ b/tests/data/bodhi-f40-branch-window-pending.json @@ -0,0 +1,128 @@ +{ + "releases": [ + { + "name": "ELN", + "long_name": "Fedora ELN", + "version": "eln", + "id_prefix": "FEDORA", + "branch": "eln", + "dist_tag": "eln", + "stable_tag": "eln", + "testing_tag": "eln-updates-testing", + "candidate_tag": "eln-updates-candidate", + "pending_signing_tag": "eln-signing-pending", + "pending_testing_tag": "eln-updates-testing-pending", + "pending_stable_tag": "eln-updates-pending", + "override_tag": "eln-override", + "mail_template": "fedora_errata_template", + "state": "pending", + "composed_by_bodhi": false, + "create_automatic_updates": true, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": "pre_beta" + }, + { + "name": "F40", + "long_name": "Fedora 40", + "version": "40", + "id_prefix": "FEDORA", + "branch": "rawhide", + "dist_tag": "f40", + "stable_tag": "f40", + "testing_tag": "f40-updates-testing", + "candidate_tag": "f40-updates-candidate", + "pending_signing_tag": "f40-signing-pending", + "pending_testing_tag": "f40-updates-testing-pending", + "pending_stable_tag": "f40-updates-pending", + "override_tag": "f40-override", + "mail_template": "fedora_errata_template", + "state": "pending", + "composed_by_bodhi": false, + "create_automatic_updates": true, + "package_manager": "dnf", + "testing_repository": "updates-testing", + "released_on": null, + "eol": null, + "setting_status": "pre_beta" + }, + { + "name": "F40C", + "long_name": "Fedora 40 Containers", + "version": "40", + "id_prefix": "FEDORA-CONTAINER", + "branch": "f40", + "dist_tag": "f40-container", + "stable_tag": "f40-container-updates", + "testing_tag": "f40-container-updates-testing", + "candidate_tag": "f40-container-updates-candidate", + "pending_signing_tag": "", + "pending_testing_tag": "f40-container-updates-testing-pending", + "pending_stable_tag": "f40-container-updates-pending", + "override_tag": "f40-container-override", + "mail_template": "fedora_errata_template", + "state": "pending", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": null + }, + { + "name": "F41", + "long_name": "Fedora 41", + "version": "41", + "id_prefix": "FEDORA", + "branch": "f41", + "dist_tag": "f41", + "stable_tag": "f41", + "testing_tag": "f41-updates-testing", + "candidate_tag": "f41-updates-candidate", + "pending_signing_tag": "f41-signing-pending", + "pending_testing_tag": "f41-updates-testing-pending", + "pending_stable_tag": "f41-updates-pending", + "override_tag": "f41-override", + "mail_template": "fedora_errata_template", + "state": "pending", + "composed_by_bodhi": false, + "create_automatic_updates": true, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": "pre_beta" + }, + { + "name": "F41C", + "long_name": "Fedora 41 Containers", + "version": "41", + "id_prefix": "FEDORA-CONTAINER", + "branch": "f41", + "dist_tag": "f41-container", + "stable_tag": "f41-container-updates", + "testing_tag": "f41-container-updates-testing", + "candidate_tag": "f41-container-updates-candidate", + "pending_signing_tag": "", + "pending_testing_tag": "f41-container-updates-testing-pending", + "pending_stable_tag": "f41-container-updates-pending", + "override_tag": "f41-container-override", + "mail_template": "fedora_errata_template", + "state": "pending", + "composed_by_bodhi": true, + "create_automatic_updates": false, + "package_manager": "unspecified", + "testing_repository": null, + "released_on": null, + "eol": null, + "setting_status": "pre_beta" + } + ], + "page": 1, + "pages": 1, + "rows_per_page": 20, + "total": 5 +} diff --git a/tests/test_fedora_distro_aliases.py b/tests/test_fedora_distro_aliases.py index a1b2be1..56f3240 100644 --- a/tests/test_fedora_distro_aliases.py +++ b/tests/test_fedora_distro_aliases.py @@ -1,5 +1,27 @@ +import os +import json +from unittest.mock import patch, MagicMock from munch import Munch -from fedora_distro_aliases import Distro +from fedora_distro_aliases import Distro, get_distro_aliases + +here = os.path.abspath(os.path.dirname(__file__)) +datadir = os.path.join(here, "data") + + +def mock_responses(files): + """ + Every `bodhi_active_releases` call sends 3 HTTP requests. To comfortably + mock their responses from saved files, we can use this function. + """ + responses = [] + for name in files: + path = os.path.join(datadir, name) + with open(path, "r") as fp: + data = json.load(fp) + response = MagicMock() + response.json.return_value = data + responses.append(response) + return responses def test_distro(): @@ -20,3 +42,23 @@ def test_distro(): assert distro.product == "fedora" assert "nonsense" not in distro assert "additional" not in distro + + +@patch("requests.get") +def test_f40_branch_to_final_release_window(requests_get): + """ + Test that everything behaves as expected during the window from branching + to the final release. + """ + requests_get.side_effect = mock_responses([ + "bodhi-f40-branch-window-current.json", + "bodhi-f40-branch-window-pending.json", + "bodhi-f40-branch-window-frozen.json", + ]) + aliases = get_distro_aliases() + branches = [x.branch for x in aliases["fedora-all"]] + assert branches == ["f38", "f39", "f40", "rawhide"] + + namevers = [x.namever for x in aliases["fedora-all"]] + expected = ["fedora-38", "fedora-39", "fedora-40", "fedora-rawhide"] + assert namevers == expected