-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PY-386][external] Core method to move items between folders & tests (#…
…709) * Core method to move items between folders & tests * Fixed test * Changes to tests to make them consistent with others
- Loading branch information
Showing
11 changed files
with
139 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Dict, List | ||
from uuid import UUID | ||
|
||
from darwin.future.core.client import ClientCore | ||
from darwin.future.core.types.common import JSONType | ||
from darwin.future.data_objects.typing import UnknownType | ||
|
||
|
||
def move_list_of_items_to_folder( | ||
api_client: ClientCore, | ||
team_slug: str, | ||
dataset_id: int, | ||
item_ids: List[UUID], | ||
path: str, | ||
filters: Dict[str, UnknownType] = {}, | ||
) -> JSONType: | ||
""" | ||
Move specified items to a folder | ||
Parameters | ||
---------- | ||
client: Client | ||
The client to use for the request | ||
team_slug: str | ||
The slug of the team containing the items | ||
dataset_id: int | ||
The ID of the dataset containing the items | ||
item_ids: List[UUID] | ||
The IDs of the items to be moved | ||
path: str | ||
The path to the folder to move the items to | ||
filters: Dict[str, UnknownType] | ||
Dataset filter parameters | ||
Returns | ||
------- | ||
JSONType | ||
""" | ||
payload = { | ||
"filters": { | ||
"dataset_ids": [dataset_id], | ||
"item_ids": [str(item_id) for item_id in item_ids], | ||
**filters, | ||
}, | ||
"path": path, | ||
} | ||
|
||
return api_client.post(f"/v2/teams/{team_slug}/items/path", data=payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
darwin/future/tests/core/items/test_move_items_to_folder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from uuid import UUID | ||
|
||
import responses | ||
from pytest import raises | ||
|
||
from darwin.future.core.client import ClientCore | ||
from darwin.future.core.items.move_items_to_folder import move_list_of_items_to_folder | ||
from darwin.future.exceptions import BadRequest | ||
from darwin.future.tests.core.fixtures import * | ||
|
||
|
||
@responses.activate | ||
def test_move_list_of_items_to_folder_including_filters( | ||
base_client: ClientCore, | ||
) -> None: | ||
# Define the expected response | ||
responses.add( | ||
responses.POST, | ||
base_client.config.api_endpoint + "v2/teams/test-team/items/path", | ||
json={"affected_item_count": 2}, | ||
) | ||
|
||
# Call the function | ||
response = move_list_of_items_to_folder( | ||
api_client=base_client, | ||
team_slug="test-team", | ||
dataset_id=000000, | ||
item_ids=[ | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
], | ||
filters={ | ||
"not_statuses": ["uploading", "annotate"], | ||
"not_assignees": [123, 456, 789], | ||
}, | ||
path="/test/path", | ||
) | ||
|
||
# Check that the response mathces what we expect | ||
assert response == {"affected_item_count": 2} | ||
|
||
|
||
def test_move_list_of_items_to_folder_with_error_response( | ||
base_client: ClientCore, | ||
) -> None: | ||
with raises(BadRequest): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
responses.POST, | ||
base_client.config.api_endpoint + "v2/teams/test-team/items/path", | ||
status=400, | ||
) | ||
|
||
move_list_of_items_to_folder( | ||
api_client=base_client, | ||
team_slug="test-team", | ||
dataset_id=000000, | ||
item_ids=[ | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
], | ||
path="/test/path", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters