2022-08-02 23:47:56 +02:00
|
|
|
import unittest
|
2022-08-03 12:35:48 +02:00
|
|
|
|
2022-09-18 19:46:20 +02:00
|
|
|
from uptime_kuma_api import UptimeKumaException, NotificationType
|
2022-08-03 12:35:48 +02:00
|
|
|
from uptime_kuma_test_case import UptimeKumaTestCase
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestNotification(UptimeKumaTestCase):
|
|
|
|
def test_notification(self):
|
2022-10-04 18:38:17 +02:00
|
|
|
# get empty list to make sure that future accesses will also work
|
|
|
|
self.api.get_notifications()
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
expected_notification = {
|
|
|
|
"name": "notification 1",
|
2022-09-17 12:24:08 +02:00
|
|
|
"isDefault": True,
|
2022-08-03 11:56:02 +02:00
|
|
|
"applyExisting": True,
|
2023-05-20 22:06:05 +02:00
|
|
|
"type": NotificationType.TELEGRAM,
|
|
|
|
"telegramChatID": "123456789",
|
|
|
|
"telegramBotToken": "987654321"
|
2022-08-02 23:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# test notification
|
2023-05-25 18:35:56 +02:00
|
|
|
with self.assertRaisesRegex(UptimeKumaException, r'Not Found'):
|
2022-08-02 23:47:56 +02:00
|
|
|
self.api.test_notification(**expected_notification)
|
|
|
|
|
|
|
|
# add notification
|
|
|
|
r = self.api.add_notification(**expected_notification)
|
|
|
|
self.assertEqual(r["msg"], "Saved")
|
|
|
|
notification_id = r["id"]
|
|
|
|
|
|
|
|
# get notification
|
|
|
|
notification = self.api.get_notification(notification_id)
|
|
|
|
self.compare(notification, expected_notification)
|
|
|
|
|
|
|
|
# get notifications
|
|
|
|
notifications = self.api.get_notifications()
|
|
|
|
notification = self.find_by_id(notifications, notification_id)
|
|
|
|
self.assertIsNotNone(notification)
|
|
|
|
self.compare(notification, expected_notification)
|
|
|
|
|
|
|
|
# edit notification
|
|
|
|
expected_notification["name"] = "notification 1 new"
|
|
|
|
expected_notification["default"] = False
|
2022-08-03 11:56:02 +02:00
|
|
|
expected_notification["applyExisting"] = False
|
2022-09-18 19:46:20 +02:00
|
|
|
expected_notification["type"] = NotificationType.PUSHDEER
|
2022-08-03 11:56:02 +02:00
|
|
|
expected_notification["pushdeerKey"] = "987654321"
|
2023-05-25 18:35:56 +02:00
|
|
|
del expected_notification["telegramChatID"]
|
|
|
|
del expected_notification["telegramBotToken"]
|
2022-08-02 23:47:56 +02:00
|
|
|
r = self.api.edit_notification(notification_id, **expected_notification)
|
|
|
|
self.assertEqual(r["msg"], "Saved")
|
|
|
|
notification = self.api.get_notification(notification_id)
|
|
|
|
self.compare(notification, expected_notification)
|
2022-08-03 11:56:02 +02:00
|
|
|
self.assertIsNone(notification.get("pushAPIKey"))
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
# delete notification
|
|
|
|
r = self.api.delete_notification(notification_id)
|
|
|
|
self.assertEqual(r["msg"], "Deleted")
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
|
|
|
self.api.delete_notification(notification_id)
|
|
|
|
|
2023-05-20 14:09:09 +02:00
|
|
|
def test_delete_not_existing_notification(self):
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
|
|
|
self.api.delete_notification(42)
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|