|
1 | | -"""Unit tests for check_fix_versions in jira.py. |
| 1 | +"""Unit tests for check_fix_versions and _notify_pending_hotfix_if_needed. |
2 | 2 |
|
3 | 3 | Rules: |
4 | 4 | - Hotfix branch PRs require the exact 4-digit fix version in Jira |
|
11 | 11 | """ |
12 | 12 | import pytest |
13 | 13 | from types import SimpleNamespace |
| 14 | +from unittest.mock import MagicMock, patch |
14 | 15 |
|
15 | 16 | from bert_e import exceptions |
16 | | -from bert_e.workflow.gitwaterflow.jira import check_fix_versions |
| 17 | +from bert_e.workflow.gitwaterflow.jira import ( |
| 18 | + check_fix_versions, |
| 19 | + _notify_pending_hotfix_if_needed, |
| 20 | +) |
17 | 21 |
|
18 | 22 |
|
19 | 23 | def _make_issue(*version_names): |
@@ -143,3 +147,47 @@ def test_dev_branch_rejects_mismatch(): |
143 | 147 | _make_job('4.3.19', '5.1.4'), |
144 | 148 | _make_issue('4.3.18', '5.1.4'), |
145 | 149 | ) |
| 150 | + |
| 151 | + |
| 152 | +# --------------------------------------------------------------------------- |
| 153 | +# _notify_pending_hotfix_if_needed — dedup behaviour |
| 154 | +# --------------------------------------------------------------------------- |
| 155 | + |
| 156 | +def _make_notify_job(phantom_hotfix_versions=None): |
| 157 | + """Build a minimal job for _notify_pending_hotfix_if_needed tests.""" |
| 158 | + cascade = SimpleNamespace( |
| 159 | + phantom_hotfix_versions=phantom_hotfix_versions or set(), |
| 160 | + ) |
| 161 | + settings = SimpleNamespace(robot='bert-e') |
| 162 | + return SimpleNamespace( |
| 163 | + git=SimpleNamespace(cascade=cascade), |
| 164 | + settings=settings, |
| 165 | + pull_request=MagicMock(), |
| 166 | + active_options=[], |
| 167 | + ) |
| 168 | + |
| 169 | + |
| 170 | +@patch('bert_e.workflow.gitwaterflow.jira.notify_user') |
| 171 | +@patch('bert_e.workflow.gitwaterflow.jira.find_comment', return_value=None) |
| 172 | +def test_pending_hotfix_posts_when_not_yet_in_history(mock_find, mock_notify): |
| 173 | + """Reminder is posted when no previous comment with that title exists.""" |
| 174 | + job = _make_notify_job(phantom_hotfix_versions={'10.0.0.0'}) |
| 175 | + issue = _make_issue('9.5.3', '10.0.0.0', '10.1.0') |
| 176 | + _notify_pending_hotfix_if_needed(job, issue) |
| 177 | + mock_notify.assert_called_once() |
| 178 | + |
| 179 | + |
| 180 | +@patch('bert_e.workflow.gitwaterflow.jira.notify_user') |
| 181 | +@patch('bert_e.workflow.gitwaterflow.jira.find_comment', |
| 182 | + return_value=MagicMock()) |
| 183 | +def test_pending_hotfix_skips_when_already_in_history(mock_find, mock_notify): |
| 184 | + """Reminder is NOT posted when a previous comment with that title exists. |
| 185 | +
|
| 186 | + This covers the active_options footer dedup fix: even if active_options |
| 187 | + changed between runs (making the full text differ), the title-prefix |
| 188 | + check prevents a second post. |
| 189 | + """ |
| 190 | + job = _make_notify_job(phantom_hotfix_versions={'10.0.0.0'}) |
| 191 | + issue = _make_issue('9.5.3', '10.0.0.0', '10.1.0') |
| 192 | + _notify_pending_hotfix_if_needed(job, issue) |
| 193 | + mock_notify.assert_not_called() |
0 commit comments