Skip to content

Commit

Permalink
feat: Add basic context-diagrams as custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
micha91 authored and ewuerger committed Jan 17, 2024
1 parent 1409b80 commit 89f38e1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions capella2polarion/converters/element_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,15 @@ def _linked_text_as_description(
# pylint: disable-next=attribute-defined-outside-init
work_item.description = self._get_linked_text(converter_data)
return work_item

def _add_context_diagram(
self, converter_data: data_session.ConverterData
) -> data_models.CapellaWorkItem:
"""Add a new custom field context diagram."""
work_item = self._generic_work_item(converter_data)
diagram = converter_data.capella_element.context_diagram
work_item.additional_attributes["context_diagram"] = {
"type": "text/html",
"value": diagram.as_html_img,
}
return work_item
26 changes: 26 additions & 0 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,3 +1184,29 @@ def test_generic_work_item(

assert work_item == data_models.CapellaWorkItem(**expected)
assert status == "open"

def test_add_context_diagram(self, model: capellambse.MelodyModel):
uuid = "11906f7b-3ae9-4343-b998-95b170be2e2b"
type_config = converter_config.CapellaTypeConfig(
"test", "add_context_diagram", []
)
serializer = element_converter.CapellaWorkItemSerializer(
pathlib.Path(""),
model,
polarion_repo.PolarionDataRepository(),
{
uuid: data_session.ConverterData(
"pa",
type_config,
model.by_uuid(uuid),
)
},
)

work_item = serializer.serialize(uuid)

assert work_item is not None
assert "context_diagram" in work_item.additional_attributes
assert str(
work_item.additional_attributes["context_diagram"]["value"]
).startswith('<img src="data:image/svg+xml;base64,')

0 comments on commit 89f38e1

Please sign in to comment.