Skip to content

Commit

Permalink
fix: minor fixes and fixes for tests after rebase. wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
micha91 committed Nov 17, 2023
1 parent 38f2865 commit 7a8e9da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 40 deletions.
11 changes: 6 additions & 5 deletions capella2polarion/elements/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_work_items(

_work_items = list(filter(None, _work_items))
valid_types = set(map(helpers.resolve_element_type, set(ctx["ELEMENTS"])))
work_items: list[polarion_api.CapellaWorkItem] = []
work_items: list[serialize.CapellaWorkItem] = []
missing_types: set[str] = set()
for work_item in _work_items:
assert work_item is not None
Expand Down Expand Up @@ -204,7 +204,7 @@ def _handle_exchanges(
return _create(context, wid, role_id, exchanges, links)


def create_grouped_links_attributes(ctx: dict[str, t.Any]) -> None:
def maintain_grouped_links_attributes(ctx: dict[str, t.Any]) -> None:
"""Create list attributes for links of all work items.
The list is updated on all primary (source) work items.
Expand Down Expand Up @@ -259,9 +259,10 @@ def maintain_reverse_grouped_links_attributes(ctx: dict[str, t.Any]) -> None:
if len(links) < 2:
continue

work_item.additional_attributes[
f"{role}_reverse"
] = _make_url_list(links, reverse=True)
work_item.additional_attributes[f"{role}_reverse"] = {
"type": "text/html",
"value": _make_url_list(links, reverse=True),
}

if work_item.uuid_capella:
del work_item.additional_attributes["uuid_capella"]
Expand Down
32 changes: 0 additions & 32 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,3 @@ def test_migrate_model_elements(monkeypatch: pytest.MonkeyPatch):
assert mock_patch_work_items.call_count == 1
assert mock_post_work_items.call_count == 1
assert ELEMENTS_IDX_PATH.exists()


def test_grouped_links_attributes(monkeypatch: pytest.MonkeyPatch):
mock_get_polarion_wi_map = prepare_cli_test(
monkeypatch,
{"uuid{i}": polarion_api.WorkItem("project/W-{i}") for i in range(10)},
)
mock_maintain_grouped_links_attributes = mock.MagicMock()
monkeypatch.setattr(
elements.element,
"maintain_grouped_links_attributes",
mock_maintain_grouped_links_attributes,
)
mock_maintain_reverse_grouped_links_attributes = mock.MagicMock()
monkeypatch.setattr(
elements.element,
"maintain_reverse_grouped_links_attributes",
mock_maintain_reverse_grouped_links_attributes,
)

command = [
"--project-id=project_id",
"grouped-links-attributes",
"OperationalCapability SystemCapability",
]

result = testing.CliRunner().invoke(main.cli, command)

assert result.exit_code == 0
assert mock_get_polarion_wi_map.call_count == 1
assert mock_maintain_grouped_links_attributes.call_count == 1
assert mock_maintain_reverse_grouped_links_attributes.call_count == 1
8 changes: 5 additions & 3 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ def test_maintain_grouped_links_attributes(context: dict[str, t.Any]):
assert [l[0][0] for l in links] == ["Obj-0", "Obj-1", "Obj-2"]
work_items = context["API"].update_work_item.call_args_list
assert context["API"].get_all_work_item_links.call_count == 3
assert work_items[0][0][0].additional_attributes["attribute"] == (
assert work_items[0][0][0].additional_attributes["attribute"][
"value"
] == (
"<ul><li>"
'<span class="polarion-rte-link" data-type="workItem" id="fake" '
'data-item-id="Obj-1" data-option-id="long"></span>'
Expand Down Expand Up @@ -515,8 +517,8 @@ def test_maintain_reverse_grouped_links_attributes(
work_items = context["API"].update_work_item.call_args_list
assert context["API"].update_work_item.call_count == 2
assert work_items[0][0][0].additional_attributes == {}
assert work_items[1][0][0].additional_attributes[
"attribute_reverse"
assert work_items[1][0][0].additional_attributes["attribute_reverse"][
"value"
] == (
"<ul><li>"
'<span class="polarion-rte-link" data-type="workItem" id="fake" '
Expand Down

0 comments on commit 7a8e9da

Please sign in to comment.