From d630b79e8b1f9ea9574cddfb8067e5ffed292eab Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 19 Feb 2022 15:14:55 -0500 Subject: [PATCH] tests: http client fixes Correctly encode the query string. Use the query string for DELETE requests in addition to GET requests. Signed-off-by: Eric Callahan --- tests/fixtures/http_client.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/fixtures/http_client.py b/tests/fixtures/http_client.py index c746e2d..0e69c9f 100644 --- a/tests/fixtures/http_client.py +++ b/tests/fixtures/http_client.py @@ -1,11 +1,12 @@ from __future__ import annotations import json -from tornado.httpclient import AsyncHTTPClient, HTTPRequest +from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPError from tornado.httputil import HTTPHeaders from tornado.escape import url_escape from typing import Dict, Any, Optional class HttpClient: + error = HTTPError def __init__(self, type: str = "http", port: int = 7010 @@ -30,16 +31,16 @@ class HttpClient: method = method.upper() body: Optional[str] = "" if method == "POST" else None if args: - if method == "GET": + if method in ["GET", "DELETE"]: parts = [] for key, val in args.items(): if isinstance(val, list): val = ",".join(val) if val: - parts.append(f"{key}={val}") + parts.append(f"{url_escape(key)}={url_escape(val)}") else: - parts.append(key) - qs = url_escape("&".join(parts)) + parts.append(url_escape(key)) + qs = "&".join(parts) url += "?" + qs else: body = json.dumps(args)