From 7f9a6b8623edf71887885d539a65ebfa72689183 Mon Sep 17 00:00:00 2001 From: Michael Harbarth Date: Tue, 16 Jan 2024 14:00:03 +0100 Subject: [PATCH 1/3] feat: implement the work item state update introduced in 2310 --- polarion_rest_api_client/base_client.py | 4 +++- polarion_rest_api_client/client.py | 2 ++ tests/test_client_workitems.py | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) 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..2d7c4da9 100644 --- a/polarion_rest_api_client/client.py +++ b/polarion_rest_api_client/client.py @@ -846,11 +846,13 @@ def update_work_item( fields will stay untouched. """ assert work_item.id is not None + work_item_type = work_item.type or oa_types.UNSET response = patch_work_item.sync_detailed( self.project_id, work_item.id, client=self.client, + change_type_to=work_item_type, 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) From 520feefaf41dbbdfaa28201af6424ce2094f6d2b Mon Sep 17 00:00:00 2001 From: Michael Harbarth Date: Tue, 16 Jan 2024 17:00:23 +0100 Subject: [PATCH 2/3] feat: Add a warning logging message if someone uses the new type transition feature --- polarion_rest_api_client/client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/polarion_rest_api_client/client.py b/polarion_rest_api_client/client.py index 2d7c4da9..e870327f 100644 --- a/polarion_rest_api_client/client.py +++ b/polarion_rest_api_client/client.py @@ -847,6 +847,12 @@ def update_work_item( """ assert work_item.id is not None work_item_type = work_item.type or oa_types.UNSET + if work_item_type: + logger.warning( + "You are 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, From 9329bc9a3c6d81390d6aecbf558bf5fce720d88d Mon Sep 17 00:00:00 2001 From: micha91 Date: Wed, 17 Jan 2024 11:22:16 +0100 Subject: [PATCH 3/3] refactor: Apply changes from review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ernst Würger <50786483+ewuerger@users.noreply.github.com> --- polarion_rest_api_client/client.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/polarion_rest_api_client/client.py b/polarion_rest_api_client/client.py index e870327f..ce49dcde 100644 --- a/polarion_rest_api_client/client.py +++ b/polarion_rest_api_client/client.py @@ -846,19 +846,18 @@ def update_work_item( fields will stay untouched. """ assert work_item.id is not None - work_item_type = work_item.type or oa_types.UNSET - if work_item_type: + if work_item.type: logger.warning( - "You are attempting to change the type of Work Item %s to %s.", + "Attempting to change the type of Work Item %s to %s.", work_item.id, - work_item_type, + work_item.type, ) response = patch_work_item.sync_detailed( self.project_id, work_item.id, client=self.client, - change_type_to=work_item_type, + change_type_to=work_item.type or oa_types.UNSET, body=self._build_work_item_patch_request(work_item), )