test: delete objects instead of uploading a backup

This commit is contained in:
lucasheld 2022-09-18 19:54:25 +02:00
parent a409c2dbaa
commit e041d66cdc
2 changed files with 36 additions and 18 deletions

View file

@ -34,12 +34,6 @@ class TestStatusPage(UptimeKumaTestCase):
] ]
} }
# slug must be unique
try:
self.api.delete_status_page(slug)
except UptimeKumaException:
pass
# add status page # add status page
r = self.api.add_status_page(slug, expected_status_page["title"]) r = self.api.add_status_page(slug, expected_status_page["title"])
self.assertEqual(r["msg"], "OK!") self.assertEqual(r["msg"], "OK!")

View file

@ -1,7 +1,7 @@
import json
import unittest 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 token = None
@ -46,17 +46,41 @@ class UptimeKumaTestCase(unittest.TestCase):
self.api.login_by_token(token) self.api.login_by_token(token)
data = { # delete monitors
"version": "1.17.1", monitors = self.api.get_monitors()
"notificationList": [], for monitor in monitors:
"monitorList": [], self.api.delete_monitor(monitor["id"])
"proxyList": []
}
data_str = json.dumps(data)
r = self.api.upload_backup(data_str, "overwrite")
self.assertEqual(r["msg"], "Backup successfully restored.")
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): def tearDown(self):
self.api.disconnect() self.api.disconnect()