From 624c16c4a6143be05ca45b22a1b49dd6dbf58248 Mon Sep 17 00:00:00 2001 From: lucasheld Date: Wed, 3 Aug 2022 12:35:48 +0200 Subject: [PATCH] add more tests --- tests/test_clear.py | 20 ++++++++++++++++++++ tests/test_heartbeat.py | 15 +++++++++++++++ tests/test_info.py | 14 ++++++++++++++ tests/test_monitor.py | 3 ++- tests/test_monitor_tag.py | 7 +++---- tests/test_notification.py | 3 ++- tests/test_proxy.py | 4 ++-- tests/test_settings.py | 18 ++++++++++++++++++ tests/test_status_page.py | 3 ++- tests/test_tag.py | 4 ++-- tests/uptime_kuma_test_case.py | 17 ++++++++++++++--- 11 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 tests/test_clear.py create mode 100644 tests/test_heartbeat.py create mode 100644 tests/test_info.py create mode 100644 tests/test_settings.py diff --git a/tests/test_clear.py b/tests/test_clear.py new file mode 100644 index 0000000..69eeb86 --- /dev/null +++ b/tests/test_clear.py @@ -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() diff --git a/tests/test_heartbeat.py b/tests/test_heartbeat.py new file mode 100644 index 0000000..483df15 --- /dev/null +++ b/tests/test_heartbeat.py @@ -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() diff --git a/tests/test_info.py b/tests/test_info.py new file mode 100644 index 0000000..505868c --- /dev/null +++ b/tests/test_info.py @@ -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() diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 5d475af..8cc7d91 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -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): diff --git a/tests/test_monitor_tag.py b/tests/test_monitor_tag.py index f21d8cf..da173ed 100644 --- a/tests/test_monitor_tag.py +++ b/tests/test_monitor_tag.py @@ -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, diff --git a/tests/test_notification.py b/tests/test_notification.py index d34e731..782ad8e 100644 --- a/tests/test_notification.py +++ b/tests/test_notification.py @@ -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): diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 295d8e6..19304fa 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -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) diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..2777d69 --- /dev/null +++ b/tests/test_settings.py @@ -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() diff --git a/tests/test_status_page.py b/tests/test_status_page.py index 9be29cd..cf56c32 100644 --- a/tests/test_status_page.py +++ b/tests/test_status_page.py @@ -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): diff --git a/tests/test_tag.py b/tests/test_tag.py index 39df788..afc411d 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -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) diff --git a/tests/uptime_kuma_test_case.py b/tests/uptime_kuma_test_case.py index a0d4bfc..4013613 100644 --- a/tests/uptime_kuma_test_case.py +++ b/tests/uptime_kuma_test_case.py @@ -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