uptime-kuma-api2 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. uptime_kuma_api2-2.1.0/LICENSE +22 -0
  2. uptime_kuma_api2-2.1.0/PKG-INFO +168 -0
  3. uptime_kuma_api2-2.1.0/README.md +127 -0
  4. uptime_kuma_api2-2.1.0/setup.cfg +4 -0
  5. uptime_kuma_api2-2.1.0/setup.py +55 -0
  6. uptime_kuma_api2-2.1.0/tests/test_2fa.py +56 -0
  7. uptime_kuma_api2-2.1.0/tests/test_api_key.py +59 -0
  8. uptime_kuma_api2-2.1.0/tests/test_avg_ping.py +13 -0
  9. uptime_kuma_api2-2.1.0/tests/test_clear.py +20 -0
  10. uptime_kuma_api2-2.1.0/tests/test_database.py +16 -0
  11. uptime_kuma_api2-2.1.0/tests/test_docker_host.py +60 -0
  12. uptime_kuma_api2-2.1.0/tests/test_game_list.py +13 -0
  13. uptime_kuma_api2-2.1.0/tests/test_heartbeat.py +20 -0
  14. uptime_kuma_api2-2.1.0/tests/test_helper_methods.py +15 -0
  15. uptime_kuma_api2-2.1.0/tests/test_info.py +25 -0
  16. uptime_kuma_api2-2.1.0/tests/test_logger.py +65 -0
  17. uptime_kuma_api2-2.1.0/tests/test_login.py +31 -0
  18. uptime_kuma_api2-2.1.0/tests/test_maintenance.py +269 -0
  19. uptime_kuma_api2-2.1.0/tests/test_monitor.py +417 -0
  20. uptime_kuma_api2-2.1.0/tests/test_monitor_builder.py +64 -0
  21. uptime_kuma_api2-2.1.0/tests/test_monitor_params_v2.py +479 -0
  22. uptime_kuma_api2-2.1.0/tests/test_monitor_tag.py +42 -0
  23. uptime_kuma_api2-2.1.0/tests/test_monitor_types_v2.py +237 -0
  24. uptime_kuma_api2-2.1.0/tests/test_notification.py +68 -0
  25. uptime_kuma_api2-2.1.0/tests/test_notification_v2.py +156 -0
  26. uptime_kuma_api2-2.1.0/tests/test_proxy.py +60 -0
  27. uptime_kuma_api2-2.1.0/tests/test_settings.py +64 -0
  28. uptime_kuma_api2-2.1.0/tests/test_status_page.py +100 -0
  29. uptime_kuma_api2-2.1.0/tests/test_status_page_v2.py +119 -0
  30. uptime_kuma_api2-2.1.0/tests/test_tag.py +49 -0
  31. uptime_kuma_api2-2.1.0/tests/test_uptime.py +16 -0
  32. uptime_kuma_api2-2.1.0/uptime_kuma_api/__init__.py +13 -0
  33. uptime_kuma_api2-2.1.0/uptime_kuma_api/__version__.py +5 -0
  34. uptime_kuma_api2-2.1.0/uptime_kuma_api/api.py +4184 -0
  35. uptime_kuma_api2-2.1.0/uptime_kuma_api/auth_method.py +20 -0
  36. uptime_kuma_api2-2.1.0/uptime_kuma_api/docker_type.py +11 -0
  37. uptime_kuma_api2-2.1.0/uptime_kuma_api/docstrings.py +438 -0
  38. uptime_kuma_api2-2.1.0/uptime_kuma_api/event.py +22 -0
  39. uptime_kuma_api2-2.1.0/uptime_kuma_api/exceptions.py +10 -0
  40. uptime_kuma_api2-2.1.0/uptime_kuma_api/incident_style.py +23 -0
  41. uptime_kuma_api2-2.1.0/uptime_kuma_api/maintenance_strategy.py +23 -0
  42. uptime_kuma_api2-2.1.0/uptime_kuma_api/monitor_builder.py +503 -0
  43. uptime_kuma_api2-2.1.0/uptime_kuma_api/monitor_status.py +17 -0
  44. uptime_kuma_api2-2.1.0/uptime_kuma_api/monitor_type.py +83 -0
  45. uptime_kuma_api2-2.1.0/uptime_kuma_api/notification_providers.py +515 -0
  46. uptime_kuma_api2-2.1.0/uptime_kuma_api/proxy_protocol.py +23 -0
  47. uptime_kuma_api2-2.1.0/uptime_kuma_api2.egg-info/PKG-INFO +168 -0
  48. uptime_kuma_api2-2.1.0/uptime_kuma_api2.egg-info/SOURCES.txt +49 -0
  49. uptime_kuma_api2-2.1.0/uptime_kuma_api2.egg-info/dependency_links.txt +1 -0
  50. uptime_kuma_api2-2.1.0/uptime_kuma_api2.egg-info/requires.txt +2 -0
  51. uptime_kuma_api2-2.1.0/uptime_kuma_api2.egg-info/top_level.txt +1 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Paolo Barone
