-
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-1800][internal] Set Priority of items #699
Changes from 7 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Dict | ||
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 set_item_priority( | ||
api_client: ClientCore, | ||
team_slug: str, | ||
dataset_id: int, | ||
item_id: UUID, | ||
priority: int, | ||
filters: Dict[str, UnknownType] = {}, | ||
) -> JSONType: | ||
""" | ||
Sets the priority of an item | ||
|
||
Parameters | ||
---------- | ||
client: Client | ||
The client to use for the request | ||
team_slug: str | ||
The slug of the team to set the priority for | ||
priority: int | ||
The priority to set | ||
|
||
Returns | ||
------- | ||
JSONType | ||
""" | ||
payload = { | ||
"priority": priority, | ||
"filters": { | ||
"item_ids": [str(item_id)], | ||
"dataset_ids": [dataset_id], | ||
**filters, | ||
}, | ||
} | ||
|
||
return api_client.post( | ||
endpoint=f"/v2/teams/{team_slug}/items/priority", | ||
data=payload, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
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.set_item_priority import set_item_priority | ||
from darwin.future.tests.core.fixtures import * | ||
|
||
|
||
@responses.activate | ||
def test_set_item_priority(base_client) -> None: | ||
responses.add( | ||
responses.POST, | ||
base_client.config.api_endpoint + "v2/teams/test-team/items/priority", | ||
json={"affected_item_count": 0}, | ||
) | ||
|
||
response = set_item_priority( | ||
base_client, | ||
"test-team", | ||
123, | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
999, | ||
) | ||
|
||
assert response == {"affected_item_count": 0} | ||
|
||
|
||
def test_set_item_priority_with_filters() -> None: | ||
base_client = Mock(spec=ClientCore) | ||
|
||
expected_payload = { | ||
"priority": 10, | ||
"filters": { | ||
"dataset_ids": [123], | ||
"item_ids": ["00000000-0000-0000-0000-000000000000"], | ||
"status": "open", | ||
}, | ||
} | ||
|
||
# Define the expected endpoint | ||
expected_endpoint = "/v2/teams/test-team/items/priority" | ||
|
||
# Define the expected response | ||
expected_response = {"status": "success"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be missing something, but if successful doesn't the endpoint always return I couldn't get it to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you pass it a 422 inducing load of rubbish, it returns a response including
|
||
|
||
# Configure the mock API client to return the expected response | ||
base_client.post.return_value = expected_response | ||
|
||
# Call the function being tested | ||
response = set_item_priority( | ||
base_client, | ||
"test-team", | ||
123, | ||
UUID("00000000-0000-0000-0000-000000000000"), | ||
priority=10, | ||
filters={"status": "open"}, | ||
) | ||
|
||
# Verify that the API client was called with the expected arguments | ||
base_client.post.assert_called_once_with( | ||
endpoint=expected_endpoint, | ||
data=expected_payload, | ||
) | ||
|
||
# Verify that the response matches the expected response | ||
assert response == expected_response | ||
|
||
|
||
def test_set_item_priority_with_error_response() -> None: | ||
# Create a mock API client | ||
api_client = Mock(spec=ClientCore) | ||
|
||
# Configure the mock API client to return the error response | ||
api_client.post.side_effect = DarwinException("Something went wrong") | ||
|
||
# Call the function being tested | ||
with pytest.raises(DarwinException): | ||
set_item_priority( | ||
api_client=api_client, | ||
team_slug="test-team", | ||
dataset_id=123, | ||
item_id=UUID("00000000-0000-0000-0000-000000000000"), | ||
priority=10, | ||
) |
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.
I think the set priority endpoint can accept a list of
item_ids
, would it made sense to allow this to as well?If so, maybe:
set_item_priority()
acceptsitem_ids: List[UUID]
, then:"item_ids": [str(item_id) for item_id in item_ids]
at this point