Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add patch Work Item Type functionality #21

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading