diff --git a/polarion_rest_api_client/base_client.py b/polarion_rest_api_client/base_client.py index e1565b76..9e1f73bf 100644 --- a/polarion_rest_api_client/base_client.py +++ b/polarion_rest_api_client/base_client.py @@ -249,7 +249,9 @@ def update_work_item(self, work_item: WorkItemType, retry: bool = True): """Update the given work item in Polarion. Only fields not set to None will be updated in Polarion. None - fields will stay untouched. + fields will stay untouched. If you want to change the Work Item + Type, we will extract it from the Work Item passed to this + method. """ raise NotImplementedError diff --git a/polarion_rest_api_client/client.py b/polarion_rest_api_client/client.py index 463fb19a..ce49dcde 100644 --- a/polarion_rest_api_client/client.py +++ b/polarion_rest_api_client/client.py @@ -846,11 +846,18 @@ def update_work_item( fields will stay untouched. """ assert work_item.id is not None + if work_item.type: + logger.warning( + "Attempting to change the type of Work Item %s to %s.", + work_item.id, + work_item.type, + ) response = patch_work_item.sync_detailed( self.project_id, work_item.id, client=self.client, + change_type_to=work_item.type or oa_types.UNSET, body=self._build_work_item_patch_request(work_item), ) diff --git a/tests/test_client_workitems.py b/tests/test_client_workitems.py index 1350e9ad..3fe005f4 100644 --- a/tests/test_client_workitems.py +++ b/tests/test_client_workitems.py @@ -535,6 +535,31 @@ def test_update_work_item_status( assert req is not None assert req.url.path.endswith("PROJ/workitems/MyWorkItemId") assert req.method == "PATCH" + assert len(req.url.params) == 0 + with open(TEST_WI_PATCH_STATUS_REQUEST, encoding="utf8") as f: + assert json.loads(req.content.decode()) == json.load(f) + + +def test_update_work_item_type( + client: polarion_api.OpenAPIPolarionProjectClient, + httpx_mock: pytest_httpx.HTTPXMock, +): + httpx_mock.add_response(204) + + client.update_work_item( + polarion_api.WorkItem( + id="MyWorkItemId", + type="newType", + status="open", + ) + ) + + req = httpx_mock.get_request() + + assert req is not None + assert req.url.path.endswith("PROJ/workitems/MyWorkItemId") + assert req.url.params["changeTypeTo"] == "newType" + assert req.method == "PATCH" with open(TEST_WI_PATCH_STATUS_REQUEST, encoding="utf8") as f: assert json.loads(req.content.decode()) == json.load(f)