2022-08-02 23:47:56 +02:00
|
|
|
import unittest
|
2022-08-03 12:35:48 +02:00
|
|
|
|
2022-09-17 12:24:08 +02:00
|
|
|
from uptime_kuma_api import UptimeKumaException, ProxyProtocol
|
2022-08-03 12:35:48 +02:00
|
|
|
from uptime_kuma_test_case import UptimeKumaTestCase
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestProxy(UptimeKumaTestCase):
|
|
|
|
def test_proxy(self):
|
2022-10-04 18:38:17 +02:00
|
|
|
# get empty list to make sure that future accesses will also work
|
|
|
|
self.api.get_proxies()
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
expected_proxy = {
|
2022-09-17 12:24:08 +02:00
|
|
|
"protocol": ProxyProtocol.HTTP,
|
2022-08-02 23:47:56 +02:00
|
|
|
"host": "127.0.0.1",
|
|
|
|
"port": 8080,
|
2022-09-17 12:24:08 +02:00
|
|
|
"auth": True,
|
|
|
|
"username": "username",
|
|
|
|
"password": "password",
|
|
|
|
"active": True,
|
|
|
|
"default": False
|
2022-08-02 23:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# add proxy
|
2022-09-17 12:24:08 +02:00
|
|
|
r = self.api.add_proxy(applyExisting=False, **expected_proxy)
|
2022-08-02 23:47:56 +02:00
|
|
|
self.assertEqual(r["msg"], "Saved")
|
|
|
|
proxy_id = r["id"]
|
|
|
|
|
|
|
|
# get proxy
|
|
|
|
proxy = self.api.get_proxy(proxy_id)
|
|
|
|
self.compare(proxy, expected_proxy)
|
|
|
|
|
2022-08-03 16:56:38 +02:00
|
|
|
# get proxies
|
|
|
|
proxies = self.api.get_proxies()
|
|
|
|
proxy = self.find_by_id(proxies, proxy_id)
|
|
|
|
self.assertIsNotNone(proxy)
|
|
|
|
self.compare(proxy, expected_proxy)
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
# edit proxy
|
2022-09-18 19:46:20 +02:00
|
|
|
expected_proxy["protocol"] = ProxyProtocol.HTTPS
|
2022-08-02 23:47:56 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|