From effaef4067fd2904b8922e064851892b5029967d Mon Sep 17 00:00:00 2001 From: ewuerger Date: Thu, 21 Nov 2024 13:49:42 +0100 Subject: [PATCH] test: Test serialization --- tests/data/model/Melody Model Test.capella | 2 +- tests/test_elements.py | 581 ++++++++------------- 2 files changed, 215 insertions(+), 368 deletions(-) diff --git a/tests/data/model/Melody Model Test.capella b/tests/data/model/Melody Model Test.capella index 7ea8f5e2..b7764ceb 100644 --- a/tests/data/model/Melody Model Test.capella +++ b/tests/data/model/Melody Model Test.capella @@ -56,7 +56,7 @@ diff --git a/tests/test_elements.py b/tests/test_elements.py index ea9e294c..5c918102 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -79,16 +79,22 @@ "This is a list\n\t
  • an unordered one
  • \n\n\n
      \n\t" "
    1. Ordered list
    2. \n\t
    3. Ok
    4. \n
    \n" ) +TEST_REQ_TEXT_1 = ( + "

    Test requirement 1 really l o n g text that is\xa0way too long to " + 'display here as that\xa0

    \n\n

    < > " \'

    \n\n
      \n\t' + "
    • This\xa0is a list
    • \n\t
    • an unordered one
    • \n
    \n\n
      " + "\n\t
    1. Ordered list
    2. \n\t
    3. Ok
    4. \n
    \n\n
    " + '
    \n' +) POLARION_ID_MAP = {f"uuid{i}": f"Obj-{i}" for i in range(3)} TEST_LOGICAL_COMPONENT = { "type": "logicalComponent", "title": "Hogwarts", "description": polarion_api.HtmlContent(markupsafe.Markup(TEST_DESCR)), } -TEST_CONDITION = { - "type": "text/html", - "value": '
    ', -} TEST_OPERATIONAL_CAPABILITY = { "type": "operationalCapability", "title": "Stay alive", @@ -173,9 +179,7 @@ def grouped_links_base_object( base_object: BaseObjectContainer, dummy_work_items: dict[str, data_model.CapellaWorkItem], ) -> GroupedLinksBaseObject: - config = converter_config.CapellaTypeConfig( - "fakeModelObject", links=[LINK_CONFIG] - ) + config = converter_config.CapellaTypeConfig("fakeModelObject", links=[LINK_CONFIG]) mock_model = mock.MagicMock() fake_2 = FakeModelObject("uuid2", "Fake 2") fake_1 = FakeModelObject("uuid1", "Fake 1") @@ -218,8 +222,8 @@ def diagr_base_object( ) } - base_object.pw.polarion_data_repo = ( - polarion_repo.PolarionDataRepository([work_item]) + base_object.pw.polarion_data_repo = polarion_repo.PolarionDataRepository( + [work_item] ) return base_object @@ -254,10 +258,7 @@ def test_delete_diagrams(diagr_base_object: BaseObjectContainer): pw.delete_orphaned_work_items(diagr_base_object.mc.converter_session) assert pw.project_client is not None assert pw.project_client.work_items.delete.call_count == 1 - assert ( - pw.project_client.work_items.delete.call_args[0][0][0].id - == "Diag-1" - ) + assert pw.project_client.work_items.delete.call_args[0][0][0].id == "Diag-1" assert pw.project_client.work_items.create.call_count == 0 @@ -313,9 +314,7 @@ def test_create_work_items_with_special_polarion_type( base_object.mc.converter_session = { uuid: data_session.ConverterData( "oa", - converter_config.CapellaTypeConfig( - _type[0].lower() + _type[1:] - ), + converter_config.CapellaTypeConfig(_type[0].lower() + _type[1:]), model.by_uuid(uuid), ) } @@ -353,9 +352,7 @@ def test_create_links_custom_resolver(base_object: BaseObjectContainer): polarion_role="description_reference", ) ] - base_object.mc.converter_session["uuid2"].description_references = [ - "uuid1" - ] + base_object.mc.converter_session["uuid2"].description_references = ["uuid1"] expected = polarion_api.WorkItemLink( "Obj-2", "Obj-1", @@ -404,15 +401,13 @@ def test_create_links_custom_exchanges_resolver( link_config = converter_config.LinkConfig( capella_attr="inputs.exchanges", polarion_role="input_exchanges" ) - base_object.mc.converter_session[function_uuid] = ( - data_session.ConverterData( - "fa", - converter_config.CapellaTypeConfig( - type(funtion_obj).__name__, links=[link_config] - ), - funtion_obj, - work_item_obj_1, - ) + base_object.mc.converter_session[function_uuid] = data_session.ConverterData( + "fa", + converter_config.CapellaTypeConfig( + type(funtion_obj).__name__, links=[link_config] + ), + funtion_obj, + work_item_obj_1, ) base_object.mc.converter_session[uuid] = data_session.ConverterData( "fa", @@ -449,9 +444,7 @@ def test_create_links_logs_error_when_no_uuid_is_found_on_value( ) no_uuid = FakeModelObject("") del no_uuid.uuid - base_object.mc.converter_session["uuid1"].capella_element.attribute = ( - no_uuid - ) + base_object.mc.converter_session["uuid1"].capella_element.attribute = no_uuid with caplog.at_level(logging.ERROR): link_serializer = link_converter.LinkSerializer( @@ -577,9 +570,7 @@ def test_create_links_with_new_links_and_errors( polarion_role="invalid_role", ), ] - base_object.mc.converter_session["uuid2"].description_references = [ - "uuid1" - ] + base_object.mc.converter_session["uuid2"].description_references = ["uuid1"] base_object.mc.converter_session["uuid2"].errors = set() expected_link = polarion_api.WorkItemLink( @@ -748,9 +739,7 @@ def test_update_work_items( uuid_capella="uuid1", status="open", title="Something", - description=polarion_api.HtmlContent( - markupsafe.Markup("Test") - ), + description=polarion_api.HtmlContent(markupsafe.Markup("Test")), ) ] polarion_api_get_all_work_items = mock.MagicMock() @@ -763,14 +752,14 @@ def test_update_work_items( base_object.pw.load_polarion_work_item_map() - base_object.mc.converter_session["uuid1"].work_item = ( - data_model.CapellaWorkItem( - id="Obj-1", - uuid_capella="uuid1", - title="Fake 1", - type="type", - description=polarion_api.HtmlContent(markupsafe.Markup("")), - ) + base_object.mc.converter_session[ + "uuid1" + ].work_item = data_model.CapellaWorkItem( + id="Obj-1", + uuid_capella="uuid1", + title="Fake 1", + type="type", + description=polarion_api.HtmlContent(markupsafe.Markup("")), ) del base_object.mc.converter_session["uuid2"] @@ -783,30 +772,17 @@ def test_update_work_items( get_work_item_mock, ) - base_object.pw.compare_and_update_work_items( - base_object.mc.converter_session - ) - assert ( - base_object.pw.project_client.work_items.links.get_all.call_count - == 0 - ) - assert ( - base_object.pw.project_client.work_items.links.delete.call_count - == 0 - ) - assert ( - base_object.pw.project_client.work_items.links.create.call_count - == 0 - ) + base_object.pw.compare_and_update_work_items(base_object.mc.converter_session) + assert base_object.pw.project_client.work_items.links.get_all.call_count == 0 + assert base_object.pw.project_client.work_items.links.delete.call_count == 0 + assert base_object.pw.project_client.work_items.links.create.call_count == 0 assert base_object.pw.project_client.work_items.update.call_count == 1 assert base_object.pw.project_client.work_items.get.call_count == 1 assert ( base_object.pw.project_client.work_items.attachments.get_all.call_count # pylint: disable=line-too-long == 0 ) - work_item = base_object.pw.project_client.work_items.update.call_args[ - 0 - ][0] + work_item = base_object.pw.project_client.work_items.update.call_args[0][0] assert isinstance(work_item, data_model.CapellaWorkItem) assert work_item.id == "Obj-1" assert work_item.title == "Fake 1" @@ -839,17 +815,15 @@ def test_update_deleted_work_item( base_object.pw.load_polarion_work_item_map() - base_object.mc.converter_session["uuid1"].work_item = ( - data_model.CapellaWorkItem( - id="Obj-1", - type="type", - uuid_capella="uuid1", - status="open", - title="Something", - description=polarion_api.HtmlContent( - markupsafe.Markup("Test") - ), - ) + base_object.mc.converter_session[ + "uuid1" + ].work_item = data_model.CapellaWorkItem( + id="Obj-1", + type="type", + uuid_capella="uuid1", + status="open", + title="Something", + description=polarion_api.HtmlContent(markupsafe.Markup("Test")), ) del base_object.mc.converter_session["uuid2"] @@ -861,22 +835,14 @@ def test_update_deleted_work_item( "get", get_work_item_mock, ) - base_object.pw.delete_orphaned_work_items( - base_object.mc.converter_session - ) + base_object.pw.delete_orphaned_work_items(base_object.mc.converter_session) assert base_object.pw.project_client.work_items.update.called is False - base_object.pw.create_missing_work_items( - base_object.mc.converter_session - ) + base_object.pw.create_missing_work_items(base_object.mc.converter_session) assert base_object.pw.project_client.work_items.create.called is False - base_object.pw.compare_and_update_work_items( - base_object.mc.converter_session - ) - work_item = base_object.pw.project_client.work_items.update.call_args[ - 0 - ][0] + base_object.pw.compare_and_update_work_items(base_object.mc.converter_session) + work_item = base_object.pw.project_client.work_items.update.call_args[0][0] assert isinstance(work_item, data_model.CapellaWorkItem) assert work_item.status == "open" @@ -896,13 +862,9 @@ def test_create_new_work_item(base_object: BaseObjectContainer): ) base_object.pw.load_polarion_work_item_map() - base_object.pw.create_missing_work_items( - base_object.mc.converter_session - ) + base_object.pw.create_missing_work_items(base_object.mc.converter_session) - polarion_api_create_work_items = ( - base_object.pw.project_client.work_items.create - ) + polarion_api_create_work_items = base_object.pw.project_client.work_items.create assert polarion_api_create_work_items.call_count == 1 assert len(polarion_api_create_work_items.call_args[0][0]) == 1 @@ -911,9 +873,7 @@ def test_create_new_work_item(base_object: BaseObjectContainer): assert work_item.id == "AUTO-0" assert len(base_object.pw.polarion_data_repo) == 2 assert ( - base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid( - "uuid2" - ).id + base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid("uuid2").id == "AUTO-0" ) @@ -935,9 +895,7 @@ def test_update_work_items_filters_work_items_with_same_checksum( del base_object.mc.converter_session["uuid2"] - base_object.pw.compare_and_update_work_items( - base_object.mc.converter_session - ) + base_object.pw.compare_and_update_work_items(base_object.mc.converter_session) assert base_object.pw.project_client.work_items.update.call_count == 0 @@ -960,36 +918,25 @@ def test_update_work_items_same_checksum_force( del base_object.mc.converter_session["uuid2"] - base_object.pw.compare_and_update_work_items( - base_object.mc.converter_session - ) + base_object.pw.compare_and_update_work_items(base_object.mc.converter_session) assert base_object.pw.project_client.work_items.update.call_count == 1 @staticmethod def test_update_links_with_no_elements(base_object: BaseObjectContainer): - base_object.pw.polarion_data_repo = ( - polarion_repo.PolarionDataRepository() - ) + base_object.pw.polarion_data_repo = polarion_repo.PolarionDataRepository() base_object.mc.converter_session = {} - base_object.pw.compare_and_update_work_items( - base_object.mc.converter_session - ) + base_object.pw.compare_and_update_work_items(base_object.mc.converter_session) - assert ( - base_object.pw.project_client.work_items.links.get_all.call_count - == 0 - ) + assert base_object.pw.project_client.work_items.links.get_all.call_count == 0 @staticmethod def test_update_links(base_object: BaseObjectContainer): link = polarion_api.WorkItemLink( "Obj-1", "Obj-2", "attribute", True, "project_id" ) - work_item = ( - base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid( - "uuid1" - ) + work_item = base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid( + "uuid1" ) work_item.linked_work_items = [link] base_object.pw.polarion_data_repo.update_work_items( @@ -1002,13 +949,13 @@ def test_update_links(base_object: BaseObjectContainer): ) ] ) - base_object.mc.converter_session["uuid2"].work_item = ( - data_model.CapellaWorkItem( - id="Obj-2", - uuid_capella="uuid2", - status="open", - type="fakeModelObject", - ) + base_object.mc.converter_session[ + "uuid2" + ].work_item = data_model.CapellaWorkItem( + id="Obj-2", + uuid_capella="uuid2", + status="open", + type="fakeModelObject", ) for data in base_object.mc.converter_session.values(): data.type_config.links[0].polarion_role = "attribute" @@ -1025,15 +972,11 @@ def test_update_links(base_object: BaseObjectContainer): generate_grouped_links_custom_fields=True, ) - work_item_1 = ( - base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid( - "uuid1" - ) + work_item_1 = base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid( + "uuid1" ) - work_item_2 = ( - base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid( - "uuid2" - ) + work_item_2 = base_object.pw.polarion_data_repo.get_work_item_by_capella_uuid( + "uuid2" ) work_item_1.linked_work_items_truncated = True work_item_2.linked_work_items_truncated = True @@ -1043,34 +986,21 @@ def test_update_links(base_object: BaseObjectContainer): work_item_2, ) - base_object.pw.compare_and_update_work_items( - base_object.mc.converter_session - ) + base_object.pw.compare_and_update_work_items(base_object.mc.converter_session) links = ( base_object.pw.project_client.work_items.links.get_all.call_args_list # pylint: disable=line-too-long ) - assert ( - base_object.pw.project_client.work_items.links.get_all.call_count - == 2 - ) + assert base_object.pw.project_client.work_items.links.get_all.call_count == 2 assert [links[0][0][0], links[1][0][0]] == ["Obj-1", "Obj-2"] - new_links = ( - base_object.pw.project_client.work_items.links.create.call_args[0][ - 0 - ] - ) - assert ( - base_object.pw.project_client.work_items.links.create.call_count - == 1 - ) + new_links = base_object.pw.project_client.work_items.links.create.call_args[0][ + 0 + ] + assert base_object.pw.project_client.work_items.links.create.call_count == 1 assert new_links == [expected_new_link] - assert ( - base_object.pw.project_client.work_items.links.delete.call_count - == 1 - ) - assert base_object.pw.project_client.work_items.links.delete.call_args[ + assert base_object.pw.project_client.work_items.links.delete.call_count == 1 + assert base_object.pw.project_client.work_items.links.delete.call_args[0][ 0 - ][0] == [link] + ] == [link] @staticmethod def test_patch_work_item_grouped_links( @@ -1087,20 +1017,18 @@ def test_patch_work_item_grouped_links( ) for work_item in dummy_work_items.values() } - base_object.pw.polarion_data_repo = ( - polarion_repo.PolarionDataRepository( - [ - data_model.CapellaWorkItem( - id="Obj-0", uuid_capella="uuid0", status="open" - ), - data_model.CapellaWorkItem( - id="Obj-1", uuid_capella="uuid1", status="open" - ), - data_model.CapellaWorkItem( - id="Obj-2", uuid_capella="uuid2", status="open" - ), - ] - ) + base_object.pw.polarion_data_repo = polarion_repo.PolarionDataRepository( + [ + data_model.CapellaWorkItem( + id="Obj-0", uuid_capella="uuid0", status="open" + ), + data_model.CapellaWorkItem( + id="Obj-1", uuid_capella="uuid1", status="open" + ), + data_model.CapellaWorkItem( + id="Obj-2", uuid_capella="uuid2", status="open" + ), + ] ) mock_create_links = mock.MagicMock() monkeypatch.setattr( @@ -1142,9 +1070,7 @@ def mock_back_link(converter_data, back_links): base_object.pw.polarion_data_repo, generate_grouped_links_custom_fields=True, ) - base_object.pw.compare_and_update_work_items( - base_object.mc.converter_session - ) + base_object.pw.compare_and_update_work_items(base_object.mc.converter_session) update_work_item_calls = ( base_object.pw.project_client.work_items.update.call_args_list ) @@ -1152,18 +1078,9 @@ def mock_back_link(converter_data, back_links): mock_grouped_links_calls = mock_grouped_links.call_args_list assert len(mock_grouped_links_calls) == 3 assert mock_grouped_links_reverse.call_count == 3 - assert ( - mock_grouped_links_calls[0][0][0].work_item - == dummy_work_items["uuid0"] - ) - assert ( - mock_grouped_links_calls[1][0][0].work_item - == dummy_work_items["uuid1"] - ) - assert ( - mock_grouped_links_calls[2][0][0].work_item - == dummy_work_items["uuid2"] - ) + assert mock_grouped_links_calls[0][0][0].work_item == dummy_work_items["uuid0"] + assert mock_grouped_links_calls[1][0][0].work_item == dummy_work_items["uuid1"] + assert mock_grouped_links_calls[2][0][0].work_item == dummy_work_items["uuid2"] work_item_0 = update_work_item_calls[0][0][0] del work_item_0.additional_attributes["checksum"] work_item_1 = update_work_item_calls[1][0][0] @@ -1207,9 +1124,7 @@ def test_maintain_grouped_links_attributes( mock_model, ) for work_item in dummy_work_items.values(): - converter_data = data_session.ConverterData( - "test", config, [], work_item - ) + converter_data = data_session.ConverterData("test", config, [], work_item) link_serializer._link_field_groups["attribute"] = ( work_item.linked_work_items ) @@ -1219,15 +1134,11 @@ def test_maintain_grouped_links_attributes( del dummy_work_items["uuid2"].additional_attributes["uuid_capella"] assert ( - dummy_work_items["uuid0"].additional_attributes.pop("attribute")[ - "value" - ] + dummy_work_items["uuid0"].additional_attributes.pop("attribute")["value"] == HTML_LINK_0["attribute"] ) assert ( - dummy_work_items["uuid1"].additional_attributes.pop("attribute")[ - "value" - ] + dummy_work_items["uuid1"].additional_attributes.pop("attribute")["value"] == HTML_LINK_1["attribute"] ) assert dummy_work_items["uuid0"].additional_attributes == {} @@ -1270,9 +1181,7 @@ def test_maintain_grouped_links_attributes_with_role_prefix( ) for work_item in dummy_work_items.values(): - converter_data = data_session.ConverterData( - "test", config, [], work_item - ) + converter_data = data_session.ConverterData("test", config, [], work_item) if work_item.uuid_capella == "uuid0": link_serializer._link_field_groups["attribute"] = ( work_item.linked_work_items @@ -1306,12 +1215,8 @@ def test_grouped_links_attributes_different_link_field_in_config( reverse_field="attribute1_reverse", ) ) - converter_data_1.capella_element.attribute = ( - converter_data_2.capella_element - ) - converter_data_1.capella_element.attribute1 = ( - converter_data_2.capella_element - ) + converter_data_1.capella_element.attribute = converter_data_2.capella_element + converter_data_1.capella_element.attribute1 = converter_data_2.capella_element expected_html = ( "
    • " 'hehe' - "
      " + '
      hehe' "
      " ), }, - "postCondition": { - "type": "text/html", - "value": '
      ', - }, + "postCondition": {"type": "text/html", "value": ""}, }, }, id="scenario", @@ -1752,18 +1597,10 @@ def test_diagram(model: capellambse.MelodyModel): "type": "capabilityRealization", "title": "Capability Realization", "uuid_capella": TEST_CAP_REAL, - "description": polarion_api.HtmlContent( - markupsafe.Markup("") - ), + "description": polarion_api.HtmlContent(markupsafe.Markup("")), "additional_attributes": { - "preCondition": { - "type": "text/html", - "value": '
      ', - }, - "postCondition": { - "type": "text/html", - "value": '
      ', - }, + "preCondition": {"type": "text/html", "value": ""}, + "postCondition": {"type": "text/html", "value": ""}, }, }, id="capabilityRealization", @@ -1805,19 +1642,9 @@ def test_generic_work_item( serializer = element_converter.CapellaWorkItemSerializer( model, polarion_repo.PolarionDataRepository( - [ - data_model.CapellaWorkItem( - id="TEST", uuid_capella=TEST_E_UUID - ) - ] + [data_model.CapellaWorkItem(id="TEST", uuid_capella=TEST_E_UUID)] ), - { - uuid: data_session.ConverterData( - layer, - type_config, - obj, - ) - }, + {uuid: data_session.ConverterData(layer, type_config, obj)}, False, ) @@ -1829,6 +1656,49 @@ def test_generic_work_item( assert work_item == data_model.CapellaWorkItem(**expected) assert status == "open" + @staticmethod + def test_add_requirements_text_grouped_by_type( + model: capellambse.MelodyModel, + ): + expected = { + **TEST_LOGICAL_COMPONENT, + "uuid_capella": TEST_ELEMENT_UUID, + "reqtype": { + "type": "text/html", + "value": markupsafe.Markup(TEST_REQ_TEXT_1), + }, + } + obj = model.by_uuid(TEST_ELEMENT_UUID) + type_config = converter_config.CapellaTypeConfig( + "logicalComponent", + "add_requirements_text_grouped_by_type", + ) + session = { + TEST_ELEMENT_UUID: data_session.ConverterData("sa", type_config, obj) + } + work_items = [ + data_model.CapellaWorkItem( + id="TEST", uuid_capella="ceffa011-7b66-4b3c-9885-8e075e312ffa" + ), + data_model.CapellaWorkItem( + id="TEST1", uuid_capella="00e7b925-cf4c-4cb0-929e-5409a1cd872b" + ), + ] + serializer = element_converter.CapellaWorkItemSerializer( + model, + polarion_repo.PolarionDataRepository(work_items), + session, + False, + ) + + work_item = serializer.serialize(TEST_ELEMENT_UUID) + assert work_item is not None + status = work_item.status + work_item.status = None + + assert work_item == data_model.CapellaWorkItem(**expected) + assert status == "open" + @staticmethod def test_add_context_diagram(model: capellambse.MelodyModel): uuid = "11906f7b-3ae9-4343-b998-95b170be2e2b" @@ -1889,9 +1759,7 @@ def test_add_context_diagram_with_params( uuid = "00e7b925-cf4c-4cb0-929e-5409a1cd872b" fnc = model.by_uuid(uuid) config = {"add_context_diagram": {"filters": [context_diagram_filter]}} - type_config = converter_config.CapellaTypeConfig( - "systemFunction", config, [] - ) + type_config = converter_config.CapellaTypeConfig("systemFunction", config, []) expected_filter = getattr(filters, context_diagram_filter) monkeypatch.setattr( element_converter.CapellaWorkItemSerializer, @@ -1917,23 +1785,15 @@ def test_add_tree_view_with_params( ): cls = model.by_uuid("c710f1c2-ede6-444e-9e2b-0ff30d7fd040") config = {"add_tree_diagram": {"render_params": {"depth": 1}}} - type_config = converter_config.CapellaTypeConfig( - "systemFunction", config, [] - ) + type_config = converter_config.CapellaTypeConfig("systemFunction", config, []) serializer = element_converter.CapellaWorkItemSerializer( model, polarion_repo.PolarionDataRepository(), - { - TEST_OCAP_UUID: data_session.ConverterData( - "pa", type_config, cls - ) - }, + {TEST_OCAP_UUID: data_session.ConverterData("pa", type_config, cls)}, True, ) - with mock.patch.object( - context.ContextDiagram, "render" - ) as wrapped_render: + with mock.patch.object(context.ContextDiagram, "render") as wrapped_render: wis = serializer.serialize_all() _ = wis[0].attachments[0].content_bytes @@ -1981,11 +1841,7 @@ def test_multiple_serializers(model: capellambse.MelodyModel, prefix: str): serializer = element_converter.CapellaWorkItemSerializer( model, polarion_repo.PolarionDataRepository(), - { - TEST_OCAP_UUID: data_session.ConverterData( - "pa", type_config, cap - ) - }, + {TEST_OCAP_UUID: data_session.ConverterData("pa", type_config, cap)}, True, ) @@ -2010,20 +1866,6 @@ def test_multiple_serializers(model: capellambse.MelodyModel, prefix: str): @pytest.mark.parametrize( "layer,uuid,expected", [ - pytest.param( - "la", - TEST_ELEMENT_UUID, - { - **TEST_LOGICAL_COMPONENT, - "type": "_C2P_logicalComponent", - "uuid_capella": TEST_ELEMENT_UUID, - "reqtype": { - "type": "text/html", - "value": markupsafe.Markup(TEST_REQ_TEXT), - }, - }, - id="logicalComponent", - ), pytest.param( "oa", TEST_OCAP_UUID, @@ -2032,12 +1874,25 @@ def test_multiple_serializers(model: capellambse.MelodyModel, prefix: str): "type": "_C2P_operationalCapability", "uuid_capella": TEST_OCAP_UUID, "additional_attributes": { - "preCondition": TEST_CONDITION, - "postCondition": TEST_CONDITION, + "preCondition": {"type": "text/html", "value": ""}, + "postCondition": {"type": "text/html", "value": ""}, }, }, id="operationalCapability", ), + pytest.param( + "oa", + TEST_WE_UUID, + { + "type": "_C2P_entity", + "title": "Environment", + "uuid_capella": TEST_WE_UUID, + "description": polarion_api.HtmlContent( + markupsafe.Markup(TEST_WE_DESCR.replace("TEST", "_C2P_TEST")) + ), + }, + id="entity", + ), ], ) def test_generic_work_item_with_type_prefix( @@ -2060,7 +1915,9 @@ def test_generic_work_item_with_type_prefix( type_config = config.get_type_config(layer, c_type, **attributes) assert type_config is not None type_config.p_type = f"{prefix}_{type_config.p_type}" - ework_item = data_model.CapellaWorkItem(id=f"{prefix}_TEST") + ework_item = data_model.CapellaWorkItem( + id=f"{prefix}_TEST", uuid_capella=TEST_E_UUID + ) serializer = element_converter.CapellaWorkItemSerializer( model, polarion_repo.PolarionDataRepository([ework_item]), @@ -2077,8 +1934,7 @@ def test_generic_work_item_with_type_prefix( @staticmethod def test_read_config_context_diagram_with_params(): expected_filter = ( - "capellambse_context_diagrams-show.exchanges.or.exchange.items." - "filter" + "capellambse_context_diagrams-show.exchanges.or.exchange.items." "filter" ) config = converter_config.ConverterConfig() with open(TEST_MODEL_ELEMENTS_CONFIG, "r", encoding="utf8") as f: @@ -2113,18 +1969,11 @@ def test_read_config_tree_view_with_params( serializer = element_converter.CapellaWorkItemSerializer( model, polarion_repo.PolarionDataRepository(), - { - TEST_OCAP_UUID: data_session.ConverterData( - "pa", type_config, cap - ) - }, + {TEST_OCAP_UUID: data_session.ConverterData("pa", type_config, cap)}, True, ) - with mock.patch.object( - context.ContextDiagram, "render" - ) as wrapped_render: - + with mock.patch.object(context.ContextDiagram, "render") as wrapped_render: wis = serializer.serialize_all() _ = wis[0].attachments[0].content_bytes @@ -2154,9 +2003,7 @@ def test_read_config_links(caplog: pytest.LogCaptureFixture): if link.capella_attr == "parent" ) assert caplog.record_tuples[0] + caplog.record_tuples[1] == expected - assert ( - system_fnc_config := config.get_type_config("sa", "SystemFunction") - ) + assert (system_fnc_config := config.get_type_config("sa", "SystemFunction")) assert system_fnc_config.links[0] == converter_config.LinkConfig( capella_attr="inputs.exchanges", polarion_role="input_exchanges",