|
| 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