-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for uptime kuma 1.21.0
- Loading branch information
Showing
8 changed files
with
329 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import unittest | ||
from packaging.version import parse as parse_version | ||
|
||
from uptime_kuma_api import DockerType, UptimeKumaException | ||
from uptime_kuma_test_case import UptimeKumaTestCase | ||
|
||
|
||
class TestApiKey(UptimeKumaTestCase): | ||
def setUp(self): | ||
super(TestApiKey, self).setUp() | ||
if parse_version(self.api.version) < parse_version("1.21"): | ||
super(TestApiKey, self).tearDown() | ||
self.skipTest("Unsupported in this Uptime Kuma version") | ||
|
||
def test_api_key(self): | ||
# get empty list to make sure that future accesses will also work | ||
self.api.get_api_keys() | ||
|
||
expected = { | ||
"name": "name 1", | ||
"expires": "2023-03-30 12:20:00", | ||
"active": True | ||
} | ||
|
||
# add api key | ||
r = self.api.add_api_key(**expected) | ||
self.assertEqual(r["msg"], "Added Successfully.") | ||
api_key_id = r["keyID"] | ||
|
||
# get api key | ||
api_key = self.api.get_api_key(api_key_id) | ||
self.compare(api_key, expected) | ||
|
||
# get api keys | ||
api_keys = self.api.get_api_keys() | ||
api_key = self.find_by_id(api_keys, api_key_id) | ||
self.assertIsNotNone(api_key) | ||
self.compare(api_key, expected) | ||
|
||
# disable api key | ||
r = self.api.disable_api_key(api_key_id) | ||
self.assertEqual(r["msg"], "Disabled Successfully.") | ||
api_key = self.api.get_api_key(api_key_id) | ||
expected["active"] = False | ||
self.compare(api_key, expected) | ||
|
||
# enable api key | ||
r = self.api.enable_api_key(api_key_id) | ||
self.assertEqual(r["msg"], "Enabled Successfully") | ||
api_key = self.api.get_api_key(api_key_id) | ||
expected["active"] = True | ||
self.compare(api_key, expected) | ||
|
||
# delete api key | ||
r = self.api.delete_api_key(api_key_id) | ||
self.assertEqual(r["msg"], "Deleted Successfully.") | ||
with self.assertRaises(UptimeKumaException): | ||
self.api.get_api_key(api_key_id) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.