Skip to content

Commit

Permalink
test: Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Dec 15, 2023
1 parent fee2b28 commit b90e8dd
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 11 deletions.
1 change: 0 additions & 1 deletion capella2polarion/elements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"delete_work_items",
"get_types",
"get_elements_and_type_map",
"make_model_elements_index",
"STATUS_DELETE",
]

Expand Down
3 changes: 0 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
TEST_MODEL_ELEMENTS_CONFIG,
)

ELEMENTS_IDX_PATH = pathlib.Path("elements_index.yaml")


def prepare_cli_test(
monkeypatch: pytest.MonkeyPatch, return_value: t.Any | cabc.Iterable[t.Any]
Expand Down Expand Up @@ -89,4 +87,3 @@ def test_migrate_model_elements(monkeypatch: pytest.MonkeyPatch):
assert mock_delete_work_items.call_count == 1
assert mock_patch_work_items.call_count == 1
assert mock_post_work_items.call_count == 1
assert ELEMENTS_IDX_PATH.exists()
107 changes: 100 additions & 7 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,18 @@ class UnsupportedFakeModelObject(FakeModelObject):


class TestModelElements:
# TODO: Add tests for link creation of real model elements (special)

@staticmethod
@pytest.fixture
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"
id="Obj-1",
uuid_capella="uuid1",
status="open",
type="fakeModelObject",
)
return {
"API": api,
Expand Down Expand Up @@ -275,10 +280,54 @@ def test_create_work_items(

assert work_items == [expected, expected1]

@staticmethod
@pytest.mark.parametrize(
"uuid,type,attrs",
[
pytest.param(
"55b90f9a-c5af-47fc-9c1c-48090414d1f1",
"OperationalInteraction",
{"title": "Prepared food"},
id="OperationalInteraction",
)
],
)
def test_create_work_items_with_special_polarion_type(
context: dict[str, t.Any],
model: capellambse.MelodyModel,
uuid: str,
type: str,
attrs: dict[str, t.Any],
):
context["ELEMENTS"] = {type: [model.by_uuid(uuid)]}
context["POLARION_TYPE_MAP"][uuid] = type
context["MODEL"] = model

expected = serialize.CapellaWorkItem(
uuid_capella=uuid,
type=type[0].lower() + type[1:],
description_type="text/html",
description=markupsafe.Markup(""),
status="open",
**attrs,
)

work_items = element.create_work_items(context)

assert work_items == [expected]

@staticmethod
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(
id="Obj-2",
uuid_capella="uuid2",
type="fakeModelObject",
description_type="text/html",
description=markupsafe.Markup(""),
status="open",
)
context["ROLES"] = {"FakeModelObject": ["description_reference"]}
context["DESCR_REFERENCES"] = {"uuid2": ["uuid1"]}
expected = polarion_api.WorkItemLink(
Expand All @@ -295,11 +344,26 @@ def test_create_links_custom_resolver(context: dict[str, t.Any]):
@staticmethod
def test_create_links_custom_exchanges_resolver(context: dict[str, t.Any]):
function_uuid = "ceffa011-7b66-4b3c-9885-8e075e312ffa"
uuid = "1a414995-f4cd-488c-8152-486e459fb9de"
obj = context["MODEL"].by_uuid(function_uuid)
context["POLARION_ID_MAP"][function_uuid] = "Obj-1"
context["POLARION_ID_MAP"][
"1a414995-f4cd-488c-8152-486e459fb9de"
] = "Obj-2"
context["POLARION_WI_MAP"][function_uuid] = serialize.CapellaWorkItem(
id="Obj-1",
uuid_capella=function_uuid,
type=type(obj).__name__,
description_type="text/html",
description=markupsafe.Markup(""),
status="open",
)
context["POLARION_ID_MAP"][uuid] = "Obj-2"
context["POLARION_WI_MAP"][uuid] = serialize.CapellaWorkItem(
id="Obj-2",
uuid_capella=uuid,
type="functionalExchange",
description_type="text/html",
description=markupsafe.Markup(""),
status="open",
)
context["ROLES"] = {"SystemFunction": ["input_exchanges"]}
expected = polarion_api.WorkItemLink(
"Obj-1",
Expand Down Expand Up @@ -341,9 +405,21 @@ def test_create_links_from_ElementList(context: dict[str, t.Any]):
),
)
context["ELEMENTS"]["FakeModelObject"].append(obj)

context["POLARION_ID_MAP"] |= {
f"uuid{i}": f"Obj-{i}" for i in range(4, 7)
}
context["POLARION_WI_MAP"] |= {
f"uuid{i}": serialize.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)
}
expected_link = polarion_api.WorkItemLink(
"Obj-6",
"Obj-5",
Expand All @@ -366,6 +442,14 @@ 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(
id="Obj-2",
uuid_capella="uuid2",
type="fakeModelObject",
description_type="text/html",
description=markupsafe.Markup(""),
status="open",
)
expected = polarion_api.WorkItemLink(
"Obj-2",
"Obj-1",
Expand Down Expand Up @@ -455,14 +539,23 @@ 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"
id="Obj-2",
uuid_capella="uuid2",
status="open",
type="fakeModelObject",
)
context["WORK_ITEMS"] = {
"uuid1": serialize.CapellaWorkItem(
id="Obj-1", uuid_capella="uuid1", status="open"
id="Obj-1",
uuid_capella="uuid1",
status="open",
type="fakeModelObject",
),
"uuid2": serialize.CapellaWorkItem(
id="Obj-2", uuid_capella="uuid2", status="open"
id="Obj-2",
uuid_capella="uuid2",
status="open",
type="fakeModelObject",
),
}
mock_get_polarion_wi_map = mock.MagicMock()
Expand Down

0 comments on commit b90e8dd

Please sign in to comment.