Skip to content

Commit 21cbfe0

Browse files
owencjonesOwen
andauthored
[IO-1800] Set priority (#697)
* Implementation * Linting --------- Co-authored-by: Owen <[email protected]>
1 parent f12feb4 commit 21cbfe0

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from typing import Dict, Optional
2+
3+
from darwin.future.core.client import ClientCore
4+
from darwin.future.core.types.common import JSONType
5+
from darwin.future.data_objects.typing import UnknownType
6+
7+
8+
def set_item_priority(
9+
api_client: ClientCore,
10+
team_slug: str,
11+
priority: int,
12+
filters: Optional[Dict[str, UnknownType]] = None,
13+
) -> JSONType:
14+
"""
15+
Sets the priority of an item
16+
17+
Parameters
18+
----------
19+
client: Client
20+
The client to use for the request
21+
team_slug: str
22+
The slug of the team to set the priority for
23+
priority: int
24+
The priority to set
25+
26+
Returns
27+
-------
28+
JSONType
29+
"""
30+
payload: Dict["str", UnknownType] = {
31+
"priority": priority,
32+
}
33+
34+
if filters:
35+
payload = {
36+
**payload,
37+
"filters": filters,
38+
}
39+
40+
return api_client.post(
41+
endpoint=f"/v2/teams/{team_slug}/items/priority",
42+
data=payload,
43+
)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from unittest.mock import Mock
2+
3+
import pytest
4+
5+
from darwin.exceptions import DarwinException
6+
from darwin.future.core.client import ClientCore
7+
from darwin.future.core.items.set_priority import set_item_priority
8+
9+
10+
def test_set_item_priority() -> None:
11+
# Create a mock API client
12+
api_client = Mock(spec=ClientCore)
13+
14+
# Define the expected payload
15+
expected_payload = {"priority": 10}
16+
17+
# Define the expected endpoint
18+
expected_endpoint = "/v2/teams/test-team/items/priority"
19+
20+
# Define the expected response
21+
expected_response = {"status": "success"}
22+
23+
# Configure the mock API client to return the expected response
24+
api_client.post.return_value = expected_response
25+
26+
# Call the function being tested
27+
response = set_item_priority(
28+
api_client=api_client,
29+
team_slug="test-team",
30+
priority=10,
31+
)
32+
33+
# Verify that the API client was called with the expected arguments
34+
api_client.post.assert_called_once_with(
35+
endpoint=expected_endpoint,
36+
data=expected_payload,
37+
)
38+
39+
# Verify that the response matches the expected response
40+
assert response == expected_response
41+
42+
43+
def test_set_item_priority_with_filters() -> None:
44+
# Create a mock API client
45+
api_client = Mock(spec=ClientCore)
46+
47+
# Define the expected payload
48+
expected_payload = {
49+
"priority": 10,
50+
"filters": {"status": "open"},
51+
}
52+
53+
# Define the expected endpoint
54+
expected_endpoint = "/v2/teams/test-team/items/priority"
55+
56+
# Define the expected response
57+
expected_response = {"status": "success"}
58+
59+
# Configure the mock API client to return the expected response
60+
api_client.post.return_value = expected_response
61+
62+
# Call the function being tested
63+
response = set_item_priority(
64+
api_client=api_client,
65+
team_slug="test-team",
66+
priority=10,
67+
filters={"status": "open"},
68+
)
69+
70+
# Verify that the API client was called with the expected arguments
71+
api_client.post.assert_called_once_with(
72+
endpoint=expected_endpoint,
73+
data=expected_payload,
74+
)
75+
76+
# Verify that the response matches the expected response
77+
assert response == expected_response
78+
79+
80+
def test_set_item_priority_with_error_response() -> None:
81+
# Create a mock API client
82+
api_client = Mock(spec=ClientCore)
83+
84+
# Configure the mock API client to return the error response
85+
api_client.post.side_effect = DarwinException("Something went wrong")
86+
87+
# Call the function being tested
88+
with pytest.raises(DarwinException):
89+
set_item_priority(
90+
api_client=api_client,
91+
team_slug="test-team",
92+
priority=10,
93+
)

0 commit comments

Comments
 (0)