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
|
2022-08-03 12:35:48 +02:00
|
|
|
from uptime_kuma_test_case import UptimeKumaTestCase
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestTag(UptimeKumaTestCase):
|
|
|
|
def test_tag(self):
|
|
|
|
expected_tag = {
|
|
|
|
"name": "tag 1",
|
|
|
|
"color": "#ffffff"
|
|
|
|
}
|
|
|
|
|
|
|
|
# add tag
|
|
|
|
tag = self.api.add_tag(**expected_tag)
|
|
|
|
self.compare(tag, expected_tag)
|
|
|
|
tag_id = tag["id"]
|
|
|
|
|
|
|
|
# get tag
|
|
|
|
tag = self.api.get_tag(tag_id)
|
|
|
|
self.compare(tag, expected_tag)
|
|
|
|
|
|
|
|
# get tags
|
|
|
|
tags = self.api.get_tags()
|
|
|
|
tag = self.find_by_id(tags, tag_id)
|
|
|
|
self.assertIsNotNone(tag)
|
|
|
|
self.compare(tag, expected_tag)
|
|
|
|
|
2023-05-20 12:43:57 +02:00
|
|
|
# edit tag
|
|
|
|
expected_tag["name"] = "tag 1 new"
|
|
|
|
expected_tag["color"] = "#000000"
|
|
|
|
r = self.api.edit_tag(tag_id, **expected_tag)
|
|
|
|
self.assertEqual(r["msg"], "Saved")
|
|
|
|
tag = self.api.get_tag(tag_id)
|
|
|
|
self.compare(tag, expected_tag)
|
2023-02-13 22:51:21 +01:00
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
# delete tag
|
|
|
|
r = self.api.delete_tag(tag_id)
|
|
|
|
self.assertEqual(r["msg"], "Deleted Successfully.")
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
2022-08-03 16:56:38 +02:00
|
|
|
self.api.get_tag(tag_id)
|
2022-08-02 23:47:56 +02:00
|
|
|
|
2023-05-20 14:09:09 +02:00
|
|
|
def test_delete_not_existing_tag(self):
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
|
|
|
self.api.delete_tag(42)
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|