4
+ Copyright (c) 2023 Lucas Held (original work)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: uptime-kuma-api2
3
+ Version: 2.1.0
4
+ Summary: A python wrapper for the Uptime Kuma WebSocket API (v2 support)
5
+ Home-page: https://github.com/pbarone/uptime-kuma-api-v2
6
+ Author: Paolo Barone
7
+ Author-email: pbarone@users.noreply.github.com
8
+ License: MIT
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Natural Language :: English
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Classifier: Topic :: Internet :: WWW/HTTP
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ Requires-Python: >=3.7, <4
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: python-socketio[client]>=5.0.0
29
+ Requires-Dist: packaging
30
+ Dynamic: author
31
+ Dynamic: author-email
32
+ Dynamic: classifier
33
+ Dynamic: description
34
+ Dynamic: description-content-type
35
+ Dynamic: home-page
36
+ Dynamic: license
37
+ Dynamic: license-file
38
+ Dynamic: requires-dist
39
+ Dynamic: requires-python
40
+ Dynamic: summary
41
+
42
+ # uptime-kuma-api-v2
43
+
44
+ A wrapper for the Uptime Kuma Socket.IO API — with full v2 support
45
+ ---
46
+
47
+ > **Fork notice:** This is an actively maintained fork of [lucasheld/uptime-kuma-api](https://github.com/lucasheld/uptime-kuma-api), which appears to be unmaintained (last release: 2023, open PRs unanswered). This fork adds full Uptime Kuma v2.x support while maintaining backward compatibility with v1.x. Original work by [Lucas Held](https://github.com/lucasheld) — thank you for building the foundation.
48
+
49
+ uptime-kuma-api-v2 is a Python wrapper for the [Uptime Kuma](https://github.com/louislam/uptime-kuma) Socket.IO API.
50
+
51
+ This package was originally developed to configure Uptime Kuma with Ansible. The original Ansible collection can be found at https://github.com/lucasheld/ansible-uptime-kuma.
52
+
53
+ Python version 3.7+ is required.
54
+
55
+ Supported Uptime Kuma versions:
56
+
57
+ | Uptime Kuma | uptime-kuma-api |
58
+ |-----------------|-----------------|
59
+ | 2.0.0 - 2.4.0 | 2.0.0 - 2.1.0 |
60
+ | 1.21.3 - 1.23.2 | 1.0.0 - 1.2.1 |
61
+ | 1.17.0 - 1.21.2 | 0.1.0 - 0.13.0 |
62
+
63
+ Installation
64
+ ---
65
+ uptime-kuma-api2 is available on the [Python Package Index (PyPI)](https://pypi.org/project/uptime-kuma-api2/).
66
+
67
+ You can install it using pip:
68
+
69
+ ```
70
+ pip install uptime-kuma-api2
71
+ ```
72
+
73
+ Documentation
74
+ ---
75
+ The API Reference is available on [Read the Docs](https://uptime-kuma-api.readthedocs.io).
76
+
77
+ Example
78
+ ---
79
+ Once you have installed the python package, you can use it to communicate with an Uptime Kuma instance.
80
+
81
+ To do so, import `UptimeKumaApi` from the library and specify the Uptime Kuma server url (e.g. 'http://127.0.0.1:3001'), username and password to initialize the connection.
82
+
83
+ ```python
84
+ >>> from uptime_kuma_api import UptimeKumaApi, MonitorType
85
+ >>> api = UptimeKumaApi('INSERT_URL')
86
+ >>> api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
87
+ ```
88
+
89
+ Now you can call one of the existing methods of the instance. For example create a new monitor:
90
+
91
+ ```python
92
+ >>> result = api.add_monitor(type=MonitorType.HTTP, name="Google", url="https://google.com")
93
+ >>> print(result)
94
+ {'msg': 'Added Successfully.', 'monitorId': 1}
95
+ ```
96
+
97
+ At the end, the connection to the API must be disconnected so that the program does not block.
98
+
99
+ ```python
100
+ >>> api.disconnect()
101
+ ```
102
+
103
+ With a context manager, the disconnect method is called automatically:
104
+
105
+ ```python
106
+ from uptime_kuma_api import UptimeKumaApi
107
+
108
+ with UptimeKumaApi('INSERT_URL') as api:
109
+ api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
110
+ api.add_monitor(
111
+ type=MonitorType.HTTP,
112
+ name="Google",
113
+ url="https://google.com"
114
+ )
115
+ ```
116
+
117
+ MonitorBuilder
118
+ ---
119
+ For complex monitor configurations, use the fluent `MonitorBuilder`:
120
+
121
+ ```python
122
+ from uptime_kuma_api import UptimeKumaApi, MonitorType, MonitorBuilder
123
+
124
+ with UptimeKumaApi('INSERT_URL') as api:
125
+ api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
126
+
127
+ config = (
128
+ MonitorBuilder()
129
+ .type(MonitorType.HTTP)
130
+ .name("My Monitor")
131
+ .url("https://example.com")
132
+ .interval(60)
133
+ .conditions([
134
+ {"type": "expression", "variable": "response_status", "operator": "==", "value": "200", "andOr": ""}
135
+ ])
136
+ .build()
137
+ )
138
+ result = api.add_monitor(**config)
139
+ print(result)
140
+ ```
141
+
142
+ New in v2.1.0
143
+ ---
144
+ - **New monitor types**: RabbitMQ, SNMP, SMTP, System Service
145
+ - **New notification providers**: Nextcloud Talk, Brevo, Evolution API
146
+ - **MonitorBuilder**: Fluent builder pattern for monitor configuration
147
+ - **Logger support**: Pass a custom logger for Socket.IO debugging
148
+ - **v2-only parameters**: Automatic version gating ensures backward compatibility with v1.x
149
+
150
+ Testing
151
+ ---
152
+ Unit tests cover all v2 features and can be run without a live server:
153
+
154
+ ```
155
+ pip install pytest
156
+ pytest tests/ -v
157
+ ```
158
+
159
+ Test files:
160
+
161
+ | File | Coverage |
162
+ |------|----------|
163
+ | `tests/test_monitor_types_v2.py` | New monitor types (RABBITMQ, SNMP, SMTP, SYSTEM_SERVICE) |
164
+ | `tests/test_monitor_params_v2.py` | v2 monitor parameters, version gating, validation |
165
+ | `tests/test_status_page_v2.py` | Status page analytics replacement, password removal, new fields |
166
+ | `tests/test_notification_v2.py` | Nextcloud Talk, Brevo, Evolution API providers |
167
+ | `tests/test_logger.py` | Logger parameter type validation |
168
+ | `tests/test_monitor_builder.py` | MonitorBuilder fluent API |
@@ -0,0 +1,127 @@
1
+ # uptime-kuma-api-v2
2
+
3
+ A wrapper for the Uptime Kuma Socket.IO API — with full v2 support
4
+ ---
5
+
6
+ > **Fork notice:** This is an actively maintained fork of [lucasheld/uptime-kuma-api](https://github.com/lucasheld/uptime-kuma-api), which appears to be unmaintained (last release: 2023, open PRs unanswered). This fork adds full Uptime Kuma v2.x support while maintaining backward compatibility with v1.x. Original work by [Lucas Held](https://github.com/lucasheld) — thank you for building the foundation.
7
+
8
+ uptime-kuma-api-v2 is a Python wrapper for the [Uptime Kuma](https://github.com/louislam/uptime-kuma) Socket.IO API.
9
+
10
+ This package was originally developed to configure Uptime Kuma with Ansible. The original Ansible collection can be found at https://github.com/lucasheld/ansible-uptime-kuma.
11
+
12
+ Python version 3.7+ is required.
13
+
14
+ Supported Uptime Kuma versions:
15
+
16
+ | Uptime Kuma | uptime-kuma-api |
17
+ |-----------------|-----------------|
18
+ | 2.0.0 - 2.4.0 | 2.0.0 - 2.1.0 |
19
+ | 1.21.3 - 1.23.2 | 1.0.0 - 1.2.1 |
20
+ | 1.17.0 - 1.21.2 | 0.1.0 - 0.13.0 |
21
+
22
+ Installation
23
+ ---
24
+ uptime-kuma-api2 is available on the [Python Package Index (PyPI)](https://pypi.org/project/uptime-kuma-api2/).
25
+
26
+ You can install it using pip:
27
+
28
+ ```
29
+ pip install uptime-kuma-api2
30
+ ```
31
+
32
+ Documentation
33
+ ---
34
+ The API Reference is available on [Read the Docs](https://uptime-kuma-api.readthedocs.io).
35
+
36
+ Example
37
+ ---
38
+ Once you have installed the python package, you can use it to communicate with an Uptime Kuma instance.
39
+
40
+ To do so, import `UptimeKumaApi` from the library and specify the Uptime Kuma server url (e.g. 'http://127.0.0.1:3001'), username and password to initialize the connection.
41
+
42
+ ```python
43
+ >>> from uptime_kuma_api import UptimeKumaApi, MonitorType
44
+ >>> api = UptimeKumaApi('INSERT_URL')
45
+ >>> api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
46
+ ```
47
+
48
+ Now you can call one of the existing methods of the instance. For example create a new monitor:
49
+
50
+ ```python
51
+ >>> result = api.add_monitor(type=MonitorType.HTTP, name="Google", url="https://google.com")
52
+ >>> print(result)
53
+ {'msg': 'Added Successfully.', 'monitorId': 1}
54
+ ```
55
+
56
+ At the end, the connection to the API must be disconnected so that the program does not block.
57
+
58
+ ```python
59
+ >>> api.disconnect()
60
+ ```
61
+
62
+ With a context manager, the disconnect method is called automatically:
63
+
64
+ ```python
65
+ from uptime_kuma_api import UptimeKumaApi
66
+
67
+ with UptimeKumaApi('INSERT_URL') as api:
68
+ api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
69
+ api.add_monitor(
70
+ type=MonitorType.HTTP,
71
+ name="Google",
72
+ url="https://google.com"
73
+ )
74
+ ```
75
+
76
+ MonitorBuilder
77
+ ---
78
+ For complex monitor configurations, use the fluent `MonitorBuilder`:
79
+
80
+ ```python
81
+ from uptime_kuma_api import UptimeKumaApi, MonitorType, MonitorBuilder
82
+
83
+ with UptimeKumaApi('INSERT_URL') as api:
84
+ api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
85
+
86
+ config = (
87
+ MonitorBuilder()
88
+ .type(MonitorType.HTTP)
89
+ .name("My Monitor")
90
+ .url("https://example.com")
91
+ .interval(60)
92
+ .conditions([
93
+ {"type": "expression", "variable": "response_status", "operator": "==", "value": "200", "andOr": ""}
94
+ ])
95
+ .build()
96
+ )
97
+ result = api.add_monitor(**config)
98
+ print(result)
99
+ ```
100
+
101
+ New in v2.1.0
102
+ ---
103
+ - **New monitor types**: RabbitMQ, SNMP, SMTP, System Service
104
+ - **New notification providers**: Nextcloud Talk, Brevo, Evolution API
105
+ - **MonitorBuilder**: Fluent builder pattern for monitor configuration
106
+ - **Logger support**: Pass a custom logger for Socket.IO debugging
107
+ - **v2-only parameters**: Automatic version gating ensures backward compatibility with v1.x
108
+
109
+ Testing
110
+ ---
111
+ Unit tests cover all v2 features and can be run without a live server:
112
+
113
+ ```
114
+ pip install pytest
115
+ pytest tests/ -v
116
+ ```
117
+
118
+ Test files:
119
+
120
+ | File | Coverage |
121
+ |------|----------|
122
+ | `tests/test_monitor_types_v2.py` | New monitor types (RABBITMQ, SNMP, SMTP, SYSTEM_SERVICE) |
123
+ | `tests/test_monitor_params_v2.py` | v2 monitor parameters, version gating, validation |
124
+ | `tests/test_status_page_v2.py` | Status page analytics replacement, password removal, new fields |
125
+ | `tests/test_notification_v2.py` | Nextcloud Talk, Brevo, Evolution API providers |
126
+ | `tests/test_logger.py` | Logger parameter type validation |
127
+ | `tests/test_monitor_builder.py` | MonitorBuilder fluent API |
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,55 @@
1
+ from setuptools import setup
2
+ from codecs import open
3
+ import os
4
+ import sys
5
+
6
+ # "setup.py publish" shortcut.
7
+ if sys.argv[-1] == "publish":
8
+ os.system("rm dist/*")
9
+ os.system("python setup.py sdist")
10
+ os.system("twine upload dist/*")
11
+ sys.exit()
12
+
13
+ info = {}
14
+ here = os.path.abspath(os.path.dirname(__file__))
15
+ with open(os.path.join(here, "uptime_kuma_api", "__version__.py"), "r", "utf-8") as f:
16
+ exec(f.read(), info)
17
+
18
+ with open("README.md", "r", "utf-8") as f:
19
+ readme = f.read()
20
+
21
+ setup(
22
+ name="uptime-kuma-api2",
23
+ version=info["__version__"],
24
+ description="A python wrapper for the Uptime Kuma WebSocket API (v2 support)",
25
+ long_description=readme,
26
+ long_description_content_type="text/markdown",
27
+ url="https://github.com/pbarone/uptime-kuma-api-v2",
28
+ author=info["__author__"],
29
+ author_email="pbarone@users.noreply.github.com",
30
+ license=info["__license__"],
31
+ packages=["uptime_kuma_api"],
32
+ python_requires=">=3.7, <4",
33
+ install_requires=[
34
+ "python-socketio[client]>=5.0.0",
35
+ "packaging"
36
+ ],
37
+ classifiers=[
38
+ "Development Status :: 5 - Production/Stable",
39
+ "Environment :: Web Environment",
40
+ "Intended Audience :: Developers",
41
+ "License :: OSI Approved :: MIT License",
42
+ "Natural Language :: English",
43
+ "Operating System :: OS Independent",
44
+ "Programming Language :: Python",
45
+ "Programming Language :: Python :: 3",
46
+ "Programming Language :: Python :: 3.7",
47
+ "Programming Language :: Python :: 3.8",
48
+ "Programming Language :: Python :: 3.9",
49
+ "Programming Language :: Python :: 3.10",
50
+ "Programming Language :: Python :: 3.11",
51
+ "Programming Language :: Python :: 3 :: Only",
52
+ "Topic :: Internet :: WWW/HTTP",
53
+ "Topic :: Software Development :: Libraries"
54
+ ]
55
+ )
@@ -0,0 +1,56 @@
1
+ import unittest
2
+ from urllib import parse
3
+
4
+ import pyotp
5
+
6
+ from uptime_kuma_test_case import UptimeKumaTestCase
7
+
8
+
9
+ def parse_secret(uri):
10
+ query = parse.urlsplit(uri).query
11
+ params = dict(parse.parse_qsl(query))
12
+ return params["secret"]
13
+
14
+
15
+ def generate_token(secret):
16
+ totp = pyotp.TOTP(secret)
17
+ return totp.now()
18
+
19
+
20
+ class Test2FA(UptimeKumaTestCase):
21
+ def test_2fa(self):
22
+ # check 2fa is disabled
23
+ r = self.api.twofa_status()
24
+ self.assertEqual(r["status"], False)
25
+
26
+ # prepare 2fa
27
+ r = self.api.prepare_2fa(self.password)
28
+ uri = r["uri"]
29
+ self.assertTrue(uri.startswith("otpauth://totp/"))
30
+ secret = parse_secret(uri)
31
+
32
+ # verify token
33
+ token = generate_token(secret)
34
+ r = self.api.verify_token(token, self.password)
35
+ self.assertEqual(r["valid"], True)
36
+
37
+ # save 2fa
38
+ r = self.api.save_2fa(self.password)
39
+ self.assertEqual(r["msg"], "2FA Enabled.")
40
+
41
+ # check 2fa is enabled
42
+ r = self.api.twofa_status()
43
+ self.assertEqual(r["status"], True)
44
+
45
+ # relogin using the totp token
46
+ self.api.logout()
47
+ token = generate_token(secret)
48
+ self.api.login(self.username, self.password, token)
49
+
50
+ # disable 2fa
51
+ r = self.api.disable_2fa(self.password)
52
+ self.assertEqual(r["msg"], "2FA Disabled.")
53
+
54
+
55
+ if __name__ == '__main__':
56
+ unittest.main()
@@ -0,0 +1,59 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_api import UptimeKumaException
4
+ from uptime_kuma_test_case import UptimeKumaTestCase
5
+
6
+
7
+ class TestApiKey(UptimeKumaTestCase):
8
+ def test_api_key(self):
9
+ # get empty list to make sure that future accesses will also work
10
+ self.api.get_api_keys()
11
+
12
+ expected = {
13
+ "name": "name 1",
14
+ "expires": "2023-03-30 12:20:00",
15
+ "active": True
16
+ }
17
+
18
+ # add api key
19
+ r = self.api.add_api_key(**expected)
20
+ self.assertEqual(r["msg"], "Added Successfully.")
21
+ api_key_id = r["keyID"]
22
+
23
+ # get api key
24
+ api_key = self.api.get_api_key(api_key_id)
25
+ self.compare(api_key, expected)
26
+
27
+ # get api keys
28
+ api_keys = self.api.get_api_keys()
29
+ api_key = self.find_by_id(api_keys, api_key_id)
30
+ self.assertIsNotNone(api_key)
31
+ self.compare(api_key, expected)
32
+
33
+ # disable api key
34
+ r = self.api.disable_api_key(api_key_id)
35
+ self.assertEqual(r["msg"], "Disabled Successfully.")
36
+ api_key = self.api.get_api_key(api_key_id)
37
+ expected["active"] = False
38
+ self.compare(api_key, expected)
39
+
40
+ # enable api key
41
+ r = self.api.enable_api_key(api_key_id)
42
+ self.assertEqual(r["msg"], "Enabled Successfully")
43
+ api_key = self.api.get_api_key(api_key_id)
44
+ expected["active"] = True
45
+ self.compare(api_key, expected)
46
+
47
+ # delete api key
48
+ r = self.api.delete_api_key(api_key_id)
49
+ self.assertEqual(r["msg"], "Deleted Successfully.")
50
+ with self.assertRaises(UptimeKumaException):
51
+ self.api.get_api_key(api_key_id)
52
+
53
+ def test_delete_not_existing_api_key(self):
54
+ with self.assertRaises(UptimeKumaException):
55
+ self.api.delete_api_key(42)
56
+
57
+
58
+ if __name__ == '__main__':
59
+ unittest.main()
@@ -0,0 +1,13 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_test_case import UptimeKumaTestCase
4
+
5
+
6
+ class TestAvgPing(UptimeKumaTestCase):
7
+ def test_avg_ping(self):
8
+ self.add_monitor()
9
+ self.api.avg_ping()
10
+
11
+
12
+ if __name__ == '__main__':
13
+ unittest.main()
@@ -0,0 +1,20 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_test_case import UptimeKumaTestCase
4
+
5
+
6
+ class TestClear(UptimeKumaTestCase):
7
+ def test_clear_events(self):
8
+ monitor_id = self.add_monitor()
9
+ self.api.clear_events(monitor_id)
10
+
11
+ def test_clear_heartbeats(self):
12
+ monitor_id = self.add_monitor()
13
+ self.api.clear_heartbeats(monitor_id)
14
+
15
+ def test_clear_statistics(self):
16
+ self.api.clear_statistics()
17
+
18
+
19
+ if __name__ == '__main__':
20
+ unittest.main()
@@ -0,0 +1,16 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_test_case import UptimeKumaTestCase
4
+
5
+
6
+ class TestDatabase(UptimeKumaTestCase):
7
+ def test_get_database_size(self):
8
+ r = self.api.get_database_size()
9
+ self.assertIn("size", r)
10
+
11
+ def test_shrink_database(self):
12
+ self.api.shrink_database()
13
+
14
+
15
+ if __name__ == '__main__':
16
+ unittest.main()
@@ -0,0 +1,60 @@
1
+ import unittest
2
+ from packaging.version import parse as parse_version
3
+
4
+ from uptime_kuma_api import DockerType, UptimeKumaException
5
+ from uptime_kuma_test_case import UptimeKumaTestCase
6
+
7
+
8
+ class TestDockerHost(UptimeKumaTestCase):
9
+ def test_docker_host(self):
10
+ # get empty list to make sure that future accesses will also work
11
+ self.api.get_docker_hosts()
12
+
13
+ expected_docker_host = {
14
+ "name": "name 1",
15
+ "dockerType": DockerType.SOCKET,
16
+ "dockerDaemon": "/var/run/docker.sock"
17
+ }
18
+
19
+ # test docker host
20
+ if parse_version(self.api.version) != parse_version("1.23.0"):
21
+ # test_docker_host does not work in 1.23.0 (https://github.com/louislam/uptime-kuma/issues/3605)
22
+ with self.assertRaisesRegex(UptimeKumaException, r'connect ENOENT /var/run/docker.sock'):
23
+ self.api.test_docker_host(**expected_docker_host)
24
+
25
+ # add docker host
26
+ r = self.api.add_docker_host(**expected_docker_host)
27
+ self.assertEqual(r["msg"], "Saved")
28
+ docker_host_id = r["id"]
29
+
30
+ # get docker host
31
+ docker_host = self.api.get_docker_host(docker_host_id)
32
+ self.compare(docker_host, expected_docker_host)
33
+
34
+ # get docker hosts
35
+ docker_hosts = self.api.get_docker_hosts()
36
+ self.assertTrue(type(docker_hosts[0]["dockerType"]) == DockerType)
37
+ docker_host = self.find_by_id(docker_hosts, docker_host_id)
38
+ self.assertIsNotNone(docker_host)
39
+ self.compare(docker_host, expected_docker_host)
40
+
41
+ # edit docker host
42
+ r = self.api.edit_docker_host(docker_host_id, name="name 2")
43
+ self.assertEqual(r["msg"], "Saved")
44
+ docker_host = self.api.get_docker_host(docker_host_id)
45
+ expected_docker_host["name"] = "name 2"
46
+ self.compare(docker_host, expected_docker_host)
47
+
48
+ # delete docker host
49
+ r = self.api.delete_docker_host(docker_host_id)
50
+ self.assertEqual(r["msg"], "Deleted")
51
+ with self.assertRaises(UptimeKumaException):
52
+ self.api.get_docker_host(docker_host_id)
53
+
54
+ def test_delete_not_existing_docker_host(self):
55
+ with self.assertRaises(UptimeKumaException):
56
+ self.api.delete_docker_host(42)
57
+
58
+
59
+ if __name__ == '__main__':
60
+ unittest.main()
@@ -0,0 +1,13 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_test_case import UptimeKumaTestCase
4
+
5
+
6
+ class TestGameList(UptimeKumaTestCase):
7
+ def test_game_list(self):
8
+ game_list = self.api.get_game_list()
9
+ self.assertTrue("keys" in game_list[0])
10
+
11
+
12
+ if __name__ == '__main__':
13
+ unittest.main()
@@ -0,0 +1,20 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_api import MonitorStatus
4
+ from uptime_kuma_test_case import UptimeKumaTestCase
5
+
6
+
7
+ class TestHeartbeat(UptimeKumaTestCase):
8
+ def test_get_heartbeats(self):
9
+ self.add_monitor()
10
+ r = self.api.get_heartbeats()
11
+ self.assertTrue(type(list(r.values())[0][0]["status"]) == MonitorStatus)
12
+
13
+ def test_get_important_heartbeats(self):
14
+ self.add_monitor()
15
+ r = self.api.get_important_heartbeats()
16
+ self.assertTrue(type(list(r.values())[0][0]["status"]) == MonitorStatus)
17
+
18
+
19
+ if __name__ == '__main__':
20
+ unittest.main()
@@ -0,0 +1,15 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_api import MonitorStatus
4
+ from uptime_kuma_test_case import UptimeKumaTestCase
5
+
6
+
7
+ class TestHelperMethods(UptimeKumaTestCase):
8
+ def test_monitor_status(self):
9
+ monitor_id = self.add_monitor()
10
+ status = self.api.get_monitor_status(monitor_id)
11
+ self.assertTrue(type(status) == MonitorStatus)
12
+
13
+
14
+ if __name__ == '__main__':
15
+ unittest.main()
@@ -0,0 +1,25 @@
1
+ import unittest
2
+
3
+ from uptime_kuma_api import UptimeKumaApi
4
+ from uptime_kuma_test_case import UptimeKumaTestCase
5
+
6
+
7
+ class TestInfo(UptimeKumaTestCase):
8
+ def test_info(self):
9
+ info = self.api.info()
10
+ self.assertIn("version", info)
11
+ self.assertIn("latestVersion", info)
12
+
13
+ def test_info_with_version(self):
14
+ # If wait_events is set to 0, the first info event is normally used.
15
+ # The info event handler needs to drop this first event without a version.
16
+ self.api.logout()
17
+ self.api.disconnect()
18
+ self.api = UptimeKumaApi(self.url, wait_events=0)
19
+ self.api.login(self.username, self.password)
20
+ info = self.api.info()
21
+ self.assertIn("version", info)
22
+
23
+
24
+ if __name__ == '__main__':
25
+ unittest.main()