diff --git a/capella2polarion/__main__.py b/capella2polarion/__main__.py index f5e44205..e6643ff3 100644 --- a/capella2polarion/__main__.py +++ b/capella2polarion/__main__.py @@ -21,6 +21,7 @@ from capella2polarion import elements from capella2polarion.c2pcli import C2PCli from capella2polarion.elements import helpers, serialize +from capella2polarion.polarion import PolarionWorker @click.group() @@ -82,16 +83,17 @@ def cli( capella_model, synchronize_config, ) - lC2PCli.setupLogger() + lC2PCli.setup_logger() ctx.obj = lC2PCli lC2PCli.echo = click.echo + lC2PCli.echo("Start") @cli.command() @click.pass_obj def printCliState(aC2PCli: C2PCli) -> None: """Print the CLI State.""" - aC2PCli.setupLogger() + aC2PCli.setup_logger() aC2PCli.printState() @@ -128,11 +130,10 @@ def synchronize(ctx: click.core.Context) -> None: # ctx.obj["CAPELLA_UUIDS"] = set(ctx.obj["POLARION_TYPE_MAP"]) # ctx.obj["CAPELLA_UUIDS"] = set(lPW.PolarionTypeMap) # lPW.CapellaUUIDs = set(lPW.PolarionTypeMap) - from polarion import PolarionWorker - lPW = PolarionWorker( aC2PCli.polarion_params, aC2PCli.logger, helpers.resolve_element_type ) + assert aC2PCli.capella_diagram_cache_index_content != None lPW.load_elements_and_type_map( aC2PCli.synchronize_config_content, aC2PCli.capella_model, diff --git a/capella2polarion/c2pcli.py b/capella2polarion/c2pcli.py index 696e31ac..203db512 100644 --- a/capella2polarion/c2pcli.py +++ b/capella2polarion/c2pcli.py @@ -47,7 +47,7 @@ def __init__( ) self.capella_diagram_cache_index_content: list[ dict[str, typing.Any] - ] | None = None + ] = [] self.capella_model: capellambse.MelodyModel = capella_model self.synchronize_config_io: typing.TextIO = synchronize_config_io self.synchronize_config_content: dict[str, typing.Any] @@ -234,7 +234,7 @@ def load_capella_diagramm_cache_index(self) -> None: """Load to CapellaDiagramCacheIndexContent.""" if not self.exitsCapellaDiagrammCacheIndexFile(): raise Exception("capella diagramm cache index file doe not exits") - self.capella_diagram_cache_index_content = None + self.capella_diagram_cache_index_content = [] if self.get_capella_diagram_cache_index_file_path() != None: l_text_content = ( self.get_capella_diagram_cache_index_file_path().read_text( diff --git a/tests/test_cli.py b/tests/test_cli.py index a18b167e..74e648bf 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -6,45 +6,49 @@ import collections.abc as cabc import os import pathlib -import typing as t +import typing from unittest import mock import polarion_rest_api_client as polarion_api import pytest from click import testing +import capella2polarion.__main__ as main +from capella2polarion import elements +from capella2polarion.c2pcli import C2PCli +from capella2polarion.polarion import PolarionWorker + # pylint: disable-next=relative-beyond-top-level, useless-suppression -from conftest import ( # type: ignore[import] +from tests.conftest import ( # type: ignore[import] TEST_DIAGRAM_CACHE, TEST_HOST, TEST_MODEL, TEST_MODEL_ELEMENTS_CONFIG, ) -import capella2polarion.__main__ as main -from capella2polarion import elements - def prepare_cli_test( - monkeypatch: pytest.MonkeyPatch, return_value: t.Any | cabc.Iterable[t.Any] + monkeypatch: pytest.MonkeyPatch, + return_value: typing.Any | cabc.Iterable[typing.Any], ) -> mock.MagicMock: os.environ["POLARION_HOST"] = TEST_HOST os.environ["POLARION_PAT"] = "1234" mock_api = mock.MagicMock(spec=polarion_api.OpenAPIPolarionProjectClient) monkeypatch.setattr(polarion_api, "OpenAPIPolarionProjectClient", mock_api) - mock_get_polarion_wi_map = mock.MagicMock() - monkeypatch.setattr( - elements, "get_polarion_wi_map", mock_get_polarion_wi_map - ) - if isinstance(return_value, cabc.Iterable) and not isinstance( - return_value, (str, dict) - ): - id_map_attr = "side_effect" - else: - id_map_attr = "return_value" + # # mock_get_polarion_wi_map = mock.MagicMock() + # # monkeypatch.setattr( + # # elements, "get_polarion_wi_map", mock_get_polarion_wi_map + # # ) + # if isinstance(return_value, cabc.Iterable) and not isinstance( + # return_value, (str, dict) + # ): + # id_map_attr = "side_effect" + # else: + # id_map_attr = "return_value" - setattr(mock_get_polarion_wi_map, id_map_attr, return_value) - return mock_get_polarion_wi_map + # setattr(mock_get_polarion_wi_map, id_map_attr, return_value) + # return mock_get_polarion_wi_map + return mock_api def test_migrate_model_elements(monkeypatch: pytest.MonkeyPatch): @@ -65,25 +69,54 @@ def test_migrate_model_elements(monkeypatch: pytest.MonkeyPatch): {}, ), ) - mock_delete_work_items = mock.MagicMock() - monkeypatch.setattr(elements, "delete_work_items", mock_delete_work_items) - mock_post_work_items = mock.MagicMock() - monkeypatch.setattr(elements, "post_work_items", mock_post_work_items) - mock_patch_work_items = mock.MagicMock() - monkeypatch.setattr(elements, "patch_work_items", mock_patch_work_items) + # mock_delete_work_items = mock.MagicMock() + # monkeypatch.setattr(elements, "delete_work_items", mock_delete_work_items) + # mock_post_work_items = mock.MagicMock() + # monkeypatch.setattr(elements, "post_work_items", mock_post_work_items) + # mock_patch_work_items = mock.MagicMock() + # monkeypatch.setattr(elements, "patch_work_items", mock_patch_work_items) command = [ - "--project-id=project_id", - "model-elements", - str(TEST_MODEL), - str(TEST_DIAGRAM_CACHE), - str(TEST_MODEL_ELEMENTS_CONFIG), + "--polarion-project-id", + "{project-id}", + "--polarion-url", + "https://www.czy.de", + "--polarion-pat", + "AlexandersPrivateAcessToken", + "--polarion-delete-work-items", + "--capella-diagram-cache-folder-path", + "./tests/data/diagram_cache", + "--capella-model", + "./tests/data/model/Melody Model Test.aird", + "--synchronize-config", + "./tests/data/model_elements/config.yaml", + "synchronize" + # ,str(TEST_MODEL), + # ,str(TEST_DIAGRAM_CACHE), + # ,str(TEST_MODEL_ELEMENTS_CONFIG), ] - result = testing.CliRunner().invoke(main.cli, command) + mock_polarionworker_deleteworkitem = mock.MagicMock() + mock.patch.object( + PolarionWorker.setup_polarion_client, + mock_polarionworker_deleteworkitem, + ) + mock.patch.object( + PolarionWorker.delete_work_items, mock_polarionworker_deleteworkitem + ) + + # mock_c2pcli_setuplogger = mock.MagicMock() + # TODO .. wieso kracht es in der nächsten Zeile? + mock.patch.object( + C2PCli.load_synchronize_config, mock_polarionworker_deleteworkitem + ) + + result = testing.CliRunner().invoke(main.cli, command, terminal_width=60) assert result.exit_code == 0 - assert mock_get_polarion_wi_map.call_count == 1 - 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 mock_c2pcli_setuplogger.call_count == 1 + # assert mock_get_polarion_wi_map.call_count == 1 + # assert mock_delete_work_items.call_count == 1 + # assert mock_patch_work_items.call_count == 1 + # assert mock_post_work_items.call_count == 1