From 8a2cdcc6c59fc54ee79882bab5844696b88673d9 Mon Sep 17 00:00:00 2001
From: Michael Harbarth
The figure below provides an overview of the interface partners:
There may be a diagram with 2 boxes and a blue line
diff --git a/tests/conftest.py b/tests/conftest.py index 296cd368..050c0343 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -32,6 +32,10 @@ "diagram_cache": str(TEST_DIAGRAM_CACHE), } TEST_HOST = "https://api.example.com" +TEST_PROJECT_ID = "project_id" +DOCUMENT_TEMPLATES = TEST_DOCUMENT_ROOT / "templates" +DOCUMENT_TEXT_WORK_ITEMS = "document_work_items.html.j2" +DOCUMENT_WORK_ITEMS_CROSS_PROJECT = "work_items_cross_project.html.j2" @pytest.fixture @@ -59,7 +63,7 @@ def dummy_work_items() -> dict[str, data_models.CapellaWorkItem]: description=markupsafe.Markup(""), linked_work_items=[ polarion_api.WorkItemLink( - f"Obj-{i}", f"Obj-{j}", "attribute", True, "project_id" + f"Obj-{i}", f"Obj-{j}", "attribute", True, TEST_PROJECT_ID ) for j in range(3) if (i not in (j, 2)) @@ -120,7 +124,7 @@ def base_object( ) c2p_cli = cli.Capella2PolarionCli( debug=True, - polarion_project_id="project_id", + polarion_project_id=TEST_PROJECT_ID, polarion_url=TEST_HOST, polarion_pat="PrivateAccessToken", polarion_delete_work_items=True, @@ -180,13 +184,9 @@ def empty_polarion_worker(monkeypatch: pytest.MonkeyPatch): mock_project_client = mock.MagicMock(spec=polarion_api.ProjectClient) monkeypatch.setattr(polarion_api, "ProjectClient", mock_project_client) polarion_params = polarion_worker.PolarionWorkerParams( - project_id="project_id", + project_id=TEST_PROJECT_ID, url=TEST_HOST, pat="PrivateAccessToken", delete_work_items=True, ) yield polarion_worker.CapellaPolarionWorker(polarion_params) - - -DOCUMENT_TEMPLATES = TEST_DOCUMENT_ROOT / "templates" -DOCUMENT_TEXT_WORK_ITEMS = "document_work_items.html.j2" diff --git a/tests/data/documents/combined_config.yaml b/tests/data/documents/combined_config.yaml index 3660a6d2..cadd7e3e 100644 --- a/tests/data/documents/combined_config.yaml +++ b/tests/data/documents/combined_config.yaml @@ -91,4 +91,4 @@ full_authority: - polarion_space: _default polarion_name: id1240 params: - interface: 2681f26a-e492-4e5d-8b33-92fb00a48622 + interface: d8655737-39ab-4482-a934-ee847c7ff6bd diff --git a/tests/data/documents/templates/work_items_cross_project.html.j2 b/tests/data/documents/templates/work_items_cross_project.html.j2 new file mode 100644 index 00000000..a3848123 --- /dev/null +++ b/tests/data/documents/templates/work_items_cross_project.html.j2 @@ -0,0 +1,8 @@ +{# + Copyright DB InfraGO AG and contributors + SPDX-License-Identifier: Apache-2.0 +#} + +{% set element = model.by_uuid(element) %} +{{ insert_work_item(element, session) }} +{{ element | link_work_item }} diff --git a/tests/test_documents.py b/tests/test_documents.py index 5069b46d..93c4b1cb 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -15,8 +15,10 @@ from tests.conftest import ( DOCUMENT_TEMPLATES, DOCUMENT_TEXT_WORK_ITEMS, + DOCUMENT_WORK_ITEMS_CROSS_PROJECT, TEST_COMBINED_DOCUMENT_CONFIG, TEST_DOCUMENT_ROOT, + TEST_PROJECT_ID, ) CLASSES_TEMPLATE = "test-classes.html.j2" @@ -26,6 +28,10 @@ FULL_AUTHORITY_CONFIG = TEST_DOCUMENT_ROOT / "full_authority_config.yaml" DOCUMENTS_CONFIG_JINJA = TEST_DOCUMENT_ROOT / "config.yaml.j2" MIXED_AUTHORITY_DOCUMENT = TEST_DOCUMENT_ROOT / "mixed_authority_doc.html" +PROJECT_EXTERNAL_WORKITEM_SRC = ( + '
' +) def existing_documents() -> polarion_repo.DocumentRepository: @@ -105,7 +111,7 @@ def test_create_new_document( ] ) renderer = document_renderer.DocumentRenderer( - empty_polarion_worker.polarion_data_repo, model + empty_polarion_worker.polarion_data_repo, model, TEST_PROJECT_ID ) document_data = renderer.render_document( @@ -159,7 +165,7 @@ def test_update_document( ] ) renderer = document_renderer.DocumentRenderer( - empty_polarion_worker.polarion_data_repo, model + empty_polarion_worker.polarion_data_repo, model, TEST_PROJECT_ID ) old_doc = polarion_api.Document( module_folder="_default", @@ -212,7 +218,7 @@ def test_mixed_authority_document( model: capellambse.MelodyModel, ): renderer = document_renderer.DocumentRenderer( - empty_polarion_worker.polarion_data_repo, model + empty_polarion_worker.polarion_data_repo, model, TEST_PROJECT_ID ) old_doc = polarion_api.Document( module_folder="_default", @@ -284,7 +290,7 @@ def test_create_full_authority_document_text_work_items( model: capellambse.MelodyModel, ): renderer = document_renderer.DocumentRenderer( - empty_polarion_worker.polarion_data_repo, model + empty_polarion_worker.polarion_data_repo, model, TEST_PROJECT_ID ) document_data = renderer.render_document( @@ -334,7 +340,7 @@ def test_update_full_authority_document_text_work_items( model: capellambse.MelodyModel, ): renderer = document_renderer.DocumentRenderer( - empty_polarion_worker.polarion_data_repo, model + empty_polarion_worker.polarion_data_repo, model, TEST_PROJECT_ID ) old_doc = polarion_api.Document( module_folder="_default", @@ -398,11 +404,20 @@ def test_render_all_documents_partially_successfully( model: capellambse.MelodyModel, caplog: pytest.LogCaptureFixture, ): + empty_polarion_worker.polarion_data_repo.update_work_items( + [ + dm.CapellaWorkItem( + "ATSY-1234", + uuid_capella="d8655737-39ab-4482-a934-ee847c7ff6bd", + type="componentExchange", + ), + ] + ) with open(TEST_COMBINED_DOCUMENT_CONFIG, "r", encoding="utf-8") as f: conf = document_config.read_config_file(f) renderer = document_renderer.DocumentRenderer( - empty_polarion_worker.polarion_data_repo, model + empty_polarion_worker.polarion_data_repo, model, TEST_PROJECT_ID ) projects_data = renderer.render_documents(conf, existing_documents()) @@ -434,6 +449,12 @@ def test_render_all_documents_partially_successfully( ) == 2 ) + assert ( + PROJECT_EXTERNAL_WORKITEM_SRC + in projects_data["TestProject"] + .updated_docs[0] + .document.home_page_content.value + ) assert ( len(projects_data[None].updated_docs[0].document.rendering_layouts) == 0 @@ -450,6 +471,56 @@ def test_render_all_documents_partially_successfully( ) +def test_insert_work_item_cross_project( + empty_polarion_worker: polarion_worker.CapellaPolarionWorker, + model: capellambse.MelodyModel, +): + empty_polarion_worker.polarion_data_repo.update_work_items( + [ + dm.CapellaWorkItem( + "ATSY-1234", + uuid_capella="d8655737-39ab-4482-a934-ee847c7ff6bd", + type="componentExchange", + ) + ] + ) + renderer = document_renderer.DocumentRenderer( + empty_polarion_worker.polarion_data_repo, model, TEST_PROJECT_ID + ) + + document_data_1 = renderer.render_document( + DOCUMENT_TEMPLATES, + DOCUMENT_WORK_ITEMS_CROSS_PROJECT, + "test", + "name", + "title", + document_project_id="DIFFERENT", + element="d8655737-39ab-4482-a934-ee847c7ff6bd", + ) + + document_data_2 = renderer.render_document( + DOCUMENT_TEMPLATES, + DOCUMENT_WORK_ITEMS_CROSS_PROJECT, + "test", + "name", + "title", + element="d8655737-39ab-4482-a934-ee847c7ff6bd", + ) + + content_1: list[html.HtmlElement] = html.fragments_fromstring( + document_data_1.document.home_page_content.value + ) + content_2: list[html.HtmlElement] = html.fragments_fromstring( + document_data_2.document.home_page_content.value + ) + + assert len(content_1) == 2 + assert content_1[0].attrib["id"].endswith(f"|project={TEST_PROJECT_ID}") + assert content_1[1].attrib["data-scope"] == TEST_PROJECT_ID + assert len(content_2) == 2 + assert content_2[0].attrib["id"].endswith("|external=true") + + def test_render_all_documents_overwrite_headings_layouts( empty_polarion_worker: polarion_worker.CapellaPolarionWorker, model: capellambse.MelodyModel, @@ -458,7 +529,11 @@ def test_render_all_documents_overwrite_headings_layouts( conf = document_config.read_config_file(f) renderer = document_renderer.DocumentRenderer( - empty_polarion_worker.polarion_data_repo, model, True, True + empty_polarion_worker.polarion_data_repo, + model, + TEST_PROJECT_ID, + True, + True, ) projects_data = renderer.render_documents(conf, existing_documents())