Browse Source

Add fallback for legacy sms values

pull/520/head
Pēteris Caune 4 years ago
parent
commit
e91441d814
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 18 additions and 2 deletions
  1. +8
    -2
      hc/api/models.py
  2. +10
    -0
      hc/api/tests/test_channel_model.py

+ 8
- 2
hc/api/models.py View File

@ -742,14 +742,20 @@ class Channel(models.Model):
@property @property
def sms_notify_up(self): def sms_notify_up(self):
assert self.kind == "sms" assert self.kind == "sms"
if not self.value.startswith("{"):
return False
doc = json.loads(self.value) doc = json.loads(self.value)
return doc["up"]
return doc.get("up", False)
@property @property
def sms_notify_down(self): def sms_notify_down(self):
assert self.kind == "sms" assert self.kind == "sms"
if not self.value.startswith("{"):
return True
doc = json.loads(self.value) doc = json.loads(self.value)
return doc["down"]
return doc.get("down", True)
@property @property
def opsgenie_key(self): def opsgenie_key(self):


+ 10
- 0
hc/api/tests/test_channel_model.py View File

@ -50,3 +50,13 @@ class ChannelModelTestCase(BaseTestCase):
c.value = json.dumps({"key": "abc", "region": "eu"}) c.value = json.dumps({"key": "abc", "region": "eu"})
self.assertEqual(c.opsgenie_key, "abc") self.assertEqual(c.opsgenie_key, "abc")
self.assertEqual(c.opsgenie_region, "eu") 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…
Cancel
Save