parent
d79e108f8d
commit
45b8b88166
3 changed files with 41 additions and 10 deletions
|
@ -147,6 +147,21 @@ class TestMonitor(UptimeKumaTestCase):
|
|||
}
|
||||
self.do_test_monitor_type(expected_monitor)
|
||||
|
||||
def test_edit_notification_id_list(self):
|
||||
# https://github.com/lucasheld/uptime-kuma-api/issues/3
|
||||
|
||||
monitor_id = self.add_monitor()
|
||||
notification_id = self.add_notification()
|
||||
|
||||
expected_monitor = self.api.get_monitor(monitor_id)
|
||||
expected_monitor["notificationIDList"] = {str(notification_id): True}
|
||||
|
||||
r = self.api.edit_monitor(id_=monitor_id, notificationIDList=[notification_id])
|
||||
self.assertEqual(r["msg"], "Saved.")
|
||||
|
||||
monitor = self.api.get_monitor(monitor_id)
|
||||
self.compare(monitor, expected_monitor)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -11,8 +11,14 @@ def compare(subset, superset):
|
|||
value2 = superset.get(key)
|
||||
if type(value) == list:
|
||||
for i in range(len(value)):
|
||||
if not value2 or not compare(value[i], value2[i]):
|
||||
if not value2:
|
||||
return False
|
||||
elif type(value[i]) == list or type(value[i]) == dict:
|
||||
if not compare(value[i], value2[i]):
|
||||
return False
|
||||
else:
|
||||
if value[i] != value2[i]:
|
||||
return False
|
||||
elif type(value) == dict:
|
||||
if not compare(value, value2):
|
||||
return False
|
||||
|
@ -72,3 +78,8 @@ class UptimeKumaTestCase(unittest.TestCase):
|
|||
r = self.api.add_tag(name="tag 1", color="#ffffff")
|
||||
tag_id = r["id"]
|
||||
return tag_id
|
||||
|
||||
def add_notification(self):
|
||||
r = self.api.add_notification(name="notification 1", type="PushByTechulus", pushAPIKey="123456789")
|
||||
notification_id = r["id"]
|
||||
return notification_id
|
||||
|
|
|
@ -23,6 +23,18 @@ def int_to_bool(data, keys):
|
|||
data[key] = True if data[key] == 1 else False
|
||||
|
||||
|
||||
def _convert_monitor_data(**kwargs):
|
||||
if not kwargs["accepted_statuscodes"]:
|
||||
kwargs["accepted_statuscodes"] = ["200-299"]
|
||||
|
||||
dict_notification_ids = {}
|
||||
if kwargs["notificationIDList"]:
|
||||
for notification_id in kwargs["notificationIDList"]:
|
||||
dict_notification_ids[notification_id] = True
|
||||
kwargs["notificationIDList"] = dict_notification_ids
|
||||
return kwargs
|
||||
|
||||
|
||||
def _build_monitor_data(
|
||||
type: MonitorType,
|
||||
name: str,
|
||||
|
@ -78,15 +90,6 @@ def _build_monitor_data(
|
|||
"Connection Timeout=<int>",
|
||||
databaseQuery: str = None
|
||||
):
|
||||
if not accepted_statuscodes:
|
||||
accepted_statuscodes = ["200-299"]
|
||||
|
||||
dict_notification_ids = {}
|
||||
if notificationIDList:
|
||||
for notification_id in notificationIDList:
|
||||
dict_notification_ids[notification_id] = True
|
||||
notificationIDList = dict_notification_ids
|
||||
|
||||
data = {
|
||||
"type": type,
|
||||
"name": name,
|
||||
|
@ -525,6 +528,7 @@ class UptimeKumaApi(object):
|
|||
|
||||
def add_monitor(self, **kwargs):
|
||||
data = _build_monitor_data(**kwargs)
|
||||
data = _convert_monitor_data(**data)
|
||||
_check_arguments_monitor(data)
|
||||
r = self._call('add', data)
|
||||
return r
|
||||
|
@ -532,6 +536,7 @@ class UptimeKumaApi(object):
|
|||
def edit_monitor(self, id_: int, **kwargs):
|
||||
data = self.get_monitor(id_)
|
||||
data.update(kwargs)
|
||||
data = _convert_monitor_data(**data)
|
||||
_check_arguments_monitor(data)
|
||||
r = self._call('editMonitor', data)
|
||||
return r
|
||||
|
|
Loading…
Reference in a new issue