|
| 1 | +"""Unit tests for check_fix_versions in jira.py. |
| 2 | +
|
| 3 | +Covers the pre-GA hotfix dual-acceptance rule: |
| 4 | + - When the hotfix branch has no GA tag yet (hfrev == 0 → target ends |
| 5 | + in ".0"), both the 4-digit form ("10.0.0.0") AND the 3-digit base |
| 6 | + ("10.0.0") must be accepted. |
| 7 | + - Once the GA tag is pushed (hfrev advances to 1 → target becomes |
| 8 | + "10.0.0.1"), only the exact 4-digit version is accepted again. |
| 9 | +""" |
| 10 | +import pytest |
| 11 | +from types import SimpleNamespace |
| 12 | + |
| 13 | +from bert_e import exceptions |
| 14 | +from bert_e.workflow.gitwaterflow.jira import check_fix_versions |
| 15 | + |
| 16 | + |
| 17 | +def _make_issue(*version_names): |
| 18 | + versions = [SimpleNamespace(name=v) for v in version_names] |
| 19 | + return SimpleNamespace( |
| 20 | + key='TEST-00001', |
| 21 | + fields=SimpleNamespace(fixVersions=versions), |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | +def _make_job(*target_versions): |
| 26 | + cascade = SimpleNamespace(target_versions=list(target_versions)) |
| 27 | + git = SimpleNamespace(cascade=cascade) |
| 28 | + return SimpleNamespace(git=git, active_options=[]) |
| 29 | + |
| 30 | + |
| 31 | +# --------------------------------------------------------------------------- |
| 32 | +# Pre-GA hotfix: target ends in ".0" (hfrev == 0, no GA tag yet) |
| 33 | +# --------------------------------------------------------------------------- |
| 34 | + |
| 35 | +def test_pre_ga_hotfix_accepts_four_digit_version(): |
| 36 | + """Jira with '10.0.0.0' is accepted for pre-GA hotfix/10.0.0.""" |
| 37 | + check_fix_versions(_make_job('10.0.0.0'), _make_issue('10.0.0.0')) |
| 38 | + |
| 39 | + |
| 40 | +def test_pre_ga_hotfix_accepts_three_digit_version(): |
| 41 | + """Jira with '10.0.0' is accepted for pre-GA hotfix/10.0.0 (no GA tag).""" |
| 42 | + check_fix_versions(_make_job('10.0.0.0'), _make_issue('10.0.0')) |
| 43 | + |
| 44 | + |
| 45 | +def test_pre_ga_hotfix_accepts_three_digit_among_others(): |
| 46 | + """Jira with '10.0.0' among other versions is still accepted.""" |
| 47 | + check_fix_versions( |
| 48 | + _make_job('10.0.0.0'), |
| 49 | + _make_issue('9.5.3', '10.0.0', '11.0.0'), |
| 50 | + ) |
| 51 | + |
| 52 | + |
| 53 | +def test_pre_ga_hotfix_rejects_wrong_version(): |
| 54 | + """Unrelated version is rejected for pre-GA hotfix/10.0.0.""" |
| 55 | + with pytest.raises(exceptions.IncorrectFixVersion): |
| 56 | + check_fix_versions(_make_job('10.0.0.0'), _make_issue('9.5.0')) |
| 57 | + |
| 58 | + |
| 59 | +def test_pre_ga_hotfix_rejects_empty_versions(): |
| 60 | + """No fix version in Jira is rejected for pre-GA hotfix/10.0.0.""" |
| 61 | + with pytest.raises(exceptions.IncorrectFixVersion): |
| 62 | + check_fix_versions(_make_job('10.0.0.0'), _make_issue()) |
| 63 | + |
| 64 | + |
| 65 | +def test_pre_ga_hotfix_rejects_next_micro(): |
| 66 | + """'10.0.1' is not a valid substitute for pre-GA '10.0.0.0'.""" |
| 67 | + with pytest.raises(exceptions.IncorrectFixVersion): |
| 68 | + check_fix_versions(_make_job('10.0.0.0'), _make_issue('10.0.1')) |
| 69 | + |
| 70 | + |
| 71 | +# --------------------------------------------------------------------------- |
| 72 | +# Post-GA hotfix: target does NOT end in ".0" (hfrev >= 1, GA tag exists) |
| 73 | +# --------------------------------------------------------------------------- |
| 74 | + |
| 75 | +def test_post_ga_hotfix_accepts_correct_4digit(): |
| 76 | + """'10.0.0.1' in Jira is accepted for post-GA hotfix (hfrev=1).""" |
| 77 | + check_fix_versions(_make_job('10.0.0.1'), _make_issue('10.0.0.1')) |
| 78 | + |
| 79 | + |
| 80 | +def test_post_ga_hotfix_rejects_3digit_base(): |
| 81 | + """'10.0.0' is NOT accepted once GA tag exists (target is '10.0.0.1').""" |
| 82 | + with pytest.raises(exceptions.IncorrectFixVersion): |
| 83 | + check_fix_versions(_make_job('10.0.0.1'), _make_issue('10.0.0')) |
| 84 | + |
| 85 | + |
| 86 | +def test_post_ga_hotfix_rejects_pre_ga_4digit(): |
| 87 | + """'10.0.0.0' is NOT accepted once GA tag exists (target is '10.0.0.1').""" |
| 88 | + with pytest.raises(exceptions.IncorrectFixVersion): |
| 89 | + check_fix_versions(_make_job('10.0.0.1'), _make_issue('10.0.0.0')) |
| 90 | + |
| 91 | + |
| 92 | +def test_post_ga_second_hotfix(): |
| 93 | + """'10.0.0.2' in Jira is accepted for second post-GA hotfix (hfrev=2).""" |
| 94 | + check_fix_versions(_make_job('10.0.0.2'), _make_issue('10.0.0.2')) |
| 95 | + |
| 96 | + |
| 97 | +def test_post_ga_hotfix_rejects_lower_hfrev(): |
| 98 | + """'10.0.0.1' is NOT accepted when target is '10.0.0.2'.""" |
| 99 | + with pytest.raises(exceptions.IncorrectFixVersion): |
| 100 | + check_fix_versions(_make_job('10.0.0.2'), _make_issue('10.0.0.1')) |
| 101 | + |
| 102 | + |
| 103 | +# --------------------------------------------------------------------------- |
| 104 | +# Regular dev-branch PR (not hotfix) — pre-existing behaviour unchanged |
| 105 | +# --------------------------------------------------------------------------- |
| 106 | + |
| 107 | +def test_dev_branch_accepts_matching_versions(): |
| 108 | + """Standard 3-digit dev-branch version check still works.""" |
| 109 | + check_fix_versions( |
| 110 | + _make_job('4.3.19', '5.1.4'), |
| 111 | + _make_issue('4.3.19', '5.1.4'), |
| 112 | + ) |
| 113 | + |
| 114 | + |
| 115 | +def test_dev_branch_rejects_mismatch(): |
| 116 | + """Wrong versions for a dev-branch PR are still rejected.""" |
| 117 | + with pytest.raises(exceptions.IncorrectFixVersion): |
| 118 | + check_fix_versions( |
| 119 | + _make_job('4.3.19', '5.1.4'), |
| 120 | + _make_issue('4.3.18', '5.1.4'), |
| 121 | + ) |
0 commit comments