add more tests

This commit is contained in:
lucasheld 2022-08-03 12:35:48 +02:00
parent 8d2c0ec4f7
commit 624c16c4a6
11 changed files with 94 additions and 14 deletions

20
tests/test_clear.py Normal file
View file

@ -0,0 +1,20 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestClear(UptimeKumaTestCase):
def test_clear_events(self):
monitor_id = self.add_monitor()
self.api.clear_events(monitor_id)
def test_clear_heartbeats(self):
monitor_id = self.add_monitor()
self.api.clear_heartbeats(monitor_id)
def test_clear_statistics(self):
self.api.clear_statistics()
if __name__ == '__main__':
unittest.main()

15
tests/test_heartbeat.py Normal file
View file

@ -0,0 +1,15 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestHeartbeat(UptimeKumaTestCase):
def test_get_heartbeats(self):
self.api.get_heartbeats()
def test_get_important_heartbeats(self):
self.api.get_important_heartbeats()
if __name__ == '__main__':
unittest.main()

14
tests/test_info.py Normal file
View file

@ -0,0 +1,14 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestInfo(UptimeKumaTestCase):
def test_info(self):
info = self.api.info()
self.assertIn("version", info)
self.assertIn("latestVersion", info)
if __name__ == '__main__':
unittest.main()

View file

@ -1,6 +1,7 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
from uptime_kuma_api import UptimeKumaException
from uptime_kuma_test_case import UptimeKumaTestCase
class TestMonitor(UptimeKumaTestCase):

View file

@ -1,13 +1,12 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestMonitorTag(UptimeKumaTestCase):
def test_monitor_tag(self):
r = self.api.add_tag(name="tag 1", color="#ffffff")
tag_id = r["id"]
r = self.api.add_monitor(type="http", name="monitor 1", url="http://127.0.0.1")
monitor_id = r["monitorID"]
tag_id = self.add_tag()
monitor_id = self.add_monitor()
expected_monitor_tag = {
"tag_id": tag_id,

View file

@ -1,6 +1,7 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
from uptime_kuma_api import UptimeKumaException
from uptime_kuma_test_case import UptimeKumaTestCase
class TestNotification(UptimeKumaTestCase):

View file

@ -1,6 +1,7 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
from uptime_kuma_api import UptimeKumaException
from uptime_kuma_test_case import UptimeKumaTestCase
class TestProxy(UptimeKumaTestCase):
@ -34,7 +35,6 @@ class TestProxy(UptimeKumaTestCase):
# delete proxy
r = self.api.delete_proxy(proxy_id)
self.assertEqual(r["msg"], "Deleted")
print(r)
with self.assertRaises(UptimeKumaException):
self.api.get_proxy(proxy_id)

18
tests/test_settings.py Normal file
View file

@ -0,0 +1,18 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
class TestSettings(UptimeKumaTestCase):
def test_settings(self):
settings_before = self.api.get_settings()
expected_check_update = not settings_before.get("checkUpdate", True)
self.api.set_settings(self.password, checkUpdate=expected_check_update)
settings = self.api.get_settings()
self.assertEqual(settings["checkUpdate"], expected_check_update)
if __name__ == '__main__':
unittest.main()

View file

@ -1,6 +1,7 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
from uptime_kuma_api import UptimeKumaException, IncidentStyle
from uptime_kuma_test_case import UptimeKumaTestCase
class TestStatusPage(UptimeKumaTestCase):

View file

@ -1,6 +1,7 @@
import unittest
from uptime_kuma_test_case import UptimeKumaTestCase
from uptime_kuma_api import UptimeKumaException
from uptime_kuma_test_case import UptimeKumaTestCase
class TestTag(UptimeKumaTestCase):
@ -28,7 +29,6 @@ class TestTag(UptimeKumaTestCase):
# delete tag
r = self.api.delete_tag(tag_id)
self.assertEqual(r["msg"], "Deleted Successfully.")
print(r)
with self.assertRaises(UptimeKumaException):
self.api.get_proxy(tag_id)

View file

@ -1,18 +1,19 @@
import unittest
from uptime_kuma_api import UptimeKumaApi
class UptimeKumaTestCase(unittest.TestCase):
api = None
password = "zS7zhQSc"
@classmethod
def setUpClass(cls):
cls.api = UptimeKumaApi("http://127.0.0.1:3001")
username = "testuser"
password = "zS7zhQSc"
if cls.api.need_setup():
cls.api.setup(username, password)
cls.api.login(username, password)
cls.api.setup(username, cls.password)
cls.api.login(username, cls.password)
@classmethod
def tearDownClass(cls):
@ -26,3 +27,13 @@ class UptimeKumaTestCase(unittest.TestCase):
for obj in objects:
if obj[key] == value:
return obj
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