Fix AutoDL GET request parameters
Controller CI / test (push) Successful in 2s

This commit is contained in:
2026-10-02 15:18:31 +08:00
parent d5f13caee0
commit c7c4850e14
2 changed files with 23 additions and 2 deletions
+10 -2
View File
@@ -14,6 +14,7 @@ import sys
import tempfile
import time
import urllib.error
import urllib.parse
import urllib.request
from dataclasses import dataclass
from pathlib import Path
@@ -144,9 +145,16 @@ class AutoDLClient:
self.token = token
def request(self, method: str, path: str, body: dict[str, Any]) -> Any:
url = f"{API_BASE}{path}"
data: bytes | None
if method == "GET":
url = f"{url}?{urllib.parse.urlencode(body)}"
data = None
else:
data = json.dumps(body).encode()
request = urllib.request.Request(
f"{API_BASE}{path}",
data=json.dumps(body).encode(),
url,
data=data,
method=method,
headers={"Authorization": self.token, "Content-Type": "application/json"},
)
+13
View File
@@ -11,6 +11,19 @@ import controller
class ControllerTests(unittest.TestCase):
def test_get_requests_encode_parameters_in_the_query_string(self):
response = io.BytesIO(json.dumps({"code": "Success", "data": "stopped"}).encode())
client = controller.AutoDLClient("test-token")
with mock.patch.object(
controller.urllib.request, "urlopen", return_value=response
) as urlopen:
self.assertEqual(client.status("pro-test"), "stopped")
request = urlopen.call_args.args[0]
self.assertEqual(request.method, "GET")
self.assertIsNone(request.data)
self.assertTrue(request.full_url.endswith("?instance_uuid=pro-test"))
def test_runner_download_uses_explicit_user_agent(self):
payload = b"test-runner"
with tempfile.TemporaryDirectory() as directory: