-
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] Set priority #697
Merged
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Dict, Optional | ||
|
||
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, | ||
priority: int, | ||
filters: Optional[Dict[str, UnknownType]] = None, | ||
) -> 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: Dict["str", UnknownType] = { | ||
"priority": priority, | ||
} | ||
|
||
if filters: | ||
payload = { | ||
**payload, | ||
"filters": filters, | ||
} | ||
|
||
return api_client.post( | ||
endpoint=f"/v2/teams/{team_slug}/items/priority", | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from darwin.exceptions import DarwinException | ||
from darwin.future.core.client import ClientCore | ||
from darwin.future.core.items.set_priority import set_item_priority | ||
|
||
|
||
def test_set_item_priority() -> None: | ||
# Create a mock API client | ||
api_client = Mock(spec=ClientCore) | ||
owencjones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Define the expected payload | ||
expected_payload = {"priority": 10} | ||
|
||
# Define the expected endpoint | ||
expected_endpoint = "/v2/teams/test-team/items/priority" | ||
|
||
# Define the expected response | ||
expected_response = {"status": "success"} | ||
|
||
# Configure the mock API client to return the expected response | ||
api_client.post.return_value = expected_response | ||
|
||
# Call the function being tested | ||
response = set_item_priority( | ||
api_client=api_client, | ||
team_slug="test-team", | ||
priority=10, | ||
) | ||
|
||
# Verify that the API client was called with the expected arguments | ||
api_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_filters() -> None: | ||
# Create a mock API client | ||
api_client = Mock(spec=ClientCore) | ||
|
||
# Define the expected payload | ||
expected_payload = { | ||
"priority": 10, | ||
"filters": {"status": "open"}, | ||
} | ||
|
||
# Define the expected endpoint | ||
expected_endpoint = "/v2/teams/test-team/items/priority" | ||
|
||
# Define the expected response | ||
expected_response = {"status": "success"} | ||
|
||
# Configure the mock API client to return the expected response | ||
api_client.post.return_value = expected_response | ||
|
||
# Call the function being tested | ||
response = set_item_priority( | ||
api_client=api_client, | ||
team_slug="test-team", | ||
priority=10, | ||
filters={"status": "open"}, | ||
) | ||
|
||
# Verify that the API client was called with the expected arguments | ||
api_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", | ||
priority=10, | ||
) |
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.
This is not blocking at all but interested here on your thoughts on
filters: Optional[...] = None
vsfilters: ... = {}
Is it more pythonic to assume None's or empty objects? The former does tend to lead to requiring more typecheck guards to satisfy mypy/pylance with likeassert filters is not None
etc, which does feel more verbose than required sometimes.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.
but obviously, it is a bit more clear that filters isn't required via the
Optional[...] = None
approachThere 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.
Nah, good point, I like the default in this backend code, will take this suggestion