From 94090627635c2248ff03807ba916d6e15e12c5b9 Mon Sep 17 00:00:00 2001 From: ewuerger Date: Fri, 15 Dec 2023 12:41:43 +0100 Subject: [PATCH] test: Fix broken tests --- tests/test_cli.py | 3 -- tests/test_elements.py | 107 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 100 insertions(+), 10 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 0b752e17..5b54e612 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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] @@ -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() diff --git a/tests/test_elements.py b/tests/test_elements.py index 58f1697d..7e16e638 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -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, @@ -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( @@ -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", @@ -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", @@ -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", @@ -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()