84d4009d6a
BREAKING CHANGE: Types of return values changed to enum values: - monitor: `type` (str -> MonitorType), `authMethod` (str -> AuthMethod) - notification: `type` (str -> NotificationType) - docker host: `dockerType` (str -> DockerType) - status page: `style` (str -> IncidentStyle) - maintenance: `strategy` (str -> MaintenanceStrategy) - proxy: `protocol` (str -> ProxyProtocol)
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
import unittest
|
|
|
|
from uptime_kuma_api import UptimeKumaException, ProxyProtocol
|
|
from uptime_kuma_test_case import UptimeKumaTestCase
|
|
|
|
|
|
class TestProxy(UptimeKumaTestCase):
|
|
def test_proxy(self):
|
|
# get empty list to make sure that future accesses will also work
|
|
self.api.get_proxies()
|
|
|
|
expected_proxy = {
|
|
"protocol": ProxyProtocol.HTTP,
|
|
"host": "127.0.0.1",
|
|
"port": 8080,
|
|
"auth": True,
|
|
"username": "username",
|
|
"password": "password",
|
|
"active": True,
|
|
"default": False
|
|
}
|
|
|
|
# add proxy
|
|
r = self.api.add_proxy(applyExisting=False, **expected_proxy)
|
|
self.assertEqual(r["msg"], "Saved")
|
|
proxy_id = r["id"]
|
|
|
|
# get proxy
|
|
proxy = self.api.get_proxy(proxy_id)
|
|
self.compare(proxy, expected_proxy)
|
|
|
|
# get proxies
|
|
proxies = self.api.get_proxies()
|
|
self.assertTrue(type(proxies[0]["protocol"]) == ProxyProtocol)
|
|
proxy = self.find_by_id(proxies, proxy_id)
|
|
self.assertIsNotNone(proxy)
|
|
self.compare(proxy, expected_proxy)
|
|
|
|
# edit proxy
|
|
expected_proxy["protocol"] = ProxyProtocol.HTTPS
|
|
expected_proxy["host"] = "127.0.0.2"
|
|
expected_proxy["port"] = 8888
|
|
r = self.api.edit_proxy(proxy_id, **expected_proxy)
|
|
self.assertEqual(r["msg"], "Saved")
|
|
proxy = self.api.get_proxy(proxy_id)
|
|
self.compare(proxy, expected_proxy)
|
|
|
|
# delete proxy
|
|
r = self.api.delete_proxy(proxy_id)
|
|
self.assertEqual(r["msg"], "Deleted")
|
|
with self.assertRaises(UptimeKumaException):
|
|
self.api.get_proxy(proxy_id)
|
|
|
|
def test_delete_not_existing_proxy(self):
|
|
with self.assertRaises(UptimeKumaException):
|
|
self.api.delete_proxy(42)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|