uptime-kuma-api/tests/test_status_page.py

101 lines
3.4 KiB
Python
Raw Normal View History

2022-08-02 23:47:56 +02:00
import unittest
2022-08-03 12:35:48 +02:00
2022-08-02 23:47:56 +02:00
from uptime_kuma_api import UptimeKumaException, IncidentStyle
2022-08-03 12:35:48 +02:00
from uptime_kuma_test_case import UptimeKumaTestCase
2022-08-02 23:47:56 +02:00
class TestStatusPage(UptimeKumaTestCase):
def test_status_page(self):
# get empty list to make sure that future accesses will also work
self.api.get_status_pages()
2022-08-26 14:04:43 +02:00
monitor_id = self.add_monitor()
2022-08-02 23:47:56 +02:00
slug = "slug1"
expected_status_page = {
"slug": slug,
"title": "status page 1",
"description": "description 1",
"theme": "light",
"published": True,
"showTags": False,
"domainNameList": [],
"customCSS": "",
"footerText": None,
2022-08-26 14:04:43 +02:00
"showPoweredBy": False,
"icon": "/icon.svg",
2022-08-26 14:04:43 +02:00
"publicGroupList": [
{
'name': 'Services',
'weight': 1,
'monitorList': [
{
"id": monitor_id
}
]
}
],
"googleAnalyticsId": ""
2022-08-02 23:47:56 +02:00
}
# add status page
r = self.api.add_status_page(slug, expected_status_page["title"])
self.assertEqual(r["msg"], "OK!")
# save status page
self.api.save_status_page(**expected_status_page)
# get status page
status_page = self.api.get_status_page(slug)
self.compare(status_page, expected_status_page)
# get status pages
status_pages = self.api.get_status_pages()
status_page = self.find_by_id(status_pages, slug, "slug")
self.assertIsNotNone(status_page)
2022-08-26 14:04:43 +02:00
# publicGroupList and incident is not available in status pages
expected_status_page_config = {i: expected_status_page[i] for i in expected_status_page if i != "publicGroupList"}
self.compare(status_page, expected_status_page_config)
2022-08-02 23:47:56 +02:00
# edit status page
expected_status_page["title"] = "status page 1 new"
expected_status_page["theme"] = "dark"
self.api.save_status_page(**expected_status_page)
status_page = self.api.get_status_page(slug)
self.compare(status_page, expected_status_page)
# pin incident
incident_expected = {
"title": "title 1",
"content": "content 1",
"style": IncidentStyle.DANGER
}
incident = self.api.post_incident(slug, **incident_expected)
self.assertTrue(type(incident["style"]) == IncidentStyle)
2022-08-02 23:47:56 +02:00
self.compare(incident, incident_expected)
2022-08-26 17:02:55 +02:00
status_page = self.api.get_status_page(slug)
self.compare(status_page["incident"], incident)
self.assertTrue(type(status_page["incident"]["style"]) == IncidentStyle)
2022-08-02 23:47:56 +02:00
# unpin incident
self.api.unpin_incident(slug)
2022-08-26 17:02:55 +02:00
status_page = self.api.get_status_page(slug)
self.assertIsNone(status_page["incident"])
2022-08-02 23:47:56 +02:00
# delete status page
self.api.delete_status_page(slug)
with self.assertRaises(UptimeKumaException):
self.api.get_status_page(slug)
status_pages = self.api.get_status_pages()
status_page = self.find_by_id(status_pages, slug, "slug")
self.assertIsNone(status_page)
def test_delete_not_existing_status_page(self):
with self.assertRaises(UptimeKumaException):
self.api.delete_status_page("slug42")
2022-08-02 23:47:56 +02:00
if __name__ == '__main__':
unittest.main()