Skip to content

Commit

Permalink
fix: many minor fixes from the first smoke tests - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
micha91 committed Jan 4, 2024
1 parent bc90df6 commit 047bde0
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 73 deletions.
3 changes: 1 addition & 2 deletions capella2polarion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, []):
Expand Down
3 changes: 2 additions & 1 deletion capella2polarion/polarion_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
155 changes: 91 additions & 64 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"]
}
Expand All @@ -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,
Expand All @@ -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"]
}
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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(""),
)
Expand Down

0 comments on commit 047bde0

Please sign in to comment.