From e041d66cdcb5ac7d8ae079698ee325be734dfe43 Mon Sep 17 00:00:00 2001 From: lucasheld Date: Sun, 18 Sep 2022 19:54:25 +0200 Subject: [PATCH] test: delete objects instead of uploading a backup --- tests/test_status_page.py | 6 ----- tests/uptime_kuma_test_case.py | 48 +++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/tests/test_status_page.py b/tests/test_status_page.py index 5e6419a..171e593 100644 --- a/tests/test_status_page.py +++ b/tests/test_status_page.py @@ -34,12 +34,6 @@ class TestStatusPage(UptimeKumaTestCase): ] } - # slug must be unique - try: - self.api.delete_status_page(slug) - except UptimeKumaException: - pass - # add status page r = self.api.add_status_page(slug, expected_status_page["title"]) self.assertEqual(r["msg"], "OK!") diff --git a/tests/uptime_kuma_test_case.py b/tests/uptime_kuma_test_case.py index 0bb49ff..74102e2 100644 --- a/tests/uptime_kuma_test_case.py +++ b/tests/uptime_kuma_test_case.py @@ -1,7 +1,7 @@ -import json import unittest +from packaging.version import parse as parse_version -from uptime_kuma_api import UptimeKumaApi, Event, MonitorType, DockerType +from uptime_kuma_api import UptimeKumaApi, MonitorType, DockerType token = None @@ -46,17 +46,41 @@ class UptimeKumaTestCase(unittest.TestCase): self.api.login_by_token(token) - data = { - "version": "1.17.1", - "notificationList": [], - "monitorList": [], - "proxyList": [] - } - data_str = json.dumps(data) - r = self.api.upload_backup(data_str, "overwrite") - self.assertEqual(r["msg"], "Backup successfully restored.") + # delete monitors + monitors = self.api.get_monitors() + for monitor in monitors: + self.api.delete_monitor(monitor["id"]) - self.api._event_data[Event.MONITOR_LIST] = {} + # delete notifications + notifications = self.api.get_notifications() + for notification in notifications: + self.api.delete_notification(notification["id"]) + + # delete proxies + proxies = self.api.get_proxies() + for proxy in proxies: + self.api.delete_proxy(proxy["id"]) + + # delete tags + tags = self.api.get_tags() + for tag in tags: + self.api.delete_tag(tag["id"]) + + # delete status pages + status_pages = self.api.get_status_pages() + for status_page in status_pages: + self.api.delete_status_page(status_page["slug"]) + + if parse_version(self.api.version) >= parse_version("1.18"): + # delete docker hosts + docker_hosts = self.api.get_docker_hosts() + for docker_host in docker_hosts: + self.api.delete_docker_host(docker_host["id"]) + + # login again to receive initial messages + self.api.disconnect() + self.api = UptimeKumaApi(self.url) + self.api.login_by_token(token) def tearDown(self): self.api.disconnect()