Skip to content

Commit

Permalink
feat: support json serialization for TextContent to make use of TextC…
Browse files Browse the repository at this point in the history
…ontent in additional attributes
  • Loading branch information
micha91 committed Aug 22, 2024
1 parent 52da46b commit adb2dc5
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions polarion_rest_api_client/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def __init__(
stacklevel=2,
)

assert not isinstance(
description, TextContent
), "Don't use description_type when setting description as TextContent"
assert not isinstance(description, TextContent), (
"Don't use description_type when setting description as "
"TextContent"
)
description = TextContent(description_type, description)
self.description = description
self.additional_attributes = (additional_attributes or {}) | kwargs
Expand Down Expand Up @@ -300,12 +301,29 @@ class TestRecord:
)


@dataclasses.dataclass
class TextContent:
class TextContent(dict):
"""A data class for text content in Polarion."""

type: str | None = None
value: str | None = None
def __init__(self, type: str | None, value: str | None):
super().__init__(type=type, value=value)

@property
def type(self):
"""Return type of the TextContent."""
return self["type"]

@type.setter
def type(self, type: str):
self["type"] = type

@property
def value(self):
"""Return value of the TextContent."""
return self["value"]

@value.setter
def value(self, value: str):
self["value"] = value


class HtmlContent(TextContent):
Expand Down

0 comments on commit adb2dc5

Please sign in to comment.