Skip to content

Commit

Permalink
refactor: Remove checksum and old client
Browse files Browse the repository at this point in the history
Merge pull request #50 from DSD-DBS/refactoring-collection
  • Loading branch information
ewuerger authored Oct 16, 2024
2 parents e32a027 + 0973601 commit 950861f
Show file tree
Hide file tree
Showing 18 changed files with 299 additions and 806 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
python -m pip install -U pip
- name: Install pre-commit
run: |-
python -m pip install pre-commit types-docutils
python -m pip install 'pre-commit>=3,<4' types-docutils
- name: Run Pre-Commit
run: |-
pre-commit run --all-files
Expand Down
1 change: 0 additions & 1 deletion polarion_rest_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
from polarion_rest_api_client.clients.projects import ProjectClient
from polarion_rest_api_client.data_models import *
from polarion_rest_api_client.errors import *
from polarion_rest_api_client.old_client import OpenAPIPolarionProjectClient
5 changes: 1 addition & 4 deletions polarion_rest_api_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ def generate_project_client(
self,
project_id: str,
delete_status: str | None = None,
add_work_item_checksum: bool = False,
):
"""Return a client for a specific project."""
return projects.ProjectClient(
project_id, self, delete_status, add_work_item_checksum
)
return projects.ProjectClient(project_id, self, delete_status)
3 changes: 1 addition & 2 deletions polarion_rest_api_client/clients/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ def __init__(
project_id: str,
client: "polarion_client.PolarionClient",
delete_status: str | None = None,
add_work_item_checksum: bool = False,
):
super().__init__(project_id, client)

self.work_items = work_items.WorkItems(
project_id, client, delete_status, add_work_item_checksum
project_id, client, delete_status
)
self.test_runs = test_runs.TestRuns(project_id, client)
self.documents = documents.Documents(project_id, client)
Expand Down
8 changes: 8 additions & 0 deletions polarion_rest_api_client/clients/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ def _create(self, items: list[dm.TestRun]):
)

self._raise_on_error(response)
assert (
isinstance(response.parsed, api_models.TestrunsListPostResponse)
and response.parsed.data
)
if response.parsed and response.parsed.data:
for i, data in enumerate(response.parsed.data):
assert data.id
items[i].id = data.id.split("/")[-1]

def _delete(self, items: dm.TestRun | list[dm.TestRun]):
raise NotImplementedError
Expand Down
56 changes: 20 additions & 36 deletions polarion_rest_api_client/clients/work_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ def __init__(
project_id: str,
client: "polarion_client.PolarionClient",
delete_status: str | None = None,
add_work_item_checksum: bool = False,
):
super().__init__(project_id, client, delete_status)
self.attachments = work_item_attachments.WorkItemAttachments(
project_id, client
)
self.links = work_item_links.WorkItemLinks(project_id, client)
self.add_work_item_checksum = add_work_item_checksum

def _update(self, to_update: list[dm.WorkItem] | dm.WorkItem):
assert not isinstance(to_update, list), "Expected only one item"
Expand Down Expand Up @@ -312,21 +310,16 @@ def _build_work_item_post_request(
type=work_item.type,
description=api_models.WorkitemsListPostRequestDataItemAttributesDescription( # pylint: disable=line-too-long
type=api_models.WorkitemsListPostRequestDataItemAttributesDescriptionType( # pylint: disable=line-too-long
work_item.description_type
work_item.description.type
),
value=work_item.description,
value=work_item.description.value or oa_types.UNSET,
),
status=work_item.status,
title=work_item.title,
)

attrs.additional_properties.update(work_item.additional_attributes)

if self.add_work_item_checksum:
attrs.additional_properties["checksum"] = (
work_item.calculate_checksum()
)

return api_models.WorkitemsListPostRequestDataItem(
type=api_models.WorkitemsListPostRequestDataItemType.WORKITEMS,
attributes=attrs,
Expand Down Expand Up @@ -361,21 +354,16 @@ def _build_work_item_patch_request(
if work_item.description is not None:
attrs.description = api_models.WorkitemsSinglePatchRequestDataAttributesDescription( # pylint: disable=line-too-long
type=api_models.WorkitemsSinglePatchRequestDataAttributesDescriptionType( # pylint: disable=line-too-long
work_item.description_type
work_item.description.type
),
value=work_item.description,
value=work_item.description.value or oa_types.UNSET,
)

if work_item.status is not None:
attrs.status = work_item.status

attrs.additional_properties.update(work_item.additional_attributes)

if self.add_work_item_checksum:
attrs.additional_properties["checksum"] = (
work_item.get_current_checksum()
)

return api_models.WorkitemsSinglePatchRequest(
data=api_models.WorkitemsSinglePatchRequestData(
type=api_models.WorkitemsSinglePatchRequestDataType.WORKITEMS,
Expand All @@ -399,11 +387,9 @@ def _post_work_item_batch(
isinstance(response.parsed, api_models.WorkitemsListPostResponse)
and response.parsed.data
)
counter = 0
for work_item_res in response.parsed.data:
for index, work_item_res in enumerate(response.parsed.data):
assert work_item_res.id
work_item_objs[counter].id = work_item_res.id.split("/")[-1]
counter += 1
work_item_objs[index].id = work_item_res.id.split("/")[-1]

def _calculate_post_work_item_request_sizes(
self,
Expand Down Expand Up @@ -480,25 +466,23 @@ def _generate_work_item(
if attachment.id
]

desc_type = None
desc = None
description = None
if work_item.attributes.description:
desc_type = self.unset_to_none(
work_item.attributes.description.type
description = dm.TextContent(
self.unset_to_none(work_item.attributes.description.type),
self.unset_to_none(work_item.attributes.description.value),
)
desc = self.unset_to_none(work_item.attributes.description.value)

return work_item_cls(
work_item_id,
self.unset_to_none(work_item.attributes.title),
desc_type,
desc,
self.unset_to_none(work_item.attributes.type),
self.unset_to_none(work_item.attributes.status),
work_item.attributes.additional_properties,
links,
attachments,
links_truncated,
attachments_truncated,
home_document,
title=self.unset_to_none(work_item.attributes.title),
description=description,
type=self.unset_to_none(work_item.attributes.type),
status=self.unset_to_none(work_item.attributes.status),
additional_attributes=work_item.attributes.additional_properties,
linked_work_items=links,
attachments=attachments,
linked_work_items_truncated=links_truncated,
attachments_truncated=attachments_truncated,
home_document=home_document,
)
Loading

0 comments on commit 950861f

Please sign in to comment.