Skip to content

Commit

Permalink
fixup! Increase debugability for tristates
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Sep 26, 2023
1 parent 7a84141 commit 178b102
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/argus/notificationprofile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def incident_fits_tristates(self, incident):
if self.are_tristates_empty():
return {}
fits_tristates = {}
incident.refresh_from_db()
for tristate in self.TRINARY_FILTERS:
filter_tristate = self._get_tristate(tristate)
if filter_tristate is None:
Expand Down
15 changes: 14 additions & 1 deletion tests/notificationprofile/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ def test_incident_fits_tristates_no_tristates_set_with_fallback(self):
incident.acked = False
empty_filter = FilterWrapper({})
result = empty_filter.incident_fits_tristates(incident)
self.assertEqual(result["open"], None)
self.assertEqual(result["acked"], False)
self.assertEqual(result["stateful"], None)
# Should match
incident.acked = True
empty_filter = FilterWrapper({})
result = empty_filter.incident_fits_tristates(incident)
self.assertEqual(result["acked"], True)
self.assertNotIn(False, result.values())
self.assertEqual(result["open"], None)
self.assertEqual(result["acked"], True)
self.assertEqual(result["stateful"], None)

def test_incident_fits_tristates_is_true(self):
incident = Mock()
Expand All @@ -108,6 +112,9 @@ def test_incident_fits_tristates_is_true(self):
filter = FilterWrapper({"open": True, "acked": False})
result = filter.incident_fits_tristates(incident)
self.assertTrue(set(result.values())) # all True!
self.assertEqual(result["open"], True)
self.assertEqual(result["acked"], True)
self.assertEqual(result["stateful"], None)

def test_incident_fits_tristates_is_false(self):
incident = Mock()
Expand All @@ -117,6 +124,9 @@ def test_incident_fits_tristates_is_false(self):
filter = FilterWrapper({"open": False, "acked": False})
result = filter.incident_fits_tristates(incident)
self.assertIn(False, result.values())
self.assertEqual(result["open"], False)
self.assertEqual(result["acked"], True)
self.assertEqual(result["stateful"], None)

@override_settings(ARGUS_FALLBACK_FILTER={"acked": True})
def test_incident_fits_tristates_fallback_should_not_override(self):
Expand All @@ -127,6 +137,9 @@ def test_incident_fits_tristates_fallback_should_not_override(self):
result = filter.incident_fits_tristates(incident)
self.assertEqual(result["acked"], True)
self.assertNotIn(False, result.values())
self.assertEqual(result["open"], None)
self.assertEqual(result["acked"], True)
self.assertEqual(result["stateful"], None)


@tag("unittest")
Expand Down

0 comments on commit 178b102

Please sign in to comment.