reset uptime kuma config after each test

This commit is contained in:
lucasheld 2022-08-26 14:01:29 +02:00
parent 8f108a700b
commit 804bd85909
2 changed files with 30 additions and 16 deletions

View file

@ -1,7 +1,7 @@
import json
import unittest
from uptime_kuma_api import UptimeKumaApi
from uptime_kuma_api import UptimeKumaApi, Event, MonitorType
token = None
@ -12,22 +12,32 @@ class UptimeKumaTestCase(unittest.TestCase):
username = "admin"
password = "secret123"
@classmethod
def setUpClass(cls):
cls.api = UptimeKumaApi(cls.url)
def setUp(self):
self.api = UptimeKumaApi(self.url)
global token
if not token:
if cls.api.need_setup():
cls.api.setup(cls.username, cls.password)
r = cls.api.login(cls.username, cls.password)
if self.api.need_setup():
self.api.setup(self.username, self.password)
r = self.api.login(self.username, self.password)
token = r["token"]
cls.api.login_by_token(token)
self.api.login_by_token(token)
@classmethod
def tearDownClass(cls):
cls.api.disconnect()
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] = {}
def tearDown(self):
self.api.disconnect()
def compare(self, superset, subset):
self.assertTrue(subset.items() <= superset.items())

View file

@ -366,6 +366,7 @@ def _check_arguments_proxy(kwargs):
class UptimeKumaApi(object):
def __init__(self, url):
self.url = url
self.sio = socketio.Client()
self._event_data: dict = {
@ -396,7 +397,7 @@ class UptimeKumaApi(object):
self.sio.on(Event.INFO, self._event_info)
self.sio.on(Event.CERT_INFO, self._event_cert_info)
self.connect(url)
self.connect()
def _get_event_data(self, event):
monitor_events = [Event.AVG_PING, Event.UPTIME, Event.HEARTBEAT_LIST, Event.IMPORTANT_HEARTBEAT_LIST, Event.CERT_INFO, Event.HEARTBEAT]
@ -489,9 +490,12 @@ class UptimeKumaApi(object):
# connection
def connect(self, url: str):
url = url.rstrip("/")
self.sio.connect(f'{url}/socket.io/')
def connect(self):
url = self.url.rstrip("/")
try:
self.sio.connect(f'{url}/socket.io/')
except:
print("")
def disconnect(self):
self.sio.disconnect()