diff --git a/src/uipath/platform/orchestrator/_queues_service.py b/src/uipath/platform/orchestrator/_queues_service.py index 9f1aebdb9..fc3045a33 100644 --- a/src/uipath/platform/orchestrator/_queues_service.py +++ b/src/uipath/platform/orchestrator/_queues_service.py @@ -1,8 +1,8 @@ -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Optional, Union from httpx import Response -from ..._utils import Endpoint, RequestSpec +from ..._utils import Endpoint, RequestSpec, header_folder from ...tracing import traced from ..common import BaseService, FolderContext, UiPathApiConfig, UiPathExecutionContext from .queues import ( @@ -26,61 +26,101 @@ def __init__( super().__init__(config=config, execution_context=execution_context) @traced(name="queues_list_items", run_type="uipath") - def list_items(self) -> Response: + def list_items( + self, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, + ) -> Response: """Retrieves a list of queue items from the Orchestrator. + Args: + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. + Returns: Response: HTTP response containing the list of queue items. """ - spec = self._list_items_spec() - response = self.request(spec.method, url=spec.endpoint) + spec = self._list_items_spec(folder_key=folder_key, folder_path=folder_path) + response = self.request(spec.method, url=spec.endpoint, headers=spec.headers) return response.json() @traced(name="queues_list_items", run_type="uipath") - async def list_items_async(self) -> Response: + async def list_items_async( + self, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, + ) -> Response: """Asynchronously retrieves a list of queue items from the Orchestrator. + Args: + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. + Returns: Response: HTTP response containing the list of queue items. """ - spec = self._list_items_spec() - response = await self.request_async(spec.method, url=spec.endpoint) + spec = self._list_items_spec(folder_key=folder_key, folder_path=folder_path) + response = await self.request_async( + spec.method, url=spec.endpoint, headers=spec.headers + ) return response.json() @traced(name="queues_create_item", run_type="uipath") - def create_item(self, item: Union[Dict[str, Any], QueueItem]) -> Response: + def create_item( + self, + item: Union[Dict[str, Any], QueueItem], + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, + ) -> Response: """Creates a new queue item in the Orchestrator. Args: item: Queue item data, either as a dictionary or QueueItem instance. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response containing the created queue item details. Related Activity: [Add Queue Item](https://docs.uipath.com/ACTIVITIES/other/latest/workflow/add-queue-item) """ - spec = self._create_item_spec(item) - response = self.request(spec.method, url=spec.endpoint, json=spec.json) + spec = self._create_item_spec( + item, folder_key=folder_key, folder_path=folder_path + ) + response = self.request( + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers + ) return response.json() @traced(name="queues_create_item", run_type="uipath") async def create_item_async( - self, item: Union[Dict[str, Any], QueueItem] + self, + item: Union[Dict[str, Any], QueueItem], + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Asynchronously creates a new queue item in the Orchestrator. Args: item: Queue item data, either as a dictionary or QueueItem instance. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response containing the created queue item details. Related Activity: [Add Queue Item](https://docs.uipath.com/ACTIVITIES/other/latest/workflow/add-queue-item) """ - spec = self._create_item_spec(item) + spec = self._create_item_spec( + item, folder_key=folder_key, folder_path=folder_path + ) response = await self.request_async( - spec.method, url=spec.endpoint, json=spec.json + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers ) return response.json() @@ -90,6 +130,9 @@ def create_items( items: List[Union[Dict[str, Any], QueueItem]], queue_name: str, commit_type: CommitType, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Creates multiple queue items in bulk. @@ -97,12 +140,22 @@ def create_items( items: List of queue items to create, each either a dictionary or QueueItem instance. queue_name: Name of the target queue. commit_type: Type of commit operation to use for the bulk operation. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response containing the bulk operation result. """ - spec = self._create_items_spec(items, queue_name, commit_type) - response = self.request(spec.method, url=spec.endpoint, json=spec.json) + spec = self._create_items_spec( + items, + queue_name, + commit_type, + folder_key=folder_key, + folder_path=folder_path, + ) + response = self.request( + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers + ) return response.json() @traced(name="queues_create_items", run_type="uipath") @@ -111,6 +164,9 @@ async def create_items_async( items: List[Union[Dict[str, Any], QueueItem]], queue_name: str, commit_type: CommitType, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Asynchronously creates multiple queue items in bulk. @@ -118,129 +174,197 @@ async def create_items_async( items: List of queue items to create, each either a dictionary or QueueItem instance. queue_name: Name of the target queue. commit_type: Type of commit operation to use for the bulk operation. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response containing the bulk operation result. """ - spec = self._create_items_spec(items, queue_name, commit_type) + spec = self._create_items_spec( + items, + queue_name, + commit_type, + folder_key=folder_key, + folder_path=folder_path, + ) response = await self.request_async( - spec.method, url=spec.endpoint, json=spec.json + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers ) return response.json() @traced(name="queues_create_transaction_item", run_type="uipath") def create_transaction_item( - self, item: Union[Dict[str, Any], TransactionItem], no_robot: bool = False + self, + item: Union[Dict[str, Any], TransactionItem], + no_robot: bool = False, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Creates a new transaction item in a queue. Args: item: Transaction item data, either as a dictionary or TransactionItem instance. no_robot: If True, the transaction will not be associated with a robot. Defaults to False. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response containing the transaction item details. """ - spec = self._create_transaction_item_spec(item, no_robot) - response = self.request(spec.method, url=spec.endpoint, json=spec.json) + spec = self._create_transaction_item_spec( + item, no_robot, folder_key=folder_key, folder_path=folder_path + ) + response = self.request( + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers + ) return response.json() @traced(name="queues_create_transaction_item", run_type="uipath") async def create_transaction_item_async( - self, item: Union[Dict[str, Any], TransactionItem], no_robot: bool = False + self, + item: Union[Dict[str, Any], TransactionItem], + no_robot: bool = False, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Asynchronously creates a new transaction item in a queue. Args: item: Transaction item data, either as a dictionary or TransactionItem instance. no_robot: If True, the transaction will not be associated with a robot. Defaults to False. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response containing the transaction item details. """ - spec = self._create_transaction_item_spec(item, no_robot) + spec = self._create_transaction_item_spec( + item, no_robot, folder_key=folder_key, folder_path=folder_path + ) response = await self.request_async( - spec.method, url=spec.endpoint, json=spec.json + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers ) return response.json() @traced(name="queues_update_progress_of_transaction_item", run_type="uipath") def update_progress_of_transaction_item( - self, transaction_key: str, progress: str + self, + transaction_key: str, + progress: str, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Updates the progress of a transaction item. Args: transaction_key: Unique identifier of the transaction. progress: Progress message to set. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response confirming the progress update. Related Activity: [Set Transaction Progress](https://docs.uipath.com/activities/other/latest/workflow/set-transaction-progress) """ - spec = self._update_progress_of_transaction_item_spec(transaction_key, progress) - response = self.request(spec.method, url=spec.endpoint, json=spec.json) + spec = self._update_progress_of_transaction_item_spec( + transaction_key, progress, folder_key=folder_key, folder_path=folder_path + ) + response = self.request( + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers + ) return response.json() @traced(name="queues_update_progress_of_transaction_item", run_type="uipath") async def update_progress_of_transaction_item_async( - self, transaction_key: str, progress: str + self, + transaction_key: str, + progress: str, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Asynchronously updates the progress of a transaction item. Args: transaction_key: Unique identifier of the transaction. progress: Progress message to set. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response confirming the progress update. Related Activity: [Set Transaction Progress](https://docs.uipath.com/activities/other/latest/workflow/set-transaction-progress) """ - spec = self._update_progress_of_transaction_item_spec(transaction_key, progress) + spec = self._update_progress_of_transaction_item_spec( + transaction_key, progress, folder_key=folder_key, folder_path=folder_path + ) response = await self.request_async( - spec.method, url=spec.endpoint, json=spec.json + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers ) return response.json() @traced(name="queues_complete_transaction_item", run_type="uipath") def complete_transaction_item( - self, transaction_key: str, result: Union[Dict[str, Any], TransactionItemResult] + self, + transaction_key: str, + result: Union[Dict[str, Any], TransactionItemResult], + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Completes a transaction item with the specified result. Args: transaction_key: Unique identifier of the transaction to complete. result: Result data for the transaction, either as a dictionary or TransactionItemResult instance. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response confirming the transaction completion. Related Activity: [Set Transaction Status](https://docs.uipath.com/activities/other/latest/workflow/set-transaction-status) """ - spec = self._complete_transaction_item_spec(transaction_key, result) - response = self.request(spec.method, url=spec.endpoint, json=spec.json) + spec = self._complete_transaction_item_spec( + transaction_key, result, folder_key=folder_key, folder_path=folder_path + ) + response = self.request( + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers + ) return response.json() @traced(name="queues_complete_transaction_item", run_type="uipath") async def complete_transaction_item_async( - self, transaction_key: str, result: Union[Dict[str, Any], TransactionItemResult] + self, + transaction_key: str, + result: Union[Dict[str, Any], TransactionItemResult], + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> Response: """Asynchronously completes a transaction item with the specified result. Args: transaction_key: Unique identifier of the transaction to complete. result: Result data for the transaction, either as a dictionary or TransactionItemResult instance. + folder_key (Optional[str]): The key of the folder. Overrides the default one set in the SDK config. + folder_path (Optional[str]): The path of the folder. Overrides the default one set in the SDK config. Returns: Response: HTTP response confirming the transaction completion. Related Activity: [Set Transaction Status](https://docs.uipath.com/activities/other/latest/workflow/set-transaction-status) """ - spec = self._complete_transaction_item_spec(transaction_key, result) + spec = self._complete_transaction_item_spec( + transaction_key, result, folder_key=folder_key, folder_path=folder_path + ) response = await self.request_async( - spec.method, url=spec.endpoint, json=spec.json + spec.method, url=spec.endpoint, json=spec.json, headers=spec.headers ) return response.json() @@ -248,13 +372,27 @@ async def complete_transaction_item_async( def custom_headers(self) -> Dict[str, str]: return self.folder_headers - def _list_items_spec(self) -> RequestSpec: + def _list_items_spec( + self, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, + ) -> RequestSpec: return RequestSpec( method="GET", endpoint=Endpoint("/orchestrator_/odata/QueueItems"), + headers={ + **header_folder(folder_key, folder_path), + }, ) - def _create_item_spec(self, item: Union[Dict[str, Any], QueueItem]) -> RequestSpec: + def _create_item_spec( + self, + item: Union[Dict[str, Any], QueueItem], + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, + ) -> RequestSpec: if isinstance(item, dict): queue_item = QueueItem(**item) elif isinstance(item, QueueItem): @@ -270,6 +408,9 @@ def _create_item_spec(self, item: Union[Dict[str, Any], QueueItem]) -> RequestSp "/orchestrator_/odata/Queues/UiPathODataSvc.AddQueueItem" ), json=json_payload, + headers={ + **header_folder(folder_key, folder_path), + }, ) def _create_items_spec( @@ -277,6 +418,9 @@ def _create_items_spec( items: List[Union[Dict[str, Any], QueueItem]], queue_name: str, commit_type: CommitType, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> RequestSpec: return RequestSpec( method="POST", @@ -293,10 +437,18 @@ def _create_items_spec( for item in items ], }, + headers={ + **header_folder(folder_key, folder_path), + }, ) def _create_transaction_item_spec( - self, item: Union[Dict[str, Any], TransactionItem], no_robot: bool = False + self, + item: Union[Dict[str, Any], TransactionItem], + no_robot: bool = False, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> RequestSpec: if isinstance(item, dict): transaction_item = TransactionItem(**item) @@ -318,10 +470,18 @@ def _create_transaction_item_spec( ), } }, + headers={ + **header_folder(folder_key, folder_path), + }, ) def _update_progress_of_transaction_item_spec( - self, transaction_key: str, progress: str + self, + transaction_key: str, + progress: str, + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> RequestSpec: return RequestSpec( method="POST", @@ -329,10 +489,18 @@ def _update_progress_of_transaction_item_spec( f"/orchestrator_/odata/QueueItems({transaction_key})/UiPathODataSvc.SetTransactionProgress" ), json={"progress": progress}, + headers={ + **header_folder(folder_key, folder_path), + }, ) def _complete_transaction_item_spec( - self, transaction_key: str, result: Union[Dict[str, Any], TransactionItemResult] + self, + transaction_key: str, + result: Union[Dict[str, Any], TransactionItemResult], + *, + folder_key: Optional[str] = None, + folder_path: Optional[str] = None, ) -> RequestSpec: if isinstance(result, dict): transaction_result = TransactionItemResult(**result) @@ -349,4 +517,7 @@ def _complete_transaction_item_spec( exclude_unset=True, by_alias=True ) }, + headers={ + **header_folder(folder_key, folder_path), + }, ) diff --git a/tests/sdk/services/test_queues_service.py b/tests/sdk/services/test_queues_service.py index 58ee2d5b5..0696c8880 100644 --- a/tests/sdk/services/test_queues_service.py +++ b/tests/sdk/services/test_queues_service.py @@ -3,7 +3,11 @@ import pytest from pytest_httpx import HTTPXMock -from uipath._utils.constants import HEADER_USER_AGENT +from uipath._utils.constants import ( + HEADER_FOLDER_KEY, + HEADER_FOLDER_PATH, + HEADER_USER_AGENT, +) from uipath.platform import UiPathApiConfig, UiPathExecutionContext from uipath.platform.orchestrator import ( CommitType, @@ -806,3 +810,374 @@ async def test_complete_transaction_item_async( sent_request.headers[HEADER_USER_AGENT] == f"UiPath.Python.Sdk/UiPath.Python.Sdk.Activities.QueuesService.complete_transaction_item_async/{version}" ) + + def test_list_items_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/QueueItems", + status_code=200, + json={"value": []}, + ) + + service.list_items(folder_key="custom-folder-key") + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + def test_list_items_with_folder_path( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/QueueItems", + status_code=200, + json={"value": []}, + ) + + service.list_items(folder_path="Custom/Folder/Path") + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_PATH in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_PATH] == "Custom/Folder/Path" + + @pytest.mark.asyncio + async def test_list_items_async_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/QueueItems", + status_code=200, + json={"value": []}, + ) + + await service.list_items_async(folder_key="custom-folder-key") + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + def test_create_item_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + queue_item = QueueItem( + name="test-queue", + priority=QueueItemPriority.HIGH, + specific_content={"key": "value"}, + ) + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues/UiPathODataSvc.AddQueueItem", + status_code=200, + json={"Id": 1}, + ) + + service.create_item(queue_item, folder_key="custom-folder-key") + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + def test_create_item_with_folder_path( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + queue_item = QueueItem( + name="test-queue", + priority=QueueItemPriority.HIGH, + specific_content={"key": "value"}, + ) + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues/UiPathODataSvc.AddQueueItem", + status_code=200, + json={"Id": 1}, + ) + + service.create_item(queue_item, folder_path="Custom/Folder/Path") + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_PATH in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_PATH] == "Custom/Folder/Path" + + @pytest.mark.asyncio + async def test_create_item_async_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + queue_item = QueueItem( + name="test-queue", + priority=QueueItemPriority.HIGH, + specific_content={"key": "value"}, + ) + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues/UiPathODataSvc.AddQueueItem", + status_code=200, + json={"Id": 1}, + ) + + await service.create_item_async(queue_item, folder_key="custom-folder-key") + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + def test_create_items_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + queue_items = [ + QueueItem( + name="test-queue", + priority=QueueItemPriority.HIGH, + specific_content={"key": "value"}, + ), + ] + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues/UiPathODataSvc.BulkAddQueueItems", + status_code=200, + json={"value": []}, + ) + + service.create_items( + queue_items, + "test-queue", + CommitType.ALL_OR_NOTHING, + folder_key="custom-folder-key", + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + @pytest.mark.asyncio + async def test_create_items_async_with_folder_path( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + queue_items = [ + QueueItem( + name="test-queue", + priority=QueueItemPriority.HIGH, + specific_content={"key": "value"}, + ), + ] + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues/UiPathODataSvc.BulkAddQueueItems", + status_code=200, + json={"value": []}, + ) + + await service.create_items_async( + queue_items, + "test-queue", + CommitType.ALL_OR_NOTHING, + folder_path="Custom/Folder/Path", + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_PATH in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_PATH] == "Custom/Folder/Path" + + def test_create_transaction_item_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + transaction_item = TransactionItem( + name="test-queue", + specific_content={"key": "value"}, + ) + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues/UiPathODataSvc.StartTransaction", + status_code=200, + json={"Id": 1}, + ) + + service.create_transaction_item( + transaction_item, folder_key="custom-folder-key" + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + @pytest.mark.asyncio + async def test_create_transaction_item_async_with_folder_path( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + transaction_item = TransactionItem( + name="test-queue", + specific_content={"key": "value"}, + ) + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues/UiPathODataSvc.StartTransaction", + status_code=200, + json={"Id": 1}, + ) + + await service.create_transaction_item_async( + transaction_item, folder_path="Custom/Folder/Path" + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_PATH in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_PATH] == "Custom/Folder/Path" + + def test_update_progress_of_transaction_item_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + transaction_key = "test-transaction-key" + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/QueueItems({transaction_key})/UiPathODataSvc.SetTransactionProgress", + status_code=200, + json={"status": "success"}, + ) + + service.update_progress_of_transaction_item( + transaction_key, "Processing...", folder_key="custom-folder-key" + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + @pytest.mark.asyncio + async def test_update_progress_of_transaction_item_async_with_folder_path( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + transaction_key = "test-transaction-key" + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/QueueItems({transaction_key})/UiPathODataSvc.SetTransactionProgress", + status_code=200, + json={"status": "success"}, + ) + + await service.update_progress_of_transaction_item_async( + transaction_key, "Processing...", folder_path="Custom/Folder/Path" + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_PATH in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_PATH] == "Custom/Folder/Path" + + def test_complete_transaction_item_with_folder_key( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + transaction_key = "test-transaction-key" + result = TransactionItemResult( + is_successful=True, + output={"result": "success"}, + ) + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues({transaction_key})/UiPathODataSvc.SetTransactionResult", + status_code=200, + json={"status": "success"}, + ) + + service.complete_transaction_item( + transaction_key, result, folder_key="custom-folder-key" + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_KEY in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_KEY] == "custom-folder-key" + + @pytest.mark.asyncio + async def test_complete_transaction_item_async_with_folder_path( + self, + httpx_mock: HTTPXMock, + service: QueuesService, + base_url: str, + org: str, + tenant: str, + ) -> None: + transaction_key = "test-transaction-key" + result = TransactionItemResult( + is_successful=True, + output={"result": "success"}, + ) + httpx_mock.add_response( + url=f"{base_url}{org}{tenant}/orchestrator_/odata/Queues({transaction_key})/UiPathODataSvc.SetTransactionResult", + status_code=200, + json={"status": "success"}, + ) + + await service.complete_transaction_item_async( + transaction_key, result, folder_path="Custom/Folder/Path" + ) + + sent_request = httpx_mock.get_request() + assert sent_request is not None + assert HEADER_FOLDER_PATH in sent_request.headers + assert sent_request.headers[HEADER_FOLDER_PATH] == "Custom/Folder/Path"