47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from server.services.http import HttpClient
|
|
|
|
|
|
def test_proxy_is_reloaded_after_restart() -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "proxy.json"
|
|
with patch("server.services.http.PROXY_PATH", path):
|
|
first = HttpClient()
|
|
first.configure_proxy({
|
|
"mode": "custom",
|
|
"scheme": "http",
|
|
"host": "127.0.0.1",
|
|
"port": "7897",
|
|
"username": "",
|
|
"password": "",
|
|
})
|
|
saved = json.loads(path.read_text(encoding="utf-8"))
|
|
assert saved["mode"] == "custom"
|
|
assert saved["host"] == "127.0.0.1"
|
|
assert saved["port"] == "7897"
|
|
|
|
second = HttpClient()
|
|
view = second.proxy_view()
|
|
assert view["mode"] == "custom"
|
|
assert view["scheme"] == "http"
|
|
assert view["url"] == "http://127.0.0.1:7897"
|
|
|
|
|
|
def test_invalid_proxy_file_does_not_block_startup() -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "proxy.json"
|
|
path.write_text("{", encoding="utf-8")
|
|
with patch("server.services.http.PROXY_PATH", path):
|
|
client = HttpClient()
|
|
assert client.proxy_view()["mode"] == "off"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_proxy_is_reloaded_after_restart()
|
|
test_invalid_proxy_file_does_not_block_startup()
|
|
print("ok")
|