forked from GithubBackups/healthchecks
Add fallback for legacy sms values
This commit is contained in:
parent
855d188981
commit
e91441d814
@ -742,14 +742,20 @@ class Channel(models.Model):
|
||||
@property
|
||||
def sms_notify_up(self):
|
||||
assert self.kind == "sms"
|
||||
if not self.value.startswith("{"):
|
||||
return False
|
||||
|
||||
doc = json.loads(self.value)
|
||||
return doc["up"]
|
||||
return doc.get("up", False)
|
||||
|
||||
@property
|
||||
def sms_notify_down(self):
|
||||
assert self.kind == "sms"
|
||||
if not self.value.startswith("{"):
|
||||
return True
|
||||
|
||||
doc = json.loads(self.value)
|
||||
return doc["down"]
|
||||
return doc.get("down", True)
|
||||
|
||||
@property
|
||||
def opsgenie_key(self):
|
||||
|
@ -50,3 +50,13 @@ class ChannelModelTestCase(BaseTestCase):
|
||||
c.value = json.dumps({"key": "abc", "region": "eu"})
|
||||
self.assertEqual(c.opsgenie_key, "abc")
|
||||
self.assertEqual(c.opsgenie_region, "eu")
|
||||
|
||||
def test_it_handles_legacy_sms_value(self):
|
||||
c = Channel(kind="sms", value="+123123123")
|
||||
self.assertTrue(c.sms_notify_down)
|
||||
self.assertFalse(c.sms_notify_up)
|
||||
|
||||
def test_it_handles_legacy_sms_json_value(self):
|
||||
c = Channel(kind="sms", value=json.dumps({"value": "+123123123"}))
|
||||
self.assertTrue(c.sms_notify_down)
|
||||
self.assertFalse(c.sms_notify_up)
|
||||
|
Loading…
x
Reference in New Issue
Block a user