Skip to content

Commit

Permalink
fix: use the newly created workitems instead of the ones received fro…
Browse files Browse the repository at this point in the history
…m Polarion for getting their type
  • Loading branch information
micha91 committed Dec 15, 2023
1 parent b90e8dd commit 777d8b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion capella2polarion/elements/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def create_links(
else:
repres = obj._short_repr_()

workitem = ctx["POLARION_WI_MAP"][obj.uuid]
workitem = ctx["WORK_ITEMS"][obj.uuid]
new_links: list[polarion_api.WorkItemLink] = []
typ = workitem.type[0].upper() + workitem.type[1:]
for role_id in ctx["ROLES"].get(typ, []):
Expand Down
31 changes: 18 additions & 13 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ def context(model: capellambse.MelodyModel) -> dict[str, t.Any]:
api = mock.MagicMock(spec=polarion_api.OpenAPIPolarionProjectClient)
fake = FakeModelObject("uuid1", name="Fake 1")
work_item = serialize.CapellaWorkItem(
id="Obj-1",
uuid_capella="uuid1",
status="open",
type="fakeModelObject",
id="Obj-1", uuid_capella="uuid1", status="open"
)
return {
"API": api,
Expand Down Expand Up @@ -320,7 +317,7 @@ def test_create_work_items_with_special_polarion_type(
def test_create_links_custom_resolver(context: dict[str, t.Any]):
obj = context["ELEMENTS"]["FakeModelObject"][1]
context["POLARION_ID_MAP"]["uuid2"] = "Obj-2"
context["POLARION_WI_MAP"]["uuid2"] = serialize.CapellaWorkItem(
context["WORK_ITEMS"]["uuid2"] = serialize.CapellaWorkItem(
id="Obj-2",
uuid_capella="uuid2",
type="fakeModelObject",
Expand All @@ -347,7 +344,7 @@ def test_create_links_custom_exchanges_resolver(context: dict[str, t.Any]):
uuid = "1a414995-f4cd-488c-8152-486e459fb9de"
obj = context["MODEL"].by_uuid(function_uuid)
context["POLARION_ID_MAP"][function_uuid] = "Obj-1"
context["POLARION_WI_MAP"][function_uuid] = serialize.CapellaWorkItem(
context["WORK_ITEMS"][function_uuid] = serialize.CapellaWorkItem(
id="Obj-1",
uuid_capella=function_uuid,
type=type(obj).__name__,
Expand All @@ -356,7 +353,7 @@ def test_create_links_custom_exchanges_resolver(context: dict[str, t.Any]):
status="open",
)
context["POLARION_ID_MAP"][uuid] = "Obj-2"
context["POLARION_WI_MAP"][uuid] = serialize.CapellaWorkItem(
context["WORK_ITEMS"][uuid] = serialize.CapellaWorkItem(
id="Obj-2",
uuid_capella=uuid,
type="functionalExchange",
Expand Down Expand Up @@ -386,6 +383,16 @@ def test_create_links_missing_attribute(
"There is no 'attribute' attribute on "
"<FakeModelObject 'Fake 1' (uuid1)>"
)
context["WORK_ITEMS"] = {
"uuid1": serialize.CapellaWorkItem(
id="Obj-1",
uuid_capella="uuid1",
title="Fake 1",
description_type="text/html",
description=markupsafe.Markup(""),
type="fakeModelObject",
)
}

with caplog.at_level(logging.DEBUG):
links = element.create_links(obj, context)
Expand All @@ -409,7 +416,7 @@ def test_create_links_from_ElementList(context: dict[str, t.Any]):
context["POLARION_ID_MAP"] |= {
f"uuid{i}": f"Obj-{i}" for i in range(4, 7)
}
context["POLARION_WI_MAP"] |= {
context["WORK_ITEMS"] |= {
f"uuid{i}": serialize.CapellaWorkItem(
id=f"Obj-{i}",
uuid_capella=f"uuid{i}",
Expand Down Expand Up @@ -442,7 +449,7 @@ def test_create_links_from_ElementList(context: dict[str, t.Any]):
def test_create_link_from_single_attribute(context: dict[str, t.Any]):
obj = context["ELEMENTS"]["FakeModelObject"][1]
context["POLARION_ID_MAP"]["uuid2"] = "Obj-2"
context["POLARION_WI_MAP"]["uuid2"] = serialize.CapellaWorkItem(
context["WORK_ITEMS"]["uuid2"] = serialize.CapellaWorkItem(
id="Obj-2",
uuid_capella="uuid2",
type="fakeModelObject",
Expand Down Expand Up @@ -487,6 +494,7 @@ def test_update_work_items(
title="Fake 1",
description_type="text/html",
description=markupsafe.Markup(""),
type="fakeModelObject",
)
}
context["MODEL"] = mock_model = mock.MagicMock()
Expand Down Expand Up @@ -539,10 +547,7 @@ def test_update_links(
)
context["POLARION_WI_MAP"]["uuid1"].linked_work_items = [link]
context["POLARION_WI_MAP"]["uuid2"] = serialize.CapellaWorkItem(
id="Obj-2",
uuid_capella="uuid2",
status="open",
type="fakeModelObject",
id="Obj-2", uuid_capella="uuid2", status="open"
)
context["WORK_ITEMS"] = {
"uuid1": serialize.CapellaWorkItem(
Expand Down

0 comments on commit 777d8b3

Please sign in to comment.