Skip to content

Commit

Permalink
feat: Also add fields, if there are less than 2 links of a type
Browse files Browse the repository at this point in the history
  • Loading branch information
micha91 committed Nov 29, 2023
1 parent 3366d46 commit 125c3ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
3 changes: 0 additions & 3 deletions capella2polarion/elements/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,6 @@ def _create_link_fields(
links: list[polarion_api.WorkItemLink],
reverse: bool = False,
):
# TODO check why we only create links for > 2 per role
if len(links) < 2:
return
role = f"{role}_reverse" if reverse else role
work_item.additional_attributes[role] = {
"type": "text/html",
Expand Down
58 changes: 33 additions & 25 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ def test_patch_work_item_grouped_links(
obj.uuid
].linked_work_items

mock_grouped_links = mock.MagicMock()
monkeypatch.setattr(
element, "create_grouped_link_fields", mock_grouped_links
)

mock_grouped_links_reverse = mock.MagicMock()
monkeypatch.setattr(
element,
"create_grouped_back_link_fields",
mock_grouped_links_reverse,
)

context["MODEL"] = mock_model = mock.MagicMock()
mock_model.by_uuid.side_effect = [
FakeModelObject(f"uuid{i}", name=f"Fake {i}") for i in range(3)
Expand All @@ -525,27 +537,19 @@ def test_patch_work_item_grouped_links(
elements.patch_work_items(context)

update_work_item_calls = context["API"].update_work_item.call_args_list

assert len(update_work_item_calls) == 3

work_item_0 = update_work_item_calls[0][0][0]
work_item_1 = update_work_item_calls[1][0][0]
work_item_2 = update_work_item_calls[2][0][0]
mock_grouped_links_calls = mock_grouped_links.call_args_list

assert (
work_item_0.additional_attributes.pop("attribute")["value"]
== HTML_LINK_0["attribute"]
)
assert len(mock_grouped_links_calls) == 3

assert (
work_item_1.additional_attributes.pop("attribute")["value"]
== HTML_LINK_1["attribute"]
)
assert mock_grouped_links_calls[0][0][0] == dummy_work_items["uuid0"]
assert mock_grouped_links_calls[1][0][0] == dummy_work_items["uuid1"]
assert mock_grouped_links_calls[2][0][0] == dummy_work_items["uuid2"]

assert (
work_item_2.additional_attributes.pop("attribute_reverse")["value"]
== HTML_LINK_2["attribute_reverse"]
)
work_item_0 = update_work_item_calls[0][0][0]
work_item_1 = update_work_item_calls[1][0][0]
work_item_2 = update_work_item_calls[2][0][0]

assert work_item_0.additional_attributes == {}
assert work_item_1.additional_attributes == {}
Expand Down Expand Up @@ -597,16 +601,20 @@ def test_maintain_reverse_grouped_links_attributes(dummy_work_items):
del dummy_work_items["uuid0"].additional_attributes["attribute"]
del dummy_work_items["uuid1"].additional_attributes["attribute"]

# TODO check if we really want to exclude groups of <2
"""
assert dummy_work_items["uuid0"].additional_attributes.pop("attribute_reverse")[
"value"
] == HTML_LINK_0["attribute_reverse"]
assert (
dummy_work_items["uuid0"].additional_attributes.pop(
"attribute_reverse"
)["value"]
== HTML_LINK_0["attribute_reverse"]
)

assert (
dummy_work_items["uuid1"].additional_attributes.pop(
"attribute_reverse"
)["value"]
== HTML_LINK_1["attribute_reverse"]
)

assert dummy_work_items["uuid1"].additional_attributes.pop("attribute_reverse")[
"value"
] == HTML_LINK_1["attribute_reverse"]
"""
assert (
dummy_work_items["uuid2"].additional_attributes.pop(
"attribute_reverse"
Expand Down

0 comments on commit 125c3ea

Please sign in to comment.