Skip to content

Commit 3708e32

Browse files
committed
Add TextContent Class
1 parent 2622e9c commit 3708e32

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

polarion_rest_api_client/base_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from polarion_rest_api_client import data_models as dm
1010

1111
WorkItemType = t.TypeVar("WorkItemType", bound=dm.WorkItem)
12-
DocumentType = t.TypeVar("DocumentType", bound=dm.Document)
1312

1413

1514
class DefaultFields:

polarion_rest_api_client/client.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -687,24 +687,47 @@ def get_document(
687687
if not getattr(data.meta, "errors", []):
688688
assert (attributes := data.attributes)
689689
assert isinstance(data.id, str)
690+
home_page_content = self._handle_home_page_content(
691+
attributes.home_page_content
692+
)
690693

691694
document: dm.Document = dm.Document(
692695
id=data.id,
693696
module_folder=unset_str_builder(attributes.module_folder),
694697
module_name=unset_str_builder(attributes.module_name),
695698
type=unset_str_builder(attributes.type),
696699
status=unset_str_builder(attributes.status),
697-
home_page_content={
698-
"type": attributes.home_page_content.type,
699-
"value": attributes.home_page_content.value,
700-
}
701-
if not isinstance(
702-
attributes.home_page_content, oa_types.Unset
703-
)
704-
else None,
700+
home_page_content=home_page_content,
705701
)
706702
return document
707703

704+
def _handle_home_page_content(self, home_page_content):
705+
home_page_content_type = None
706+
home_page_content_value = None
707+
708+
if not isinstance(home_page_content, oa_types.Unset):
709+
if isinstance(
710+
home_page_content.type,
711+
api_models.DocumentsSingleGetResponseDataAttributesHomePageContentType,
712+
):
713+
home_page_content_type = str(home_page_content.type)
714+
elif isinstance(home_page_content.type, oa_types.Unset):
715+
home_page_content_type = None
716+
717+
if isinstance(home_page_content.value, str):
718+
home_page_content_value = home_page_content.value
719+
elif isinstance(home_page_content.value, oa_types.Unset):
720+
home_page_content_value = None
721+
722+
home_page_content = dm.TextContent(
723+
type=home_page_content_type,
724+
value=home_page_content_value,
725+
)
726+
else:
727+
home_page_content = None
728+
729+
return home_page_content
730+
708731
def create_work_items(self, work_items: list[base_client.WorkItemType]):
709732
"""Create the given list of work items."""
710733
current_batch = api_models.WorkitemsListPostRequest([])

polarion_rest_api_client/data_models.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Document(BaseItem):
147147

148148
module_folder: str | None = None
149149
module_name: str | None = None
150-
home_page_content: dict | None = None
150+
home_page_content: TextContent | None = None
151151

152152
def __init__(
153153
self,
@@ -156,9 +156,24 @@ def __init__(
156156
module_name: str | None = None,
157157
type: str | None = None,
158158
status: str | None = None,
159-
home_page_content: dict | None = None,
159+
home_page_content: TextContent | None = None,
160160
):
161161
super().__init__(id, type, status)
162162
self.module_folder = module_folder
163163
self.module_name = module_name
164164
self.home_page_content = home_page_content
165+
166+
167+
class TextContent:
168+
"""A data class for home_page_content of a Polarion Document."""
169+
170+
type: str | None = None
171+
value: str | None = None
172+
173+
def __init__(
174+
self,
175+
type: str | None = None,
176+
value: str | None = None,
177+
):
178+
self.type = type
179+
self.value = value

tests/test_client_documents.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ def test_get_document_with_all_fields(
3333
"MyDocumentName",
3434
"standardSpecification",
3535
"open",
36-
{"type": "text/html", "value": "<h1>My text value</h1>"},
36+
polarion_api.data_models.TextContent(
37+
type="text/html", value="<h1>My text value</h1>"
38+
),
3739
)

0 commit comments

Comments
 (0)