From 89f38e11c98a93125a324a8ecbc2c844cc20adad Mon Sep 17 00:00:00 2001 From: Michael Harbarth Date: Wed, 17 Jan 2024 10:42:20 +0100 Subject: [PATCH] feat: Add basic context-diagrams as custom fields --- .../converters/element_converter.py | 12 +++++++++ tests/test_elements.py | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/capella2polarion/converters/element_converter.py b/capella2polarion/converters/element_converter.py index 309c34d8..d480c6ab 100644 --- a/capella2polarion/converters/element_converter.py +++ b/capella2polarion/converters/element_converter.py @@ -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 diff --git a/tests/test_elements.py b/tests/test_elements.py index 69e9cb88..5bc08eb1 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -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('