|
11 | 11 | from netbox_change_control.choices import ChangeRequestStatusChoices, ReviewDecisionChoices |
12 | 12 | from netbox_change_control.models import ChangeRequest, ChangeRequestPolicy, Policy, Review |
13 | 13 | from netbox_change_control.policy import evaluate_change_request |
14 | | -from netbox_change_control.tests.base import add_rule, approve, make_branch, make_policy |
| 14 | +from netbox_change_control.tests.base import ChangeControlTestCase, add_rule, approve, make_branch, make_policy |
15 | 15 |
|
16 | 16 |
|
17 | 17 | class PolicyRuleEligibilityTest(TestCase): |
@@ -246,3 +246,39 @@ def test_it_does_not_weaken_another_policy(self): |
246 | 246 | approve(cr, engineer) |
247 | 247 | cr.refresh_from_db() |
248 | 248 | self.assertEqual(cr.status, ChangeRequestStatusChoices.APPROVED) |
| 249 | + |
| 250 | + |
| 251 | +class ReasonsAudienceTest(ChangeControlTestCase): |
| 252 | + """ |
| 253 | + The change request page lists every rule with its count, so repeating each shortfall in |
| 254 | + prose underneath said the same thing twice. The merge gate has no such table, so it still |
| 255 | + needs the full text. |
| 256 | + """ |
| 257 | + |
| 258 | + branch_prefix = 'reasons' |
| 259 | + |
| 260 | + def test_a_plain_shortfall_adds_nothing_to_the_page(self): |
| 261 | + evaluation = self.cr.evaluate() |
| 262 | + self.assertEqual(evaluation.other_reasons(), []) |
| 263 | + self.assertTrue(any('needs 1 more' in r for r in evaluation.reasons())) |
| 264 | + |
| 265 | + def test_a_rejection_is_shown_because_no_rule_row_carries_it(self): |
| 266 | + Review.objects.create( |
| 267 | + change_request=self.cr, |
| 268 | + reviewer=self.reviewer, |
| 269 | + decision=ReviewDecisionChoices.REJECT, |
| 270 | + comment='not yet', |
| 271 | + ) |
| 272 | + notes = self.cr.evaluate().other_reasons() |
| 273 | + self.assertEqual(len(notes), 1) |
| 274 | + self.assertIn('requested changes', notes[0]) |
| 275 | + |
| 276 | + def test_having_no_rules_at_all_is_shown(self): |
| 277 | + ChangeRequestPolicy.objects.filter(change_request=self.cr).delete() |
| 278 | + self.cr.refresh_from_db() |
| 279 | + self.assertIn('No policy rules apply', ' '.join(self.cr.evaluate().other_reasons())) |
| 280 | + |
| 281 | + def test_the_merge_gate_still_names_every_unmet_rule(self): |
| 282 | + message = self.cr.merge_blocked_reason |
| 283 | + self.assertIn('not approved', message) |
| 284 | + self.assertTrue(any('needs' in r for r in self.cr.evaluate().reasons())) |
0 commit comments