From ee7d9df4a9eddf7da21b66a2070227c0aaa71ad2 Mon Sep 17 00:00:00 2001 From: Kirill Sosnovskikh Date: Thu, 5 Dec 2024 16:34:36 +0300 Subject: [PATCH] [#333] Fix `files` param in http client part two Signed-off-by: Kirill Sosnovskikh --- src/frostfs_testlib/http/http_client.py | 26 ++++++++++--------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/frostfs_testlib/http/http_client.py b/src/frostfs_testlib/http/http_client.py index 6008989..a3e3e54 100644 --- a/src/frostfs_testlib/http/http_client.py +++ b/src/frostfs_testlib/http/http_client.py @@ -84,12 +84,12 @@ class HttpClient: return request_body @classmethod - def _parse_files(cls, files: Mapping | Sequence | None) -> str | None: - if not files: - return None - + def _parse_files(cls, files: Mapping | Sequence | None) -> dict: filepaths = {} + if not files: + return filepaths + if isinstance(files, Sequence): items = files elif isinstance(files, Mapping): @@ -100,11 +100,10 @@ class HttpClient: for name, file in items: if isinstance(file, io.IOBase): filepaths[name] = file.name - - if isinstance(file, tuple): + elif isinstance(file, Sequence): filepaths[name] = file[1].name - return json.dumps(filepaths, default=str, indent=4) + return filepaths @classmethod def _attach_response(cls, response: httpx.Response, **kwargs): @@ -128,23 +127,18 @@ class HttpClient: + f"Response Headers: {response_headers}\n\n" + (f"Response Body: {response_body}\n\n" if response_body else "") ) - curl_request = cls._create_curl_request(request.url, request.method, request.headers, request_body, files) + curl_request = cls._create_curl_request(request.url, request.method, request.headers, request_body, request_files) reporter.attach(report, "Requests Info") reporter.attach(curl_request, "CURL") @classmethod - def _create_curl_request(cls, url: str, method: str, headers: httpx.Headers, data: str, files: dict = None) -> str: + def _create_curl_request(cls, url: str, method: str, headers: httpx.Headers, data: str, files: dict) -> str: headers = " ".join(f'-H "{name.title()}: {value}"' for name, value in headers.items()) data = f" -d '{data}'" if data else "" - if files: - for name, file in files.items(): - if isinstance(file, io.IOBase): - data += f' -F "{name}=@{file.name}"' - - if isinstance(file, tuple): - data += f' -F "{name}=@{file[1].name}"' + for name, path in files.items(): + data += f' -F "{name}=@{path}"' # Option -k means no verify SSL return f"curl {url} -X {method} {headers}{data} -k"