Skip to content

Commit

Permalink
fixing failure to fetch files with commas (#359)
Browse files Browse the repository at this point in the history
* fixing failure to fetch files with commas

* changed filter in test

* Update tests/darwin/dataset/remote_dataset_test.py

Co-authored-by: Andrea Azzini <[email protected]>

Co-authored-by: Andrea Azzini <[email protected]>
  • Loading branch information
Fl4m3Ph03n1x and andreaazzini authored Feb 24, 2022
1 parent 18c337b commit cef92a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions darwin/dataset/remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,14 @@ def fetch_remote_files(
Iterator[DatasetItem]
An iterator of ``DatasetItem``.
"""
post_filters: Dict[str, str] = {}
post_filters: Dict[str, Union[str, List[str]]] = {}
post_sort: Dict[str, str] = {}

if filters:
for list_type in ["filenames", "statuses"]:
if list_type in filters:
if type(filters[list_type]) is list:
post_filters[list_type] = ",".join(filters[list_type])
post_filters[list_type] = filters[list_type]
else:
post_filters[list_type] = str(filters[list_type])
if "path" in filters:
Expand Down
21 changes: 21 additions & 0 deletions tests/darwin/dataset/remote_dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,27 @@ def it_works(darwin_client: Client, dataset_name: str, dataset_slug: str, team_s
assert item_1.id == 386074
assert item_2.id == 386073

@responses.activate
def it_fetches_files_with_commas(
darwin_client: Client, dataset_name: str, dataset_slug: str, team_slug: str, files_content: dict
):
remote_dataset = RemoteDataset(
client=darwin_client, team=team_slug, name=dataset_name, slug=dataset_slug, dataset_id=1
)
url = "http://localhost/api/datasets/1/items?page%5Bsize%5D=500"
responses.add(
responses.POST,
url,
json=files_content,
status=200,
)

list(remote_dataset.fetch_remote_files({"filenames": ["example,with, comma.mp4"]}))

request_body = json.loads(responses.calls[0].request.body)

assert request_body["filter"]["filenames"] == ["example,with, comma.mp4"]


@pytest.fixture
def remote_dataset(darwin_client: Client, dataset_name: str, dataset_slug: str, team_slug: str):
Expand Down

0 comments on commit cef92a9

Please sign in to comment.