Skip to content

Commit

Permalink
merge: Merge pull request #21 from DSD-DBS/patch-workitem-type
Browse files Browse the repository at this point in the history
Feat: Add patch Work Item Type functionality
  • Loading branch information
micha91 authored Jan 17, 2024
2 parents 8d50bb8 + 9329bc9 commit 705deb3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion polarion_rest_api_client/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions polarion_rest_api_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand Down
25 changes: 25 additions & 0 deletions tests/test_client_workitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 705deb3

Please sign in to comment.