add more tests

This commit is contained in:
lucasheld 2022-08-05 14:35:17 +02:00
parent 512057ab61
commit 01664f5fbc
6 changed files with 73 additions and 1 deletions

13
tests/test_avg_ping.py Normal file
View file

@ -0,0 +1,13 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestAvgPing(UptimeKumaTestCase):
def test_avg_ping(self):
self.add_monitor()
self.api.avg_ping()
if __name__ == '__main__':
unittest.main()

16
tests/test_database.py Normal file
View file

@ -0,0 +1,16 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestDatabase(UptimeKumaTestCase):
def test_get_database_size(self):
r = self.api.get_database_size()
self.assertIn("size", r)
def test_shrink_database(self):
self.api.shrink_database()
if __name__ == '__main__':
unittest.main()

View file

@ -49,6 +49,9 @@ class TestMonitor(UptimeKumaTestCase):
r = self.api.resume_monitor(monitor_id)
self.assertEqual(r["msg"], "Resumed Successfully.")
# get monitor beats
self.api.get_monitor_beats(monitor_id, 6)
# delete monitor
r = self.api.delete_monitor(monitor_id)
self.assertEqual(r["msg"], "Deleted Successfully.")

View file

@ -1,4 +1,5 @@
import unittest
import json
from uptime_kuma_test_case import UptimeKumaTestCase
@ -13,6 +14,32 @@ class TestSettings(UptimeKumaTestCase):
settings = self.api.get_settings()
self.assertEqual(settings["checkUpdate"], expected_check_update)
def test_change_password(self):
new_password = "321terces"
# change password
r = self.api.change_password(self.password, new_password)
self.assertEqual(r["msg"], "Password has been updated successfully.")
# check login
r = self.api.login(self.username, new_password)
self.assertIn("token", r)
# restore password
r = self.api.change_password(new_password, self.password)
self.assertEqual(r["msg"], "Password has been updated successfully.")
def test_upload_backup(self):
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.")
if __name__ == '__main__':
unittest.main()

13
tests/test_uptime.py Normal file
View file

@ -0,0 +1,13 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestUptime(UptimeKumaTestCase):
def test_uptime(self):
self.add_monitor()
self.api.uptime()
if __name__ == '__main__':
unittest.main()

View file

@ -788,7 +788,7 @@ class UptimeKumaApi(object):
"newPassword": new_password,
})
def upload_backup(self, json_data, import_handle: str):
def upload_backup(self, json_data, import_handle: str = "skip"):
if import_handle not in ["overwrite", "skip", "keep"]:
raise ValueError()
return self._call('uploadBackup', (json_data, import_handle))