[#332] Fix files param in http client #332

Merged
abereziny merged 1 commit from Kiriruso/frostfs-testlib:fix-files-param into master 2024-12-05 11:29:52 +00:00

View file

@ -2,7 +2,7 @@ import io
import json import json
import logging import logging
import logging.config import logging.config
from typing import IO from typing import Mapping, Sequence
import httpx import httpx
@ -84,13 +84,20 @@ class HttpClient:
return request_body return request_body
@classmethod @classmethod
def _parse_files(cls, files: dict | None) -> str | None: def _parse_files(cls, files: Mapping | Sequence | None) -> str | None:
if not files: if not files:
return None return None
filepaths = {} filepaths = {}
for name, file in files.items(): if isinstance(files, Sequence):
items = files
elif isinstance(files, Mapping):
items = files.items()
else:
raise TypeError(f"'files' must be either Sequence or Mapping, got: {type(files).__name__}")
for name, file in items:
if isinstance(file, io.IOBase): if isinstance(file, io.IOBase):
filepaths[name] = file.name filepaths[name] = file.name