feat: raise exception when deleting an element that does not exist #37
10 changed files with 80 additions and 13 deletions
|
@ -50,6 +50,10 @@ class TestApiKey(UptimeKumaTestCase):
|
||||||
with self.assertRaises(UptimeKumaException):
|
with self.assertRaises(UptimeKumaException):
|
||||||
self.api.get_api_key(api_key_id)
|
self.api.get_api_key(api_key_id)
|
||||||
|
|
||||||
|
def test_delete_not_existing_api_key(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_api_key(42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -47,6 +47,10 @@ class TestDockerHost(UptimeKumaTestCase):
|
||||||
with self.assertRaises(UptimeKumaException):
|
with self.assertRaises(UptimeKumaException):
|
||||||
self.api.get_docker_host(docker_host_id)
|
self.api.get_docker_host(docker_host_id)
|
||||||
|
|
||||||
|
def test_delete_not_existing_docker_host(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_docker_host(42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -260,6 +260,10 @@ class TestMaintenance(UptimeKumaTestCase):
|
||||||
with self.assertRaises(UptimeKumaException):
|
with self.assertRaises(UptimeKumaException):
|
||||||
self.api.get_maintenance(maintenance_id)
|
self.api.get_maintenance(maintenance_id)
|
||||||
|
|
||||||
|
def test_delete_not_existing_maintenance(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_maintenance(42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -298,6 +298,10 @@ class TestMonitor(UptimeKumaTestCase):
|
||||||
}
|
}
|
||||||
self.do_test_monitor_type(expected_monitor)
|
self.do_test_monitor_type(expected_monitor)
|
||||||
|
|
||||||
|
def test_delete_not_existing_monitor(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_monitor(42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from uptime_kuma_api import UptimeKumaException
|
||||||
from uptime_kuma_test_case import UptimeKumaTestCase
|
from uptime_kuma_test_case import UptimeKumaTestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +33,10 @@ class TestMonitorTag(UptimeKumaTestCase):
|
||||||
monitor = self.find_by_id(monitors, monitor_id)
|
monitor = self.find_by_id(monitors, monitor_id)
|
||||||
self.assertEqual(monitor["tags"], [])
|
self.assertEqual(monitor["tags"], [])
|
||||||
|
|
||||||
|
def test_delete_not_existing_monitor_tag(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_monitor_tag(42, 42, 42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -55,6 +55,10 @@ class TestNotification(UptimeKumaTestCase):
|
||||||
with self.assertRaises(UptimeKumaException):
|
with self.assertRaises(UptimeKumaException):
|
||||||
self.api.delete_notification(notification_id)
|
self.api.delete_notification(notification_id)
|
||||||
|
|
||||||
|
def test_delete_not_existing_notification(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_notification(42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -50,6 +50,10 @@ class TestProxy(UptimeKumaTestCase):
|
||||||
with self.assertRaises(UptimeKumaException):
|
with self.assertRaises(UptimeKumaException):
|
||||||
self.api.get_proxy(proxy_id)
|
self.api.get_proxy(proxy_id)
|
||||||
|
|
||||||
|
def test_delete_not_existing_proxy(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_proxy(42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -89,6 +89,10 @@ class TestStatusPage(UptimeKumaTestCase):
|
||||||
status_page = self.find_by_id(status_pages, slug, "slug")
|
status_page = self.find_by_id(status_pages, slug, "slug")
|
||||||
self.assertIsNone(status_page)
|
self.assertIsNone(status_page)
|
||||||
|
|
||||||
|
def test_delete_not_existing_status_page(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_status_page("slug42")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -40,6 +40,10 @@ class TestTag(UptimeKumaTestCase):
|
||||||
with self.assertRaises(UptimeKumaException):
|
with self.assertRaises(UptimeKumaException):
|
||||||
self.api.get_tag(tag_id)
|
self.api.get_tag(tag_id)
|
||||||
|
|
||||||
|
def test_delete_not_existing_tag(self):
|
||||||
|
with self.assertRaises(UptimeKumaException):
|
||||||
|
self.api.delete_tag(42)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1111,6 +1111,8 @@ class UptimeKumaApi(object):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
with self.wait_for_event(Event.MONITOR_LIST):
|
with self.wait_for_event(Event.MONITOR_LIST):
|
||||||
|
if id_ not in [i["id"] for i in self.get_monitors()]:
|
||||||
|
raise UptimeKumaException("monitor does not exist")
|
||||||
return self._call('deleteMonitor', id_)
|
return self._call('deleteMonitor', id_)
|
||||||
|
|
||||||
def get_monitor_beats(self, id_: int, hours: int) -> list[dict]:
|
def get_monitor_beats(self, id_: int, hours: int) -> list[dict]:
|
||||||
|
@ -1304,6 +1306,18 @@ class UptimeKumaApi(object):
|
||||||
'msg': 'Deleted Successfully.'
|
'msg': 'Deleted Successfully.'
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
with self.wait_for_event(Event.MONITOR_LIST):
|
||||||
|
tags = [
|
||||||
|
{
|
||||||
|
"monitor_id": y["monitor_id"],
|
||||||
|
"tag_id": y["tag_id"],
|
||||||
|
"value": y["value"]
|
||||||
|
} for x in [
|
||||||
|
i.get("tags") for i in self.get_monitors()
|
||||||
|
] for y in x
|
||||||
|
]
|
||||||
|
if {"monitor_id": monitor_id, "tag_id": tag_id, "value": value} not in tags:
|
||||||
|
raise UptimeKumaException("monitor tag does not exist")
|
||||||
r = self._call('deleteMonitorTag', (tag_id, monitor_id, value))
|
r = self._call('deleteMonitorTag', (tag_id, monitor_id, value))
|
||||||
# the monitor list event does not send the updated tags
|
# the monitor list event does not send the updated tags
|
||||||
self._event_data[Event.MONITOR_LIST][str(monitor_id)] = self.get_monitor(monitor_id)
|
self._event_data[Event.MONITOR_LIST][str(monitor_id)] = self.get_monitor(monitor_id)
|
||||||
|
@ -1487,6 +1501,8 @@ class UptimeKumaApi(object):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
with self.wait_for_event(Event.NOTIFICATION_LIST):
|
with self.wait_for_event(Event.NOTIFICATION_LIST):
|
||||||
|
if id_ not in [i["id"] for i in self.get_notifications()]:
|
||||||
|
raise UptimeKumaException("notification does not exist")
|
||||||
return self._call('deleteNotification', id_)
|
return self._call('deleteNotification', id_)
|
||||||
|
|
||||||
def check_apprise(self) -> bool:
|
def check_apprise(self) -> bool:
|
||||||
|
@ -1646,6 +1662,8 @@ class UptimeKumaApi(object):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
with self.wait_for_event(Event.PROXY_LIST):
|
with self.wait_for_event(Event.PROXY_LIST):
|
||||||
|
if id_ not in [i["id"] for i in self.get_proxies()]:
|
||||||
|
raise UptimeKumaException("proxy does not exist")
|
||||||
return self._call('deleteProxy', id_)
|
return self._call('deleteProxy', id_)
|
||||||
|
|
||||||
# status page
|
# status page
|
||||||
|
@ -1783,6 +1801,9 @@ class UptimeKumaApi(object):
|
||||||
>>> api.delete_status_page("slug1")
|
>>> api.delete_status_page("slug1")
|
||||||
{}
|
{}
|
||||||
"""
|
"""
|
||||||
|
with self.wait_for_event(Event.STATUS_PAGE_LIST):
|
||||||
|
if slug not in [i["slug"] for i in self.get_status_pages()]:
|
||||||
|
raise UptimeKumaException("status page does not exist")
|
||||||
r = self._call('deleteStatusPage', slug)
|
r = self._call('deleteStatusPage', slug)
|
||||||
|
|
||||||
# uptime kuma does not send the status page list event when a status page is deleted
|
# uptime kuma does not send the status page list event when a status page is deleted
|
||||||
|
@ -2424,6 +2445,8 @@ class UptimeKumaApi(object):
|
||||||
'msg': 'Deleted Successfully.'
|
'msg': 'Deleted Successfully.'
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
if id_ not in [i["id"] for i in self.get_tags()]:
|
||||||
|
raise UptimeKumaException("tag does not exist")
|
||||||
return self._call('deleteTag', id_)
|
return self._call('deleteTag', id_)
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
|
@ -3000,6 +3023,8 @@ class UptimeKumaApi(object):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
with self.wait_for_event(Event.DOCKER_HOST_LIST):
|
with self.wait_for_event(Event.DOCKER_HOST_LIST):
|
||||||
|
if id_ not in [i["id"] for i in self.get_docker_hosts()]:
|
||||||
|
raise UptimeKumaException("docker host does not exist")
|
||||||
return self._call('deleteDockerHost', id_)
|
return self._call('deleteDockerHost', id_)
|
||||||
|
|
||||||
# maintenance
|
# maintenance
|
||||||
|
@ -3355,6 +3380,9 @@ class UptimeKumaApi(object):
|
||||||
"msg": "Deleted Successfully."
|
"msg": "Deleted Successfully."
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
with self.wait_for_event(Event.MAINTENANCE_LIST):
|
||||||
|
if id_ not in [i["id"] for i in self.get_maintenances()]:
|
||||||
|
raise UptimeKumaException("maintenance does not exist")
|
||||||
return self._call('deleteMaintenance', id_)
|
return self._call('deleteMaintenance', id_)
|
||||||
|
|
||||||
def pause_maintenance(self, id_: int) -> dict:
|
def pause_maintenance(self, id_: int) -> dict:
|
||||||
|
@ -3672,6 +3700,8 @@ class UptimeKumaApi(object):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
with self.wait_for_event(Event.API_KEY_LIST):
|
with self.wait_for_event(Event.API_KEY_LIST):
|
||||||
|
if id_ not in [i["id"] for i in self.get_api_keys()]:
|
||||||
|
raise UptimeKumaException("api key does not exist")
|
||||||
return self._call('deleteAPIKey', id_)
|
return self._call('deleteAPIKey', id_)
|
||||||
|
|
||||||
# helper methods
|
# helper methods
|
||||||
|
|
Loading…
Reference in a new issue