uptime-kuma-api/tests/test_status_page.py

86 lines
2.7 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):
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",
2022-08-26 14:04:43 +02:00
"showPoweredBy": False,
"publicGroupList": [
{
'name': 'Services',
'weight': 1,
'monitorList': [
{
"id": monitor_id
}
]
}
]
2022-08-02 23:47:56 +02:00
}
# slug must be unique
try:
self.api.delete_status_page(slug)
except UptimeKumaException:
pass
# 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.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)
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)
if __name__ == '__main__':
unittest.main()