-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IO-1801][external] Core item archive method & tests #702
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,44 @@ | ||
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 archive_list_of_items( | ||
api_client: ClientCore, | ||
team_slug: str, | ||
dataset_id: int, | ||
item_ids: List[UUID], | ||
filters: Dict[str, UnknownType] = {}, | ||
) -> JSONType: | ||
""" | ||
Archive specified items | ||
|
||
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 archived | ||
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, | ||
} | ||
} | ||
|
||
return api_client.post(f"/v2/teams/{team_slug}/items/archive", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from unittest.mock import Mock | ||
from uuid import UUID | ||
|
||
import pytest | ||
import responses | ||
|
||
from darwin.exceptions import DarwinException | ||
from darwin.future.core.client import ClientCore | ||
from darwin.future.core.items.archive_items import archive_list_of_items | ||
from darwin.future.tests.core.fixtures import * | ||
|
||
|
||
@responses.activate | ||
def test_archive_items_including_filters(base_client: ClientCore) -> None: | ||
# Define the expected response | ||
responses.add( | ||
responses.POST, | ||
base_client.config.api_endpoint + "v2/teams/test-team/items/archive", | ||
json={"affected_item_count": 2}, | ||
) | ||
|
||
# Call the function | ||
response = archive_list_of_items( | ||
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], | ||
}, | ||
) | ||
|
||
# Check that the response mathces what we expect | ||
assert response == {"affected_item_count": 2} | ||
|
||
|
||
def test_archive_items_with_error_response() -> None: | ||
api_client = Mock(spec=ClientCore) | ||
api_client.post.side_effect = DarwinException("Something went wrong") | ||
|
||
with pytest.raises(DarwinException): | ||
archive_list_of_items( | ||
api_client=api_client, | ||
team_slug="test-team", | ||
dataset_id=000000, | ||
item_ids=[ | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
], | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to surface / deal with / pprint 422s later, especially because the endpoints generally do a good job of pointing out exactly what causes 422s