From 047bde03062fa7cc8e6d5b8e43f802c686b97afd Mon Sep 17 00:00:00 2001 From: Michael Harbarth Date: Thu, 4 Jan 2024 19:40:10 +0100 Subject: [PATCH] fix: many minor fixes from the first smoke tests - WIP --- capella2polarion/__main__.py | 3 +- .../link_converter.py | 9 +- capella2polarion/polarion_worker.py | 3 +- tests/test_elements.py | 155 ++++++++++-------- 4 files changed, 97 insertions(+), 73 deletions(-) diff --git a/capella2polarion/__main__.py b/capella2polarion/__main__.py index 3a47e75e..f5008cbe 100644 --- a/capella2polarion/__main__.py +++ b/capella2polarion/__main__.py @@ -30,8 +30,7 @@ ) @click.option( "--polarion-url", - envvar="POLARION_URL", - default="https://localhost", + envvar="POLARION_HOST", type=str, ) @click.option("--polarion-pat", envvar="POLARION_PAT", type=str) diff --git a/capella2polarion/capella_polarion_conversion/link_converter.py b/capella2polarion/capella_polarion_conversion/link_converter.py index ab73c5f5..059c36d4 100644 --- a/capella2polarion/capella_polarion_conversion/link_converter.py +++ b/capella2polarion/capella_polarion_conversion/link_converter.py @@ -28,11 +28,13 @@ class LinkSerializer: def __init__( self, capella_polarion_mapping: polarion_repo.PolarionDataRepository, + new_work_items: dict[str, capella_work_item.CapellaWorkItem], description_references: dict[str, list[str]], project_id: str, model: capellambse.MelodyModel, ): self.capella_polarion_mapping = capella_polarion_mapping + self.new_work_items = new_work_items self.description_references = description_references self.project_id = project_id self.model = model @@ -48,12 +50,7 @@ def create_links_for_work_item( else: repres = obj._short_repr_() - work_item = ( - self.capella_polarion_mapping.get_work_item_by_capella_uuid( - obj.uuid - ) - ) - assert work_item is not None + work_item = self.new_work_items[obj.uuid] new_links: list[polarion_api.WorkItemLink] = [] typ = work_item.type[0].upper() + work_item.type[1:] for role_id in roles.get(typ, []): diff --git a/capella2polarion/polarion_worker.py b/capella2polarion/polarion_worker.py index 50f270d8..e535cd04 100644 --- a/capella2polarion/polarion_worker.py +++ b/capella2polarion/polarion_worker.py @@ -398,12 +398,13 @@ def patch_work_items( back_links: dict[str, list[polarion_api.WorkItemLink]] = {} link_serializer = link_converter.LinkSerializer( self.polarion_data_repo, + new_work_items, descr_references, self.polarion_params.project_id, self.model, ) - for uuid in self.polarion_data_repo: + for uuid in new_work_items: objects = self.model if uuid.startswith("_"): objects = self.model.diagrams diff --git a/tests/test_elements.py b/tests/test_elements.py index 3f6e56bd..1a0f7632 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -130,9 +130,15 @@ class BaseObjectContainer: - def __init__(self, cli: Capella2PolarionCli, pw: PolarionWorker) -> None: + def __init__( + self, + cli: Capella2PolarionCli, + pw: PolarionWorker, + new_work_items: dict[str, capella_work_item.CapellaWorkItem], + ) -> None: self.c2pcli: Capella2PolarionCli = cli self.pw: PolarionWorker = pw + self.new_work_items = new_work_items class TestDiagramElements: @@ -180,7 +186,18 @@ def write(self, text: str): [work_item] ) pw.elements = {"Diagram": c2p_cli.capella_model.diagrams} - return BaseObjectContainer(c2p_cli, pw) + return BaseObjectContainer( + c2p_cli, + pw, + { + uuid: capella_work_item.CapellaWorkItem( + id="Diag-1", + checksum="123", + uuid_capella=uuid, + type="fakeModelObject", + ) + }, + ) @staticmethod def test_create_diagrams(base_object: BaseObjectContainer): @@ -269,10 +286,7 @@ def write(self, text: str): pass work_item = capella_work_item.CapellaWorkItem( - id="Obj-1", - uuid_capella="uuid1", - status="open", - type="fakeModelObject", + id="Obj-1", uuid_capella="uuid1", status="open", checksum="123" ) c2p_cli = Capella2PolarionCli( debug=True, @@ -311,7 +325,19 @@ def write(self, text: str): UnsupportedFakeModelObject("uuid3") ], } - return BaseObjectContainer(c2p_cli, pw) + return BaseObjectContainer( + c2p_cli, + pw, + { + "uuid1": capella_work_item.CapellaWorkItem( + id="Obj-1", + uuid_capella="uuid1", + status="open", + checksum="123", + type="fakeModelObject", + ) + }, + ) @staticmethod def test_create_work_items( @@ -392,18 +418,16 @@ def test_create_work_items_with_special_polarion_type( @staticmethod def test_create_links_custom_resolver(base_object: BaseObjectContainer): obj = base_object.pw.elements["FakeModelObject"][1] - base_object.pw.polarion_data_repo.update_work_items( - [ - capella_work_item.CapellaWorkItem( - id="Obj-2", - uuid_capella="uuid2", - type="fakeModelObject", - description_type="text/html", - description=markupsafe.Markup(""), - status="open", - ) - ] + obj_2 = capella_work_item.CapellaWorkItem( + id="Obj-2", + uuid_capella="uuid2", + type="fakeModelObject", + description_type="text/html", + description=markupsafe.Markup(""), + status="open", ) + base_object.pw.polarion_data_repo.update_work_items([obj_2]) + base_object.new_work_items["uuid2"] = obj_2 base_object.c2pcli.synchronize_config_roles = { "FakeModelObject": ["description_reference"] } @@ -416,6 +440,7 @@ def test_create_links_custom_resolver(base_object: BaseObjectContainer): ) link_serializer = link_converter.LinkSerializer( base_object.pw.polarion_data_repo, + base_object.new_work_items, description_reference, base_object.pw.polarion_params.project_id, base_object.c2pcli.capella_model, @@ -435,31 +460,27 @@ def test_create_links_custom_exchanges_resolver( obj = base_object.c2pcli.capella_model.by_uuid(function_uuid) - base_object.pw.polarion_data_repo.update_work_items( - [ - capella_work_item.CapellaWorkItem( - id="Obj-1", - uuid_capella=function_uuid, - type=type(obj).__name__, - description_type="text/html", - description=markupsafe.Markup(""), - status="open", - ) - ] + obj_1 = capella_work_item.CapellaWorkItem( + id="Obj-1", + uuid_capella=function_uuid, + type=type(obj).__name__, + description_type="text/html", + description=markupsafe.Markup(""), + status="open", ) - base_object.pw.polarion_data_repo.update_work_items( - [ - capella_work_item.CapellaWorkItem( - id="Obj-2", - uuid_capella=uuid, - type="functionalExchange", - description_type="text/html", - description=markupsafe.Markup(""), - status="open", - ) - ] + obj_2 = capella_work_item.CapellaWorkItem( + id="Obj-2", + uuid_capella=uuid, + type="functionalExchange", + description_type="text/html", + description=markupsafe.Markup(""), + status="open", ) + base_object.pw.polarion_data_repo.update_work_items([obj_1, obj_2]) + base_object.new_work_items[function_uuid] = obj_1 + base_object.new_work_items[uuid] = obj_2 + base_object.c2pcli.synchronize_config_roles = { "SystemFunction": ["input_exchanges"] } @@ -471,6 +492,7 @@ def test_create_links_custom_exchanges_resolver( ) link_serializer = link_converter.LinkSerializer( base_object.pw.polarion_data_repo, + base_object.new_work_items, {}, base_object.pw.polarion_params.project_id, base_object.c2pcli.capella_model, @@ -494,6 +516,7 @@ def test_create_links_missing_attribute( with caplog.at_level(logging.DEBUG): link_serializer = link_converter.LinkSerializer( base_object.pw.polarion_data_repo, + base_object.new_work_items, {}, base_object.pw.polarion_params.project_id, base_object.c2pcli.capella_model, @@ -519,19 +542,21 @@ def test_create_links_from_ElementList(base_object: BaseObjectContainer): ), ) base_object.pw.elements["FakeModelObject"].append(obj) - base_object.pw.polarion_data_repo.update_work_items( - [ - capella_work_item.CapellaWorkItem( - id=f"Obj-{i}", - uuid_capella=f"uuid{i}", - type="fakeModelObject", - description_type="text/html", - description=markupsafe.Markup(""), - status="open", - ) - for i in range(4, 7) - ] - ) + + work_items = [ + capella_work_item.CapellaWorkItem( + id=f"Obj-{i}", + uuid_capella=f"uuid{i}", + type="fakeModelObject", + description_type="text/html", + description=markupsafe.Markup(""), + status="open", + ) + for i in range(4, 7) + ] + base_object.pw.polarion_data_repo.update_work_items(work_items) + for work_item in work_items: + base_object.new_work_items[work_item.uuid_capella] = work_item expected_link = polarion_api.WorkItemLink( "Obj-6", @@ -547,6 +572,7 @@ def test_create_links_from_ElementList(base_object: BaseObjectContainer): ) link_serializer = link_converter.LinkSerializer( base_object.pw.polarion_data_repo, + base_object.new_work_items, {}, base_object.pw.polarion_params.project_id, base_object.c2pcli.capella_model, @@ -564,19 +590,18 @@ def test_create_link_from_single_attribute( base_object: BaseObjectContainer, ): obj = base_object.pw.elements["FakeModelObject"][1] - base_object.pw.polarion_data_repo.update_work_items( - [ - capella_work_item.CapellaWorkItem( - id="Obj-2", - uuid_capella="uuid2", - type="fakeModelObject", - description_type="text/html", - description=markupsafe.Markup(""), - status="open", - ) - ] + work_item_2 = capella_work_item.CapellaWorkItem( + id="Obj-2", + uuid_capella="uuid2", + type="fakeModelObject", + description_type="text/html", + description=markupsafe.Markup(""), + status="open", ) + base_object.pw.polarion_data_repo.update_work_items([work_item_2]) + base_object.new_work_items["uuid2"] = work_item_2 + expected = polarion_api.WorkItemLink( "Obj-2", "Obj-1", @@ -585,6 +610,7 @@ def test_create_link_from_single_attribute( ) link_serializer = link_converter.LinkSerializer( base_object.pw.polarion_data_repo, + base_object.new_work_items, {}, base_object.pw.polarion_params.project_id, base_object.c2pcli.capella_model, @@ -625,6 +651,7 @@ def test_update_work_items( id="Obj-1", uuid_capella="uuid1", title="Fake 1", + type="type", description_type="text/html", description=markupsafe.Markup(""), )