2022-08-26 14:01:29 +02:00
|
|
|
import json
|
2022-08-02 23:47:56 +02:00
|
|
|
import unittest
|
2022-08-03 12:35:48 +02:00
|
|
|
|
2022-08-26 14:01:29 +02:00
|
|
|
from uptime_kuma_api import UptimeKumaApi, Event, MonitorType
|
2022-08-02 23:47:56 +02:00
|
|
|
|
2022-08-03 12:37:37 +02:00
|
|
|
token = None
|
|
|
|
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
class UptimeKumaTestCase(unittest.TestCase):
|
|
|
|
api = None
|
2022-08-03 12:37:37 +02:00
|
|
|
url = "http://127.0.0.1:3001"
|
2022-08-05 13:03:58 +02:00
|
|
|
username = "admin"
|
|
|
|
password = "secret123"
|
2022-08-02 23:47:56 +02:00
|
|
|
|
2022-08-26 14:01:29 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.api = UptimeKumaApi(self.url)
|
2022-08-03 12:37:37 +02:00
|
|
|
|
|
|
|
global token
|
|
|
|
if not token:
|
2022-08-26 14:01:29 +02:00
|
|
|
if self.api.need_setup():
|
|
|
|
self.api.setup(self.username, self.password)
|
|
|
|
r = self.api.login(self.username, self.password)
|
2022-08-03 12:37:37 +02:00
|
|
|
token = r["token"]
|
|
|
|
|
2022-08-26 14:01:29 +02:00
|
|
|
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.")
|
|
|
|
|
|
|
|
self.api._event_data[Event.MONITOR_LIST] = {}
|
2022-08-02 23:47:56 +02:00
|
|
|
|
2022-08-26 14:01:29 +02:00
|
|
|
def tearDown(self):
|
|
|
|
self.api.disconnect()
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
def compare(self, superset, subset):
|
2022-08-03 16:56:38 +02:00
|
|
|
self.assertTrue(subset.items() <= superset.items())
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
def find_by_id(self, objects, value, key="id"):
|
|
|
|
for obj in objects:
|
|
|
|
if obj[key] == value:
|
|
|
|
return obj
|
2022-08-03 12:35:48 +02:00
|
|
|
|
|
|
|
def add_monitor(self):
|
|
|
|
r = self.api.add_monitor(type="http", name="monitor 1", url="http://127.0.0.1")
|
|
|
|
monitor_id = r["monitorID"]
|
|
|
|
return monitor_id
|
|
|
|
|
|
|
|
def add_tag(self):
|
|
|
|
r = self.api.add_tag(name="tag 1", color="#ffffff")
|
|
|
|
tag_id = r["id"]
|
|
|
|
return tag_id
|