2022-12-29 00:22:53 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from uptime_kuma_api import UptimeKumaException, MaintenanceStrategy
|
|
|
|
from uptime_kuma_test_case import UptimeKumaTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class TestMaintenance(UptimeKumaTestCase):
|
|
|
|
def test_maintenance(self):
|
|
|
|
expected_maintenance = {
|
|
|
|
"title": "maintenance 1",
|
|
|
|
"description": "test",
|
2022-12-30 21:37:10 +01:00
|
|
|
"strategy": MaintenanceStrategy.SINGLE,
|
2022-12-29 00:22:53 +01:00
|
|
|
"active": True,
|
|
|
|
"intervalDay": 1,
|
|
|
|
"dateRange": [
|
|
|
|
"2022-12-27 22:36:00",
|
|
|
|
"2022-12-29 22:36:00"
|
|
|
|
],
|
|
|
|
"weekdays": [],
|
2023-05-20 12:43:57 +02:00
|
|
|
"daysOfMonth": [],
|
|
|
|
"timezoneOption": "Europe/Berlin"
|
2022-12-29 00:22:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# add maintenance
|
|
|
|
r = self.api.add_maintenance(**expected_maintenance)
|
|
|
|
self.assertEqual(r["msg"], "Added Successfully.")
|
|
|
|
maintenance_id = r["maintenanceID"]
|
|
|
|
|
|
|
|
# get maintenance
|
|
|
|
maintenance = self.api.get_maintenance(maintenance_id)
|
2023-05-25 21:26:54 +02:00
|
|
|
self.assertTrue(type(maintenance["strategy"]) == MaintenanceStrategy)
|
2022-12-29 00:22:53 +01:00
|
|
|
self.compare(maintenance, expected_maintenance)
|
|
|
|
|
|
|
|
# get maintenances
|
|
|
|
maintenances = self.api.get_maintenances()
|
2023-05-25 21:26:54 +02:00
|
|
|
self.assertTrue(type(maintenances[0]["strategy"]) == MaintenanceStrategy)
|
2022-12-29 00:22:53 +01:00
|
|
|
maintenance = self.find_by_id(maintenances, maintenance_id)
|
|
|
|
self.assertIsNotNone(maintenance)
|
|
|
|
self.compare(maintenance, expected_maintenance)
|
|
|
|
|
|
|
|
# edit maintenance
|
|
|
|
expected_maintenance["strategy"] = MaintenanceStrategy.RECURRING_INTERVAL
|
|
|
|
expected_maintenance["title"] = "maintenance 1 new"
|
|
|
|
r = self.api.edit_maintenance(maintenance_id, **expected_maintenance)
|
|
|
|
self.assertEqual(r["msg"], "Saved.")
|
|
|
|
maintenance = self.api.get_maintenance(maintenance_id)
|
|
|
|
self.compare(maintenance, expected_maintenance)
|
|
|
|
|
|
|
|
# pause maintenance
|
|
|
|
r = self.api.pause_maintenance(maintenance_id)
|
|
|
|
self.assertEqual(r["msg"], "Paused Successfully.")
|
|
|
|
|
|
|
|
# resume maintenance
|
|
|
|
r = self.api.resume_maintenance(maintenance_id)
|
|
|
|
self.assertEqual(r["msg"], "Resume Successfully")
|
|
|
|
|
|
|
|
# add monitor maintenance
|
|
|
|
monitor_name = "monitor 1"
|
|
|
|
monitor_id = self.add_monitor(monitor_name)
|
|
|
|
monitors = [
|
|
|
|
{
|
2023-08-12 16:37:28 +02:00
|
|
|
"id": monitor_id
|
2022-12-29 00:22:53 +01:00
|
|
|
},
|
|
|
|
]
|
|
|
|
r = self.api.add_monitor_maintenance(maintenance_id, monitors)
|
|
|
|
self.assertEqual(r["msg"], "Added Successfully.")
|
|
|
|
|
|
|
|
# get monitor maintenance
|
|
|
|
monitors = self.api.get_monitor_maintenance(maintenance_id)
|
|
|
|
monitor = self.find_by_id(monitors, monitor_id)
|
|
|
|
self.assertIsNotNone(monitor)
|
|
|
|
|
|
|
|
# add status page maintenance
|
|
|
|
status_page_title = "status page 1"
|
|
|
|
status_page_id = self.add_status_page(status_page_title)
|
|
|
|
status_pages = [
|
|
|
|
{
|
2023-08-12 16:37:28 +02:00
|
|
|
"id": status_page_id
|
2022-12-29 00:22:53 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
r = self.api.add_status_page_maintenance(maintenance_id, status_pages)
|
|
|
|
self.assertEqual(r["msg"], "Added Successfully.")
|
|
|
|
|
|
|
|
# get status page maintenance
|
|
|
|
status_pages = self.api.get_status_page_maintenance(maintenance_id)
|
|
|
|
status_page = self.find_by_id(status_pages, status_page_id)
|
|
|
|
self.assertIsNotNone(status_page)
|
|
|
|
|
|
|
|
# delete maintenance
|
|
|
|
r = self.api.delete_maintenance(maintenance_id)
|
|
|
|
self.assertEqual(r["msg"], "Deleted Successfully.")
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
|
|
|
self.api.get_maintenance(maintenance_id)
|
|
|
|
|
|
|
|
def test_maintenance_strategy_manual(self):
|
|
|
|
expected_maintenance = {
|
|
|
|
"title": "test",
|
|
|
|
"description": "test",
|
2022-12-30 21:37:10 +01:00
|
|
|
"strategy": MaintenanceStrategy.MANUAL,
|
2022-12-29 00:22:53 +01:00
|
|
|
"active": True,
|
|
|
|
"intervalDay": 1,
|
|
|
|
"dateRange": [
|
|
|
|
"2022-12-27 00:00:00"
|
|
|
|
],
|
|
|
|
"weekdays": [],
|
|
|
|
"daysOfMonth": []
|
|
|
|
}
|
|
|
|
self.do_test_maintenance_strategy(expected_maintenance)
|
|
|
|
|
|
|
|
def test_maintenance_strategy_single(self):
|
|
|
|
expected_maintenance = {
|
|
|
|
"title": "test",
|
|
|
|
"description": "test",
|
2022-12-30 21:37:10 +01:00
|
|
|
"strategy": MaintenanceStrategy.SINGLE,
|
2022-12-29 00:22:53 +01:00
|
|
|
"active": True,
|
|
|
|
"intervalDay": 1,
|
|
|
|
"dateRange": [
|
|
|
|
"2022-12-27 22:36:00",
|
|
|
|
"2022-12-29 22:36:00"
|
|
|
|
],
|
|
|
|
"weekdays": [],
|
|
|
|
"daysOfMonth": []
|
|
|
|
}
|
|
|
|
self.do_test_maintenance_strategy(expected_maintenance)
|
|
|
|
|
|
|
|
def test_maintenance_strategy_recurring_interval(self):
|
|
|
|
expected_maintenance = {
|
|
|
|
"title": "test",
|
|
|
|
"description": "test",
|
2022-12-30 21:37:10 +01:00
|
|
|
"strategy": MaintenanceStrategy.RECURRING_INTERVAL,
|
2022-12-29 00:22:53 +01:00
|
|
|
"active": True,
|
|
|
|
"intervalDay": 1,
|
|
|
|
"dateRange": [
|
|
|
|
"2022-12-27 22:37:00",
|
|
|
|
"2022-12-31 22:37:00"
|
|
|
|
],
|
|
|
|
"timeRange": [
|
|
|
|
{
|
|
|
|
"hours": 2,
|
|
|
|
"minutes": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"hours": 3,
|
|
|
|
"minutes": 0
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"weekdays": [],
|
|
|
|
"daysOfMonth": []
|
|
|
|
}
|
|
|
|
self.do_test_maintenance_strategy(expected_maintenance)
|
|
|
|
|
|
|
|
def test_maintenance_strategy_recurring_weekday(self):
|
|
|
|
expected_maintenance = {
|
|
|
|
"title": "test",
|
|
|
|
"description": "test",
|
2022-12-30 21:37:10 +01:00
|
|
|
"strategy": MaintenanceStrategy.RECURRING_WEEKDAY,
|
2022-12-29 00:22:53 +01:00
|
|
|
"active": True,
|
|
|
|
"intervalDay": 1,
|
|
|
|
"dateRange": [
|
|
|
|
"2022-12-27 22:38:00",
|
|
|
|
"2022-12-31 22:38:00"
|
|
|
|
],
|
|
|
|
"timeRange": [
|
|
|
|
{
|
|
|
|
"hours": 2,
|
|
|
|
"minutes": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"hours": 3,
|
|
|
|
"minutes": 0
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"weekdays": [
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
5,
|
|
|
|
0
|
|
|
|
],
|
|
|
|
"daysOfMonth": []
|
|
|
|
}
|
|
|
|
self.do_test_maintenance_strategy(expected_maintenance)
|
|
|
|
|
|
|
|
def test_maintenance_strategy_recurring_day_of_month(self):
|
|
|
|
expected_maintenance = {
|
|
|
|
"title": "test",
|
|
|
|
"description": "test",
|
2022-12-30 21:37:10 +01:00
|
|
|
"strategy": MaintenanceStrategy.RECURRING_DAY_OF_MONTH,
|
2022-12-29 00:22:53 +01:00
|
|
|
"active": True,
|
|
|
|
"intervalDay": 1,
|
|
|
|
"dateRange": [
|
|
|
|
"2022-12-27 22:39:00",
|
|
|
|
"2022-12-31 22:39:00"
|
|
|
|
],
|
|
|
|
"timeRange": [
|
|
|
|
{
|
|
|
|
"hours": 2,
|
|
|
|
"minutes": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"hours": 3,
|
|
|
|
"minutes": 0
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"weekdays": [],
|
|
|
|
"daysOfMonth": [
|
|
|
|
1,
|
|
|
|
10,
|
|
|
|
20,
|
|
|
|
30,
|
2023-04-07 21:03:33 +02:00
|
|
|
"lastDay1"
|
2022-12-29 00:22:53 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
self.do_test_maintenance_strategy(expected_maintenance)
|
|
|
|
|
2023-04-07 21:03:33 +02:00
|
|
|
def test_maintenance_strategy_cron(self):
|
|
|
|
expected_maintenance = {
|
|
|
|
"title": "test",
|
|
|
|
"description": "test",
|
|
|
|
"strategy": MaintenanceStrategy.CRON,
|
|
|
|
"active": True,
|
|
|
|
"intervalDay": 1,
|
|
|
|
"dateRange": [
|
|
|
|
"2022-12-27 22:37:00",
|
|
|
|
"2022-12-31 22:37:00"
|
|
|
|
],
|
|
|
|
"weekdays": [],
|
|
|
|
"daysOfMonth": [],
|
|
|
|
"cron": "50 5 * * *",
|
|
|
|
"durationMinutes": 120,
|
2023-05-19 13:49:36 +02:00
|
|
|
"timezoneOption": "Europe/Berlin"
|
2023-04-07 21:03:33 +02:00
|
|
|
}
|
|
|
|
self.do_test_maintenance_strategy(expected_maintenance)
|
|
|
|
|
2022-12-29 00:22:53 +01:00
|
|
|
def do_test_maintenance_strategy(self, expected_maintenance):
|
|
|
|
# add maintenance
|
|
|
|
r = self.api.add_maintenance(**expected_maintenance)
|
|
|
|
self.assertEqual(r["msg"], "Added Successfully.")
|
|
|
|
maintenance_id = r["maintenanceID"]
|
|
|
|
|
|
|
|
# get maintenance
|
|
|
|
maintenance = self.api.get_maintenance(maintenance_id)
|
|
|
|
self.compare(maintenance, expected_maintenance)
|
|
|
|
|
|
|
|
# get maintenances
|
|
|
|
maintenances = self.api.get_maintenances()
|
|
|
|
maintenance = self.find_by_id(maintenances, maintenance_id)
|
|
|
|
self.assertIsNotNone(maintenance)
|
|
|
|
self.compare(maintenance, expected_maintenance)
|
|
|
|
|
|
|
|
# edit maintenance
|
|
|
|
r = self.api.edit_maintenance(maintenance_id, title="name 2")
|
|
|
|
self.assertEqual(r["msg"], "Saved.")
|
|
|
|
maintenance = self.api.get_maintenance(maintenance_id)
|
|
|
|
expected_maintenance["title"] = "name 2"
|
|
|
|
self.compare(maintenance, expected_maintenance)
|
|
|
|
|
|
|
|
# delete maintenance
|
|
|
|
r = self.api.delete_maintenance(maintenance_id)
|
|
|
|
self.assertEqual(r["msg"], "Deleted Successfully.")
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
|
|
|
self.api.get_maintenance(maintenance_id)
|
|
|
|
|
2023-05-20 14:09:09 +02:00
|
|
|
def test_delete_not_existing_maintenance(self):
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
|
|
|
self.api.delete_maintenance(42)
|
|
|
|
|
2022-12-29 00:22:53 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|