From e2e7d9a29eaf536789761a1a5ee18dc18ecf5fbc Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 17:17:00 +0200 Subject: [PATCH 01/59] support content path update --- .../commands/common/content_constant_paths.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 266b6e969b8..c7d8200afa1 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -43,3 +43,61 @@ ) PYTHONPATH_STR = ":".join(str(path) for path in PYTHONPATH) + + +def update_global_content_path(content_path: str) -> None: + """ + Set the global CONTENT_PATH variable to the provided content path. + + Args: + content_path (str): The new content path to set. + """ + global CONTENT_PATH + global ALL_PACKS_DEPENDENCIES_DEFAULT_PATH + global CONF_PATH + global DEFAULT_ID_SET_PATH + global MP_V2_ID_SET_PATH + global XPANSE_ID_SET_PATH + global LANDING_PAGE_SECTIONS_PATH + global NATIVE_IMAGE_PATH + global COMMON_SERVER_PYTHON_PATH + global DEMISTO_MOCK_PATH + global API_MODULES_SCRIPTS_DIR + global PYTHONPATH + global PYTHONPATH_STR + + logger.info(f'Updating content_path globally: {content_path}') + CONTENT_PATH = Path(content_path) + ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = CONTENT_PATH / "all_packs_dependencies.json" + CONF_PATH = CONTENT_PATH / TESTS_DIR / "conf.json" + DEFAULT_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set.json" + MP_V2_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" + XPANSE_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" + LANDING_PAGE_SECTIONS_PATH = ( + CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" + ) + NATIVE_IMAGE_PATH = CONTENT_PATH / "Tests" / NATIVE_IMAGE_FILE_NAME + COMMON_SERVER_PYTHON_PATH = ( + CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" + ) + DEMISTO_MOCK_PATH = CONTENT_PATH / TESTS_DIR / "demistomock" + API_MODULES_SCRIPTS_DIR = CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" + + PYTHONPATH = [ + path.absolute() + for path in [ + Path(CONTENT_PATH), + COMMON_SERVER_PYTHON_PATH, + DEMISTO_MOCK_PATH, + Path(__file__).parent.parent / "lint" / "resources" / "pylint_plugins", + ] + ] + + if API_MODULES_SCRIPTS_DIR.exists(): + PYTHONPATH.extend(path.absolute() for path in API_MODULES_SCRIPTS_DIR.iterdir()) + else: + logger.debug( + "Could not add API modules to 'PYTHONPATH' as the base directory does not exist." + ) + + PYTHONPATH_STR = ":".join(str(path) for path in PYTHONPATH) From 14a911dbcb03fcb056614d7fff129e4e1262d880 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 17:18:15 +0200 Subject: [PATCH 02/59] changelog --- .changelog/4663.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changelog/4663.yml diff --git a/.changelog/4663.yml b/.changelog/4663.yml new file mode 100644 index 00000000000..aeb72e905df --- /dev/null +++ b/.changelog/4663.yml @@ -0,0 +1,4 @@ +changes: +- description: Introducing functionality for updating CONTENT_PATH global. + type: feature +pr_number: 4663 \ No newline at end of file From 84c0ed0548f07f194ec5c847cf6f4a58f74f570d Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 18:28:01 +0200 Subject: [PATCH 03/59] pre-commit fixes --- demisto_sdk/commands/common/content_constant_paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index c7d8200afa1..f4f27d51464 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -66,7 +66,7 @@ def update_global_content_path(content_path: str) -> None: global PYTHONPATH global PYTHONPATH_STR - logger.info(f'Updating content_path globally: {content_path}') + logger.info(f"Updating content_path globally: {content_path}") CONTENT_PATH = Path(content_path) ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = CONTENT_PATH / "all_packs_dependencies.json" CONF_PATH = CONTENT_PATH / TESTS_DIR / "conf.json" From f8d062f3c3a0faed13f40aee179e59a83872afd4 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 18:28:50 +0200 Subject: [PATCH 04/59] docstring --- demisto_sdk/commands/common/content_constant_paths.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index f4f27d51464..243790f5b3a 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -47,7 +47,8 @@ def update_global_content_path(content_path: str) -> None: """ - Set the global CONTENT_PATH variable to the provided content path. + Sets the global CONTENT_PATH variable to the provided content path + and its derivatives accordingly. Args: content_path (str): The new content path to set. From 54721cf7c9fe50cb403cfbfcf5805e717dbfc343 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 18:56:55 +0200 Subject: [PATCH 05/59] pre commit fix --- .changelog/4663.yml | 2 +- demisto_sdk/commands/common/content_constant_paths.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.changelog/4663.yml b/.changelog/4663.yml index aeb72e905df..83b1b0075b7 100644 --- a/.changelog/4663.yml +++ b/.changelog/4663.yml @@ -1,4 +1,4 @@ changes: - description: Introducing functionality for updating CONTENT_PATH global. type: feature -pr_number: 4663 \ No newline at end of file +pr_number: 4663 diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 243790f5b3a..4276836433f 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -45,6 +45,7 @@ PYTHONPATH_STR = ":".join(str(path) for path in PYTHONPATH) + def update_global_content_path(content_path: str) -> None: """ Sets the global CONTENT_PATH variable to the provided content path From b6b268d6189c900663a4e374caa0f672202670ff Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 21:31:10 +0200 Subject: [PATCH 06/59] introduce ContentPaths and update references --- conftest.py | 6 +- demisto_sdk/__main__.py | 15 +- .../commands/common/content_constant_paths.py | 161 ++++++++---------- demisto_sdk/commands/common/errors.py | 10 +- .../common/hook_validations/conf_json.py | 8 +- .../content_entity_validator.py | 6 +- .../common/hook_validations/readme.py | 8 +- demisto_sdk/commands/common/native_image.py | 4 +- demisto_sdk/commands/common/update_id_set.py | 14 +- .../commands/content_graph/interface/graph.py | 4 +- .../content_graph/objects/base_content.py | 4 +- .../content_graph/objects/conf_json.py | 4 +- .../content_graph/objects/content_item.py | 14 +- .../commands/content_graph/objects/pack.py | 14 +- .../content_graph/objects/repository.py | 8 +- .../content_graph/parsers/base_content.py | 6 +- .../tests/format_with_graph_test.py | 2 +- .../tests/generate_docs_script_test.py | 2 +- .../tests/graph_validator_test.py | 2 +- .../tests/pack_metadata_graph_test.py | 2 +- .../tests/prepare_content_graph_test.py | 2 +- .../tests/update_content_graph_test.py | 2 +- .../commands/coverage_analyze/helpers.py | 4 +- .../commands/create_id_set/create_id_set.py | 12 +- .../find_dependencies/find_dependencies.py | 4 +- .../commands/format/update_generic_yml.py | 10 +- .../commands/init/contribution_converter.py | 4 +- .../init/tests/contribution_converter_test.py | 4 +- demisto_sdk/commands/lint/lint_manager.py | 4 +- .../commands/pre_commit/hooks/docker.py | 14 +- demisto_sdk/commands/pre_commit/hooks/hook.py | 6 +- .../commands/pre_commit/hooks/pycln.py | 6 +- .../commands/pre_commit/hooks/sourcery.py | 4 +- .../commands/pre_commit/pre_commit_command.py | 26 +-- .../commands/pre_commit/pre_commit_context.py | 6 +- .../commands/setup_env/setup_environment.py | 87 +++++----- .../test_modeling_rule/test_modeling_rule.py | 6 +- .../tests/test_modeling_rule_test.py | 4 +- .../commands/validate/old_validate_manager.py | 11 +- .../validate/tests/old_validators_test.py | 6 +- .../validate/tests/validators_test.py | 4 +- .../GR101_is_using_invalid_from_version.py | 4 +- .../GR103_is_using_unknown_content.py | 4 +- ...104_is_pack_display_name_already_exists.py | 4 +- .../GR105_duplicate_content_id.py | 6 +- .../GR106_is_testplaybook_in_use.py | 4 +- ...107_is_deprecated_content_item_in_usage.py | 6 +- ...109_script_name_is_not_unique_validator.py | 4 +- .../validate/validators/base_validator.py | 10 +- .../commands/xsoar_linter/xsoar_linter.py | 4 +- demisto_sdk/scripts/merge_pytest_reports.py | 12 +- demisto_sdk/scripts/validate_conf_json.py | 4 +- 52 files changed, 268 insertions(+), 314 deletions(-) diff --git a/conftest.py b/conftest.py index af46bfece8f..29c2810cd6a 100644 --- a/conftest.py +++ b/conftest.py @@ -102,10 +102,10 @@ def graph_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Ge repo = get_repo(request, tmp_path_factory) - bc.CONTENT_PATH = Path(repo.path) - neo4j_path = bc.CONTENT_PATH.parent.parent / "neo4j" + bc.ContentPaths.update_content_path(Path(repo.path)) + neo4j_path = bc.ContentPaths.CONTENT_PATH.parent.parent / "neo4j" - mock.patch.object(ContentGraphInterface, "repo_path", bc.CONTENT_PATH) + mock.patch.object(ContentGraphInterface, "repo_path", bc.ContentPaths.CONTENT_PATH) mock.patch.object(neo4j_service, "REPO_PATH", neo4j_path) yield repo diff --git a/demisto_sdk/__main__.py b/demisto_sdk/__main__.py index 5bfda94b65d..fed96bbc2c9 100644 --- a/demisto_sdk/__main__.py +++ b/demisto_sdk/__main__.py @@ -37,10 +37,7 @@ FileType, MarketplaceVersions, ) -from demisto_sdk.commands.common.content_constant_paths import ( - ALL_PACKS_DEPENDENCIES_DEFAULT_PATH, - CONTENT_PATH, -) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.cpu_count import cpu_count from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.hook_validations.readme import ReadMeValidator @@ -212,7 +209,7 @@ def main(ctx, config, version, release_notes, **kwargs): import dotenv dotenv.load_dotenv( - CONTENT_PATH / ".env", override=True + ContentPaths.CONTENT_PATH / ".env", override=True ) # load .env file from the cwd if platform.system() == "Windows": @@ -2712,7 +2709,7 @@ def find_dependencies(ctx, **kwargs): use_pack_metadata = kwargs.get("use_pack_metadata", False) all_packs_dependencies = kwargs.get("all_packs_dependencies", False) get_dependent_on = kwargs.get("get_dependent_on", False) - output_path = kwargs.get("output_path", ALL_PACKS_DEPENDENCIES_DEFAULT_PATH) + output_path = kwargs.get("output_path", ContentPaths.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH) dependency = kwargs.get("dependency", "") try: PackDependencies.find_dependencies_manager( @@ -3644,12 +3641,12 @@ def setup_env( if ide == "auto-detect": # Order decides which IDEType will be selected for configuration if multiple IDEs are detected - if (CONTENT_PATH / ".vscode").exists(): + if (ContentPaths.CONTENT_PATH / ".vscode").exists(): logger.info( "Visual Studio Code IDEType has been detected and will be configured." ) ide_type = IDEType.VSCODE - elif (CONTENT_PATH / ".idea").exists(): + elif (ContentPaths.CONTENT_PATH / ".idea").exists(): logger.info( "PyCharm / IDEA IDEType has been detected and will be configured." ) @@ -3912,7 +3909,7 @@ def xsoar_linter( def dump_api( ctx: typer.Context, output_path: Path = typer.Option( - CONTENT_PATH, + ContentPaths.CONTENT_PATH, "-o", "--output", help="The output directory or JSON file to save the demisto-sdk api.", diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 4276836433f..3e2fe4b10fc 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -1,105 +1,80 @@ from pathlib import Path +from typing import Union from demisto_sdk.commands.common.constants import NATIVE_IMAGE_FILE_NAME, TESTS_DIR from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import get_content_path -CONTENT_PATH: Path = Path(get_content_path()) - -ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = CONTENT_PATH / "all_packs_dependencies.json" - -CONF_PATH = CONTENT_PATH / TESTS_DIR / "conf.json" - -DEFAULT_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set.json" -MP_V2_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" -XPANSE_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" -LANDING_PAGE_SECTIONS_PATH = ( - CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" -) -NATIVE_IMAGE_PATH = CONTENT_PATH / "Tests" / NATIVE_IMAGE_FILE_NAME - -COMMON_SERVER_PYTHON_PATH = ( - CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" -) -DEMISTO_MOCK_PATH = CONTENT_PATH / TESTS_DIR / "demistomock" -API_MODULES_SCRIPTS_DIR = CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" - -PYTHONPATH = [ - path.absolute() - for path in [ - Path(CONTENT_PATH), - COMMON_SERVER_PYTHON_PATH, - DEMISTO_MOCK_PATH, - Path(__file__).parent.parent / "lint" / "resources" / "pylint_plugins", - ] -] - -if API_MODULES_SCRIPTS_DIR.exists(): - PYTHONPATH.extend(path.absolute() for path in API_MODULES_SCRIPTS_DIR.iterdir()) - -else: - logger.debug( - "Could not add API modules to 'PYTHONPATH' as the base directory does not exist." - ) - -PYTHONPATH_STR = ":".join(str(path) for path in PYTHONPATH) - - - -def update_global_content_path(content_path: str) -> None: - """ - Sets the global CONTENT_PATH variable to the provided content path - and its derivatives accordingly. - - Args: - content_path (str): The new content path to set. - """ - global CONTENT_PATH - global ALL_PACKS_DEPENDENCIES_DEFAULT_PATH - global CONF_PATH - global DEFAULT_ID_SET_PATH - global MP_V2_ID_SET_PATH - global XPANSE_ID_SET_PATH - global LANDING_PAGE_SECTIONS_PATH - global NATIVE_IMAGE_PATH - global COMMON_SERVER_PYTHON_PATH - global DEMISTO_MOCK_PATH - global API_MODULES_SCRIPTS_DIR - global PYTHONPATH - global PYTHONPATH_STR - - logger.info(f"Updating content_path globally: {content_path}") - CONTENT_PATH = Path(content_path) - ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = CONTENT_PATH / "all_packs_dependencies.json" - CONF_PATH = CONTENT_PATH / TESTS_DIR / "conf.json" - DEFAULT_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set.json" - MP_V2_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" - XPANSE_ID_SET_PATH = CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" - LANDING_PAGE_SECTIONS_PATH = ( - CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" - ) - NATIVE_IMAGE_PATH = CONTENT_PATH / "Tests" / NATIVE_IMAGE_FILE_NAME - COMMON_SERVER_PYTHON_PATH = ( - CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" - ) - DEMISTO_MOCK_PATH = CONTENT_PATH / TESTS_DIR / "demistomock" - API_MODULES_SCRIPTS_DIR = CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" +class ContentPaths: + # Class-level variables (shared across all instances) + CONTENT_PATH: Path = Path(get_content_path()) + ALL_PACKS_DEPENDENCIES_DEFAULT_PATH: Path = CONTENT_PATH / "all_packs_dependencies.json" + CONF_PATH: Path = CONTENT_PATH / TESTS_DIR / "conf.json" + DEFAULT_ID_SET_PATH: Path = CONTENT_PATH / TESTS_DIR / "id_set.json" + MP_V2_ID_SET_PATH: Path = CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" + XPANSE_ID_SET_PATH: Path = CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" + LANDING_PAGE_SECTIONS_PATH: Path = ( + CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" + ) + NATIVE_IMAGE_PATH: Path = CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME + COMMON_SERVER_PYTHON_PATH: Path = ( + CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" + ) + DEMISTO_MOCK_PATH: Path = CONTENT_PATH / TESTS_DIR / "demistomock" + API_MODULES_SCRIPTS_DIR: Path = CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" PYTHONPATH = [ - path.absolute() - for path in [ - Path(CONTENT_PATH), - COMMON_SERVER_PYTHON_PATH, - DEMISTO_MOCK_PATH, - Path(__file__).parent.parent / "lint" / "resources" / "pylint_plugins", + path.absolute() + for path in [ + CONTENT_PATH, + COMMON_SERVER_PYTHON_PATH, + DEMISTO_MOCK_PATH, + Path(__file__).parent.parent / "lint" / "resources" / "pylint_plugins", + ] ] - ] + PYTHONPATH_STR = ":".join(str(path) for path in PYTHONPATH) - if API_MODULES_SCRIPTS_DIR.exists(): - PYTHONPATH.extend(path.absolute() for path in API_MODULES_SCRIPTS_DIR.iterdir()) - else: - logger.debug( - "Could not add API modules to 'PYTHONPATH' as the base directory does not exist." + @classmethod + def update_content_path(cls, content_path: Union[str, Path]) -> None: + """ + Updates the class-level content path and derived paths. + + Args: + content_path (Union[str, Path]): The new content path to set. + """ + logger.info(f"Updating content_path globally: {content_path}") + + cls.CONTENT_PATH = Path(content_path) + cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = cls.CONTENT_PATH / "all_packs_dependencies.json" + cls.CONF_PATH = cls.CONTENT_PATH / TESTS_DIR / "conf.json" + cls.DEFAULT_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set.json" + cls.MP_V2_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" + cls.XPANSE_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" + cls.LANDING_PAGE_SECTIONS_PATH = ( + cls.CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" + ) + cls.NATIVE_IMAGE_PATH = cls.CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME + cls.COMMON_SERVER_PYTHON_PATH = ( + cls.CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" ) + cls.DEMISTO_MOCK_PATH = cls.CONTENT_PATH / TESTS_DIR / "demistomock" + cls.API_MODULES_SCRIPTS_DIR = cls.CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" + + cls.PYTHONPATH = [ + path.absolute() + for path in [ + cls.CONTENT_PATH, + cls.COMMON_SERVER_PYTHON_PATH, + cls.DEMISTO_MOCK_PATH, + Path(__file__).parent.parent / "lint" / "resources" / "pylint_plugins", + ] + ] - PYTHONPATH_STR = ":".join(str(path) for path in PYTHONPATH) + if cls.API_MODULES_SCRIPTS_DIR.exists(): + cls.PYTHONPATH.extend(path.absolute() for path in cls.API_MODULES_SCRIPTS_DIR.iterdir()) + else: + logger.debug( + "Could not add API modules to 'PYTHONPATH' as the base directory does not exist." + ) + + cls.PYTHONPATH_STR = ":".join(str(path) for path in cls.PYTHONPATH) diff --git a/demisto_sdk/commands/common/errors.py b/demisto_sdk/commands/common/errors.py index 67652cec8b4..c7484e32151 100644 --- a/demisto_sdk/commands/common/errors.py +++ b/demisto_sdk/commands/common/errors.py @@ -20,7 +20,7 @@ FileType, MarketplaceVersions, ) -from demisto_sdk.commands.common.content_constant_paths import CONF_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.tools import is_external_repository FOUND_FILES_AND_ERRORS: list = [] @@ -2512,8 +2512,8 @@ def integration_not_registered( file_path, missing_test_playbook_configurations, no_tests_key ): return ( - f"The following integration is not registered in {CONF_PATH} file.\n" - f"Please add:\n{missing_test_playbook_configurations}\nto {CONF_PATH} " + f"The following integration is not registered in {ContentPaths.CONF_PATH} file.\n" + f"Please add:\n{missing_test_playbook_configurations}\nto {ContentPaths.CONF_PATH} " f"path under 'tests' key.\n" f"If you don't want to add a test playbook for this integration, please add: \n{no_tests_key}to the " f"file {file_path} or run 'demisto-sdk format -i {file_path}'" @@ -2539,10 +2539,10 @@ def test_playbook_not_configured( missing_integration_configurations, ): return ( - f"The TestPlaybook {content_item_id} is not registered in {CONF_PATH} file.\n " + f"The TestPlaybook {content_item_id} is not registered in {ContentPaths.CONF_PATH} file.\n " f"Please add\n{missing_test_playbook_configurations}\n " f"or if this test playbook is for an integration\n{missing_integration_configurations}\n " - f"to {CONF_PATH} path under 'tests' key." + f"to {ContentPaths.CONF_PATH} path under 'tests' key." ) @staticmethod diff --git a/demisto_sdk/commands/common/hook_validations/conf_json.py b/demisto_sdk/commands/common/hook_validations/conf_json.py index 10b78c739ba..df0d8671ee9 100644 --- a/demisto_sdk/commands/common/hook_validations/conf_json.py +++ b/demisto_sdk/commands/common/hook_validations/conf_json.py @@ -1,7 +1,7 @@ from pathlib import Path from demisto_sdk.commands.common.constants import API_MODULES_PACK, FileType -from demisto_sdk.commands.common.content_constant_paths import CONF_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.errors import Errors from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.hook_validations.base_validator import ( @@ -37,7 +37,7 @@ def __init__( self.conf_data = self.load_conf_file() def load_conf_file(self): - with open(CONF_PATH) as data_file: + with open(ContentPaths.CONF_PATH) as data_file: return json.load(data_file) def is_valid_conf_json(self): @@ -69,7 +69,7 @@ def is_valid_description_in_conf_dict(self, checked_dict): error_message, error_code = Errors.description_missing_from_conf_json( problematic_instances ) - if self.handle_error(error_message, error_code, file_path=CONF_PATH): + if self.handle_error(error_message, error_code, file_path=ContentPaths.CONF_PATH): self._is_valid = False return self._is_valid @@ -91,7 +91,7 @@ def is_test_in_conf_json(self, file_id): return True error_message, error_code = Errors.test_not_in_conf_json(file_id) - if self.handle_error(error_message, error_code, file_path=CONF_PATH): + if self.handle_error(error_message, error_code, file_path=ContentPaths.CONF_PATH): return False return True diff --git a/demisto_sdk/commands/common/hook_validations/content_entity_validator.py b/demisto_sdk/commands/common/hook_validations/content_entity_validator.py index a4c02fb3e7b..3eb064ee3ed 100644 --- a/demisto_sdk/commands/common/hook_validations/content_entity_validator.py +++ b/demisto_sdk/commands/common/hook_validations/content_entity_validator.py @@ -30,7 +30,7 @@ FileType, ) from demisto_sdk.commands.common.content import Content -from demisto_sdk.commands.common.content_constant_paths import CONF_PATH, CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.errors import Errors from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.handlers import DEFAULT_YAML_HANDLER as yaml @@ -224,7 +224,7 @@ def is_valid_marketplaces_on_modified(self) -> bool: try: old_pack_marketplaces = set( get_remote_file( - f"{CONTENT_PATH}/Packs/{pack_name}/pack_metadata.json", + f"{ContentPaths.CONTENT_PATH}/Packs/{pack_name}/pack_metadata.json", tag=self.prev_ver, ).get(MARKETPLACE_KEY_PACK_METADATA, ()) ) @@ -368,7 +368,7 @@ def _is_id_equals_name(self, file_type): return True def _load_conf_file(self): - with open(CONF_PATH) as data_file: + with open(ContentPaths.CONF_PATH) as data_file: return json.load(data_file) @error_codes("CJ104,CJ102") diff --git a/demisto_sdk/commands/common/hook_validations/readme.py b/demisto_sdk/commands/common/hook_validations/readme.py index af0d7d52550..6f5c8cb0c49 100644 --- a/demisto_sdk/commands/common/hook_validations/readme.py +++ b/demisto_sdk/commands/common/hook_validations/readme.py @@ -18,7 +18,7 @@ RELATIVE_HREF_URL_REGEX, RELATIVE_MARKDOWN_URL_REGEX, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.docker_helper import init_global_docker_client from demisto_sdk.commands.common.errors import ( FOUND_FILES_AND_ERRORS, @@ -173,7 +173,7 @@ def __init__( json_file_path=json_file_path, specific_validations=specific_validations, ) - self.content_path = CONTENT_PATH + self.content_path = ContentPaths.CONTENT_PATH self.file_path_str = file_path self.file_path = Path(file_path) self.pack_path = self.file_path.parent @@ -757,7 +757,7 @@ def empty_context_mgr(bool): if mdx_server_is_up(): # this allows for this context to be reentrant logger.debug("server is already up. Not restarting") return empty_context_mgr(True) - if ReadMeValidator.are_modules_installed_for_verify(CONTENT_PATH): # type: ignore + if ReadMeValidator.are_modules_installed_for_verify(ContentPaths.CONTENT_PATH): # type: ignore ReadMeValidator.add_node_env_vars() return start_local_MDX_server(handle_error, file_path) elif ReadMeValidator.is_docker_available(): @@ -766,7 +766,7 @@ def empty_context_mgr(bool): @staticmethod def add_node_env_vars(): - content_path = CONTENT_PATH + content_path = ContentPaths.CONTENT_PATH node_modules_path = content_path / Path("node_modules") # type: ignore os.environ["NODE_PATH"] = ( str(node_modules_path) + os.pathsep + os.getenv("NODE_PATH", "") diff --git a/demisto_sdk/commands/common/native_image.py b/demisto_sdk/commands/common/native_image.py index babb0c83f72..be8341517d0 100644 --- a/demisto_sdk/commands/common/native_image.py +++ b/demisto_sdk/commands/common/native_image.py @@ -5,7 +5,7 @@ from pydantic import BaseModel from demisto_sdk.commands.common.constants import NATIVE_IMAGE_DOCKER_NAME -from demisto_sdk.commands.common.content_constant_paths import NATIVE_IMAGE_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.hook_validations.docker import DockerImageValidator from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.singleton import PydanticSingleton @@ -68,7 +68,7 @@ def get_instance_from(cls, *args, **kwargs): return cls.from_path(*args, **kwargs) @classmethod - def from_path(cls, native_image_config_file_path: Path = Path(NATIVE_IMAGE_PATH)): + def from_path(cls, native_image_config_file_path: Path = Path(ContentPaths.NATIVE_IMAGE_PATH)): native_image_config = cls.parse_file(native_image_config_file_path) native_image_config.__docker_images_to_native_images_support() return native_image_config diff --git a/demisto_sdk/commands/common/update_id_set.py b/demisto_sdk/commands/common/update_id_set.py index 782c9de0913..0665e417d6c 100755 --- a/demisto_sdk/commands/common/update_id_set.py +++ b/demisto_sdk/commands/common/update_id_set.py @@ -51,11 +51,7 @@ FileType, MarketplaceVersions, ) -from demisto_sdk.commands.common.content_constant_paths import ( - DEFAULT_ID_SET_PATH, - MP_V2_ID_SET_PATH, - XPANSE_ID_SET_PATH, -) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.cpu_count import cpu_count from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.logger import logger @@ -2629,7 +2625,7 @@ def merge_id_sets( def re_create_id_set( # noqa: C901 - id_set_path: Optional[Path] = DEFAULT_ID_SET_PATH, + id_set_path: Optional[Path] = ContentPaths.DEFAULT_ID_SET_PATH, pack_to_create=None, objects_to_create: list = None, print_logs: bool = True, @@ -2652,9 +2648,9 @@ def re_create_id_set( # noqa: C901 """ if id_set_path == "": id_set_path = { - MarketplaceVersions.MarketplaceV2.value: MP_V2_ID_SET_PATH, - MarketplaceVersions.XPANSE.value: XPANSE_ID_SET_PATH, - }.get(marketplace, DEFAULT_ID_SET_PATH) + MarketplaceVersions.MarketplaceV2.value: ContentPaths.MP_V2_ID_SET_PATH, + MarketplaceVersions.XPANSE.value: ContentPaths.XPANSE_ID_SET_PATH, + }.get(marketplace, ContentPaths.DEFAULT_ID_SET_PATH) if not objects_to_create: if marketplace == MarketplaceVersions.MarketplaceV2.value: diff --git a/demisto_sdk/commands/content_graph/interface/graph.py b/demisto_sdk/commands/content_graph/interface/graph.py index 7b60cad8731..cb7d9d85b2a 100644 --- a/demisto_sdk/commands/content_graph/interface/graph.py +++ b/demisto_sdk/commands/content_graph/interface/graph.py @@ -4,7 +4,7 @@ from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union from demisto_sdk.commands.common.constants import MarketplaceVersions -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.git_util import GitUtil from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import ( @@ -29,7 +29,7 @@ class DeprecatedItemUsage(NamedTuple): class ContentGraphInterface(ABC): - repo_path = CONTENT_PATH # type: ignore + repo_path = ContentPaths.CONTENT_PATH # type: ignore METADATA_FILE_NAME = "metadata.json" DEPENDS_ON_FILE_NAME = "depends_on.json" _depends_on = None diff --git a/demisto_sdk/commands/content_graph/objects/base_content.py b/demisto_sdk/commands/content_graph/objects/base_content.py index 50c173d1ff1..2fff5e8433b 100644 --- a/demisto_sdk/commands/content_graph/objects/base_content.py +++ b/demisto_sdk/commands/content_graph/objects/base_content.py @@ -28,7 +28,7 @@ GitStatuses, MarketplaceVersions, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import JSON_Handler from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import set_value, write_dict @@ -182,7 +182,7 @@ def to_dict(self) -> Dict[str, Any]: ) if "path" in json_dct and Path(json_dct["path"]).is_absolute(): json_dct["path"] = ( - Path(json_dct["path"]).relative_to(CONTENT_PATH) + Path(json_dct["path"]).relative_to(ContentPaths.CONTENT_PATH) ).as_posix() # type: ignore json_dct["content_type"] = self.content_type return json_dct diff --git a/demisto_sdk/commands/content_graph/objects/conf_json.py b/demisto_sdk/commands/content_graph/objects/conf_json.py index 781f6425436..d95236ccef6 100644 --- a/demisto_sdk/commands/content_graph/objects/conf_json.py +++ b/demisto_sdk/commands/content_graph/objects/conf_json.py @@ -13,7 +13,7 @@ from pydantic import BaseModel, Extra, Field, validator from demisto_sdk.commands.common.constants import MarketplaceVersions -from demisto_sdk.commands.common.content_constant_paths import CONF_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.tools import get_json from demisto_sdk.commands.content_graph.common import ContentType @@ -88,7 +88,7 @@ class ConfJSON(StrictBaseModel): reputation_tests: List[str] @staticmethod - def from_path(path: Path = CONF_PATH) -> "ConfJSON": + def from_path(path: Path = ContentPaths.CONF_PATH) -> "ConfJSON": return ConfJSON(**get_json(path)) # type:ignore[assignment] @property diff --git a/demisto_sdk/commands/content_graph/objects/content_item.py b/demisto_sdk/commands/content_graph/objects/content_item.py index 452756cae2c..e20879837e6 100644 --- a/demisto_sdk/commands/content_graph/objects/content_item.py +++ b/demisto_sdk/commands/content_graph/objects/content_item.py @@ -22,7 +22,7 @@ from pydantic import DirectoryPath, Field, fields, validator from demisto_sdk.commands.common.constants import PACKS_FOLDER, MarketplaceVersions -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import ( get_file, @@ -60,9 +60,9 @@ class ContentItem(BaseContent): def validate_path(cls, v: Path, values) -> Path: if v.is_absolute(): return v - if not CONTENT_PATH.name: - return CONTENT_PATH / v - return CONTENT_PATH.with_name(values.get("source_repo", "content")) / v + if not ContentPaths.CONTENT_PATH.name: + return ContentPaths.CONTENT_PATH / v + return ContentPaths.CONTENT_PATH.with_name(values.get("source_repo", "content")) / v @staticmethod @abstractmethod @@ -126,7 +126,7 @@ def get_pack( if not pack: if pack_name := get_pack_name(path): pack = BaseContent.from_path( - CONTENT_PATH / PACKS_FOLDER / pack_name, metadata_only=True + ContentPaths.CONTENT_PATH / PACKS_FOLDER / pack_name, metadata_only=True ) # type: ignore[assignment] return pack # type: ignore[return-value] @@ -134,13 +134,13 @@ def get_pack( def ignored_errors(self) -> List[str]: if ignored_errors := self.get_ignored_errors(self.path.name): return ignored_errors - file_path = get_relative_path(self.path, CONTENT_PATH) + file_path = get_relative_path(self.path, ContentPaths.CONTENT_PATH) return self.get_ignored_errors(file_path) def ignored_errors_related_files(self, file_path: Path) -> List[str]: if ignored_errors := self.get_ignored_errors((Path(file_path)).name): return ignored_errors - file_path = get_relative_path(file_path, CONTENT_PATH) + file_path = get_relative_path(file_path, ContentPaths.CONTENT_PATH) return self.get_ignored_errors(file_path) def get_ignored_errors(self, path: Union[str, Path]) -> List[str]: diff --git a/demisto_sdk/commands/content_graph/objects/pack.py b/demisto_sdk/commands/content_graph/objects/pack.py index e726618b86c..51ecec57cf1 100644 --- a/demisto_sdk/commands/content_graph/objects/pack.py +++ b/demisto_sdk/commands/content_graph/objects/pack.py @@ -19,7 +19,7 @@ ImagesFolderNames, MarketplaceVersions, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import ( MarketplaceTagParser, @@ -143,9 +143,9 @@ def from_orm(cls, obj) -> "Pack": def validate_path(cls, v: Path, values) -> Path: if v.is_absolute(): return v - if not CONTENT_PATH.name: - return CONTENT_PATH / v - return CONTENT_PATH.with_name(values.get("source_repo", "content")) / v + if not ContentPaths.CONTENT_PATH.name: + return ContentPaths.CONTENT_PATH / v + return ContentPaths.CONTENT_PATH.with_name(values.get("source_repo", "content")) / v @property def is_private(self) -> bool: @@ -159,13 +159,13 @@ def pack_id(self) -> str: def ignored_errors(self) -> List[str]: if ignored_errors := self.get_ignored_errors(PACK_METADATA_FILENAME): return ignored_errors - file_path = get_relative_path(self.path, CONTENT_PATH) + file_path = get_relative_path(self.path, ContentPaths.CONTENT_PATH) return self.get_ignored_errors(file_path / PACK_METADATA_FILENAME) def ignored_errors_related_files(self, file_path: Path) -> List[str]: if ignored_errors := self.get_ignored_errors((Path(file_path)).name): return ignored_errors - file_path = get_relative_path(file_path, CONTENT_PATH) + file_path = get_relative_path(file_path, ContentPaths.CONTENT_PATH) return self.get_ignored_errors(file_path) def get_ignored_errors(self, path: Union[str, Path]) -> List[str]: @@ -532,7 +532,7 @@ def _upload_item_by_item( def _copy_base_pack_docs( self, destination_path: Path, marketplace: MarketplaceVersions ): - documentation_path = CONTENT_PATH / "Documentation" + documentation_path = ContentPaths.CONTENT_PATH / "Documentation" documentation_output = destination_path / "Documentation" documentation_output.mkdir(exist_ok=True, parents=True) if ( diff --git a/demisto_sdk/commands/content_graph/objects/repository.py b/demisto_sdk/commands/content_graph/objects/repository.py index 76ce4184c6d..0a7daa6b052 100644 --- a/demisto_sdk/commands/content_graph/objects/repository.py +++ b/demisto_sdk/commands/content_graph/objects/repository.py @@ -9,7 +9,7 @@ from pydantic import BaseModel, DirectoryPath from demisto_sdk.commands.common.constants import MarketplaceVersions -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.cpu_count import cpu_count from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.content_graph.objects.pack import Pack @@ -19,7 +19,7 @@ @lru_cache -def from_path(path: Path = CONTENT_PATH, packs_to_parse: Optional[Tuple[str]] = None): +def from_path(path: Path = ContentPaths.CONTENT_PATH, packs_to_parse: Optional[Tuple[str]] = None): """ Returns a ContentDTO object with all the packs of the content repository. @@ -40,12 +40,12 @@ def from_path(path: Path = CONTENT_PATH, packs_to_parse: Optional[Tuple[str]] = class ContentDTO(BaseModel): - path: DirectoryPath = Path(CONTENT_PATH) # type: ignore + path: DirectoryPath = Path(ContentPaths.CONTENT_PATH) # type: ignore packs: List[Pack] @staticmethod def from_path( - path: Path = CONTENT_PATH, packs_to_parse: Optional[Tuple[str, ...]] = None + path: Path = ContentPaths.CONTENT_PATH, packs_to_parse: Optional[Tuple[str, ...]] = None ): """ Returns a ContentDTO object with all the packs of the content repository. diff --git a/demisto_sdk/commands/content_graph/parsers/base_content.py b/demisto_sdk/commands/content_graph/parsers/base_content.py index 9db360275d7..61b0013f8c0 100644 --- a/demisto_sdk/commands/content_graph/parsers/base_content.py +++ b/demisto_sdk/commands/content_graph/parsers/base_content.py @@ -7,9 +7,7 @@ from pydantic import Field from demisto_sdk.commands.common.constants import MarketplaceVersions -from demisto_sdk.commands.common.content_constant_paths import ( - CONTENT_PATH, -) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.common import ContentType from demisto_sdk.commands.content_graph.strict_objects.base_strict_model import ( StructureError, @@ -60,7 +58,7 @@ def node_id(self) -> str: @property def source_repo(self) -> Optional[str]: - return CONTENT_PATH.name + return ContentPaths.CONTENT_PATH.name @staticmethod def update_marketplaces_set_with_xsoar_values(marketplaces_set: set) -> set: diff --git a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py index 5c32fdff63b..56f2d68f9dc 100644 --- a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py @@ -39,7 +39,7 @@ def setup_method(mocker, tmp_path_factory, repo: Repo): import demisto_sdk.commands.content_graph.objects.base_content as bc from demisto_sdk.commands.common.files.file import File - bc.CONTENT_PATH = Path(repo.path) + bc.ContentPaths.update_content_path(Path(repo.path)) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) diff --git a/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py b/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py index 61ec5a4b33c..4fcd277b7eb 100644 --- a/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py +++ b/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py @@ -37,7 +37,7 @@ def setup_method(mocker, tmp_path_factory, repo: Repo): """Auto-used fixture for setup before every test run""" import demisto_sdk.commands.content_graph.objects.base_content as bc - bc.CONTENT_PATH = Path(repo.path) + bc.ContentPaths.update_content_path(Path(repo.path)) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index 27bbb31fcbc..0a56acd06fd 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -42,7 +42,7 @@ def setup_method(mocker, tmp_path_factory): import demisto_sdk.commands.content_graph.objects.base_content as bc from demisto_sdk.commands.common.files.file import File - bc.CONTENT_PATH = GIT_PATH + bc.ContentPaths.update_content_path(GIT_PATH) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) diff --git a/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py b/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py index e61ef031ac8..75c4647e46f 100644 --- a/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py @@ -28,7 +28,7 @@ def setup_method(mocker, tmp_path_factory, repo: Repo): """Auto-used fixture for setup before every test run""" import demisto_sdk.commands.content_graph.objects.base_content as bc - bc.CONTENT_PATH = Path(repo.path) + bc.ContentPaths.update_content_path(Path(repo.path)) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) diff --git a/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py index 18406ee49b2..38767b57b91 100644 --- a/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py @@ -37,7 +37,7 @@ def setup_method(mocker, tmp_path_factory, repo: Repo): import demisto_sdk.commands.content_graph.objects.base_content as bc from demisto_sdk.commands.common.files.file import File - bc.CONTENT_PATH = Path(repo.path) + bc.ContentPaths.update_content_path(Path(repo.path)) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) diff --git a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py index fa74d8079fb..c596beb36ff 100644 --- a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py @@ -47,7 +47,7 @@ def setup_method(mocker, tmp_path_factory): from_path.cache_clear() - bc.CONTENT_PATH = GIT_PATH + bc.ContentPaths.update_content_path(GIT_PATH) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) diff --git a/demisto_sdk/commands/coverage_analyze/helpers.py b/demisto_sdk/commands/coverage_analyze/helpers.py index 6f4c7deecd6..2d20e8786d0 100644 --- a/demisto_sdk/commands/coverage_analyze/helpers.py +++ b/demisto_sdk/commands/coverage_analyze/helpers.py @@ -8,7 +8,7 @@ import coverage import requests -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.logger import logger @@ -89,7 +89,7 @@ def coverage_files() -> Iterable[str]: """ iterate over the '.coverage' files in the repo. """ - packs_path = CONTENT_PATH / "Packs" + packs_path = ContentPaths.CONTENT_PATH / "Packs" for cov_path in packs_path.glob("*/Integrations/*/.coverage"): yield str(cov_path) for cov_path in packs_path.glob("*/Scripts/*/.coverage"): diff --git a/demisto_sdk/commands/create_id_set/create_id_set.py b/demisto_sdk/commands/create_id_set/create_id_set.py index 6c7a9834fe4..68b28658037 100644 --- a/demisto_sdk/commands/create_id_set/create_id_set.py +++ b/demisto_sdk/commands/create_id_set/create_id_set.py @@ -8,11 +8,7 @@ GENERIC_COMMANDS_NAMES, MarketplaceVersions, ) -from demisto_sdk.commands.common.content_constant_paths import ( - DEFAULT_ID_SET_PATH, - MP_V2_ID_SET_PATH, - XPANSE_ID_SET_PATH, -) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.tools import open_id_set_file from demisto_sdk.commands.common.update_id_set import re_create_id_set @@ -109,11 +105,11 @@ def create_command_to_implemented_integration_map(self): def save_id_set(self): if not self.output: if self.marketplace == MarketplaceVersions.MarketplaceV2: - self.output = MP_V2_ID_SET_PATH + self.output = ContentPaths.MP_V2_ID_SET_PATH elif self.marketplace == MarketplaceVersions.XPANSE: - self.output = XPANSE_ID_SET_PATH + self.output = ContentPaths.XPANSE_ID_SET_PATH else: - self.output = DEFAULT_ID_SET_PATH + self.output = ContentPaths.DEFAULT_ID_SET_PATH if self.output: if not exists(self.output): intermediate_dirs = os.path.dirname(os.path.abspath(self.output)) diff --git a/demisto_sdk/commands/find_dependencies/find_dependencies.py b/demisto_sdk/commands/find_dependencies/find_dependencies.py index 52f0677d785..10cd699ded3 100644 --- a/demisto_sdk/commands/find_dependencies/find_dependencies.py +++ b/demisto_sdk/commands/find_dependencies/find_dependencies.py @@ -17,7 +17,7 @@ IGNORED_PACKS_IN_DEPENDENCY_CALC, PACKS_DIR, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import ( @@ -39,7 +39,7 @@ CORE_ALERT_FIELDS_PACK = "CoreAlertFields" # full path to Packs folder in content repo -PACKS_FULL_PATH = os.path.join(CONTENT_PATH, PACKS_DIR) # type: ignore +PACKS_FULL_PATH = os.path.join(ContentPaths.CONTENT_PATH, PACKS_DIR) # type: ignore def parse_for_pack_metadata( diff --git a/demisto_sdk/commands/format/update_generic_yml.py b/demisto_sdk/commands/format/update_generic_yml.py index 311a10c8304..5fca2c780cb 100644 --- a/demisto_sdk/commands/format/update_generic_yml.py +++ b/demisto_sdk/commands/format/update_generic_yml.py @@ -15,7 +15,7 @@ TEST_PLAYBOOKS_DIR, FileType, ) -from demisto_sdk.commands.common.content_constant_paths import CONF_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.handlers import DEFAULT_YAML_HANDLER as yaml from demisto_sdk.commands.common.logger import logger @@ -89,7 +89,7 @@ def _load_conf_file(self) -> Dict: Returns: The content of the json file """ - return get_file(CONF_PATH, raise_on_error=True) + return get_file(ContentPaths.CONF_PATH, raise_on_error=True) def get_id_and_version_path_object(self): """Gets the dict that holds the id and version fields. @@ -287,7 +287,7 @@ def remove_from_conf_json(self, file_type, content_item_id) -> None: conf_json_content = self._load_conf_file() except FileNotFoundError: logger.debug( - f"Unable to find {CONF_PATH} - skipping update." + f"Unable to find {ContentPaths.CONF_PATH} - skipping update." ) return conf_json_test_configuration = conf_json_content["tests"] @@ -319,7 +319,7 @@ def update_conf_json(self, file_type: str) -> None: conf_json_content = self._load_conf_file() except FileNotFoundError: logger.debug( - f"Unable to find {CONF_PATH} - skipping update." + f"Unable to find {ContentPaths.CONF_PATH} - skipping update." ) return conf_json_test_configuration = conf_json_content["tests"] @@ -354,7 +354,7 @@ def update_conf_json(self, file_type: str) -> None: def _save_to_conf_json(self, conf_json_content: Dict) -> None: """Save formatted JSON data to destination file.""" - with open(CONF_PATH, "w") as file: + with open(ContentPaths.CONF_PATH, "w") as file: json.dump(conf_json_content, file, indent=4) def update_deprecate(self, file_type=None): diff --git a/demisto_sdk/commands/init/contribution_converter.py b/demisto_sdk/commands/init/contribution_converter.py index 54e944eb4f5..2120628df03 100644 --- a/demisto_sdk/commands/init/contribution_converter.py +++ b/demisto_sdk/commands/init/contribution_converter.py @@ -34,7 +34,7 @@ ContentItems, FileType, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.handlers import YAML_Handler from demisto_sdk.commands.common.logger import logger @@ -168,7 +168,7 @@ def __init__( self.create_new = create_new self.contribution_items_version: Dict[str, Dict[str, str]] = {} self.contribution_items_version_note = "" - base_dir = base_dir or CONTENT_PATH # type: ignore + base_dir = base_dir or ContentPaths.CONTENT_PATH # type: ignore self.packs_dir_path: str = os.path.join(base_dir, "Packs") # type: ignore if not os.path.isdir(self.packs_dir_path): os.makedirs(self.packs_dir_path) diff --git a/demisto_sdk/commands/init/tests/contribution_converter_test.py b/demisto_sdk/commands/init/tests/contribution_converter_test.py index 484dfa479e9..8885d7f3306 100644 --- a/demisto_sdk/commands/init/tests/contribution_converter_test.py +++ b/demisto_sdk/commands/init/tests/contribution_converter_test.py @@ -1277,7 +1277,7 @@ def test_process_existing_pack_existing_integration_readme( import demisto_sdk.commands.init.contribution_converter as cc - cc.CONTENT_PATH = git_repo.path + cc.ContentPaths.update_content_path(git_repo.path) # Read integration python, yml code and README to create mock integration py_code_path = Path(CONTRIBUTION_TESTS, "common", "integration.py") @@ -1409,7 +1409,7 @@ def test_process_existing_pack_new_integration_readme( import demisto_sdk.commands.init.contribution_converter as cc - cc.CONTENT_PATH = git_repo.path + cc.ContentPaths.update_content_path(git_repo.path) git_repo.create_pack(self.existing_pack_name) diff --git a/demisto_sdk/commands/lint/lint_manager.py b/demisto_sdk/commands/lint/lint_manager.py index 31b2ac34755..1e747d2c677 100644 --- a/demisto_sdk/commands/lint/lint_manager.py +++ b/demisto_sdk/commands/lint/lint_manager.py @@ -22,7 +22,7 @@ TYPE_PYTHON, DemistoException, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.docker_helper import init_global_docker_client from demisto_sdk.commands.common.git_util import GitUtil from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json @@ -1351,7 +1351,7 @@ def vulture_error_formatter(self, errors: Dict, json_contents: List) -> None: """ error_messages = errors.get("messages", "") error_messages = error_messages.split("\n") if error_messages else [] - content_path = CONTENT_PATH + content_path = ContentPaths.CONTENT_PATH for message in error_messages: if message: file_name, line_number, error_contents = message.split(":", 2) diff --git a/demisto_sdk/commands/pre_commit/hooks/docker.py b/demisto_sdk/commands/pre_commit/hooks/docker.py index 67d3cc4d2b8..e28f5349d4d 100644 --- a/demisto_sdk/commands/pre_commit/hooks/docker.py +++ b/demisto_sdk/commands/pre_commit/hooks/docker.py @@ -19,7 +19,7 @@ TYPE_PWSH, TYPE_PYTHON, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH, PYTHONPATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.cpu_count import cpu_count from demisto_sdk.commands.common.docker_helper import ( DockerBase, @@ -59,7 +59,7 @@ def get_mypy_requirements(): Raises: RuntimeError: If the requirements cannot be read from GitHub. """ - mypy_requirements_path = Path(f"{CONTENT_PATH}/mypy-requirements.txt") + mypy_requirements_path = Path(f"{ContentPaths.CONTENT_PATH}/mypy-requirements.txt") if mypy_requirements_path.exists(): requirements = get_pip_requirements_from_file(mypy_requirements_path) else: @@ -88,7 +88,7 @@ def get_docker_python_path(drop_site_packages: bool = False) -> str: This means CommonServerPython's path is /src/Packs/Base/...CSP.py Returns: A PYTHONPATH formatted string """ - path_to_replace = str(Path(CONTENT_PATH).absolute()) + path_to_replace = str(Path(ContentPaths.CONTENT_PATH).absolute()) docker_path = [str(path).replace(path_to_replace, "/src") for path in PYTHONPATH] if drop_site_packages: docker_path = [p for p in docker_path if "site-packages" not in p] @@ -361,11 +361,11 @@ def prepare_hook( all_objects = {obj for _, obj in filtered_files_with_objects if obj} for obj in all_objects: for file in copy_files: - source: Path = CONTENT_PATH / file + source: Path = ContentPaths.CONTENT_PATH / file target = obj.path.parent / Path(file).name if source != target and source.exists() and not target.exists(): shutil.copy( - CONTENT_PATH / file, obj.path.parent / Path(file).name + ContentPaths.CONTENT_PATH / file, obj.path.parent / Path(file).name ) run_isolated = self._get_property("run_isolated", False) config_arg = self._get_config_file_arg() @@ -464,7 +464,7 @@ def generate_hooks( Path("/src") / ( integration_script.path.parent / config_arg[1] - ).relative_to(CONTENT_PATH) + ).relative_to(ContentPaths.CONTENT_PATH) ), ] ) @@ -477,7 +477,7 @@ def generate_hooks( ) # change the working directory to the integration script, as it runs in an isolated container hook["entry"] = ( - f"-w {Path('/src') / integration_script.path.parent.relative_to(CONTENT_PATH)} {hook['entry']}" + f"-w {Path('/src') / integration_script.path.parent.relative_to(ContentPaths.CONTENT_PATH)} {hook['entry']}" ) if self._set_files_on_hook( diff --git a/demisto_sdk/commands/pre_commit/hooks/hook.py b/demisto_sdk/commands/pre_commit/hooks/hook.py index 4472ce6db6b..3554db5e541 100644 --- a/demisto_sdk/commands/pre_commit/hooks/hook.py +++ b/demisto_sdk/commands/pre_commit/hooks/hook.py @@ -7,7 +7,7 @@ from packaging.version import Version -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.pre_commit.hooks.utils import get_property from demisto_sdk.commands.pre_commit.pre_commit_context import PreCommitContext @@ -70,7 +70,7 @@ def _set_files_on_hook( files: Iterable[Path], should_filter: bool = True, use_args: bool = False, - base_path: Path = CONTENT_PATH, + base_path: Path = ContentPaths.CONTENT_PATH, ) -> int: """ @@ -210,7 +210,7 @@ def join_files(files: Set[Path], separator: str = "|") -> str: str: The joined string. """ return separator.join( - str(file) if (CONTENT_PATH / file).is_file() else f"{str(file)}{os.sep}" + str(file) if (ContentPaths.CONTENT_PATH / file).is_file() else f"{str(file)}{os.sep}" for file in files ) diff --git a/demisto_sdk/commands/pre_commit/hooks/pycln.py b/demisto_sdk/commands/pre_commit/hooks/pycln.py index 8533fcf6e8c..c59bf6220e3 100644 --- a/demisto_sdk/commands/pre_commit/hooks/pycln.py +++ b/demisto_sdk/commands/pre_commit/hooks/pycln.py @@ -1,4 +1,4 @@ -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH, PYTHONPATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.pre_commit.hooks.hook import ( GeneratedHooks, Hook, @@ -18,8 +18,8 @@ def prepare_hook(self) -> GeneratedHooks: """ paths_to_skip = tuple( path.name - for path in PYTHONPATH - if path.absolute() != CONTENT_PATH.absolute() + for path in ContentPaths.PYTHONPATH + if path.absolute() != ContentPaths.CONTENT_PATH.absolute() ) builtins_to_skip = ("demisto", "CommonServerUserPython") diff --git a/demisto_sdk/commands/pre_commit/hooks/sourcery.py b/demisto_sdk/commands/pre_commit/hooks/sourcery.py index 1ae798ce45d..67e5c669969 100644 --- a/demisto_sdk/commands/pre_commit/hooks/sourcery.py +++ b/demisto_sdk/commands/pre_commit/hooks/sourcery.py @@ -4,7 +4,7 @@ from typing import Any, Dict from demisto_sdk.commands.common import tools -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.pre_commit.hooks.hook import GeneratedHooks, Hook, join_files @@ -32,7 +32,7 @@ def prepare_hook(self) -> GeneratedHooks: Returns: None """ - config_file = CONTENT_PATH / self._get_property("config_file", ".sourcery.yml") + config_file = ContentPaths.CONTENT_PATH / self._get_property("config_file", ".sourcery.yml") if not config_file.exists(): return [] self.base_hook.pop("config_file", None) diff --git a/demisto_sdk/commands/pre_commit/pre_commit_command.py b/demisto_sdk/commands/pre_commit/pre_commit_command.py index 6d5e77c06c8..0c1fc426f8c 100644 --- a/demisto_sdk/commands/pre_commit/pre_commit_command.py +++ b/demisto_sdk/commands/pre_commit/pre_commit_command.py @@ -19,7 +19,7 @@ PACKS_FOLDER, SCRIPTS_DIR, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH, PYTHONPATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.cpu_count import cpu_count from demisto_sdk.commands.common.git_util import GitUtil from demisto_sdk.commands.common.logger import logger @@ -184,7 +184,7 @@ def _run_pre_commit_process( ) ), env=precommit_env, - cwd=CONTENT_PATH, + cwd=ContentPaths.CONTENT_PATH, stdout=stdout, stderr=stdout, universal_newlines=True, @@ -301,12 +301,12 @@ def prepare_and_run( ret_val = 0 pre_commit_context.dry_run = dry_run precommit_env = os.environ.copy() - precommit_env["PYTHONPATH"] = ":".join(str(path) for path in PYTHONPATH) + precommit_env["PYTHONPATH"] = ":".join(str(path) for path in ContentPaths.PYTHONPATH) # The PYTHONPATH should be the same as the PYTHONPATH, but without the site-packages because MYPY does not support it precommit_env["MYPYPATH"] = ":".join( - str(path) for path in sorted(PYTHONPATH) if "site-packages" not in str(path) + str(path) for path in sorted(ContentPaths.PYTHONPATH) if "site-packages" not in str(path) ) - precommit_env["DEMISTO_SDK_CONTENT_PATH"] = str(CONTENT_PATH) + precommit_env["DEMISTO_SDK_CONTENT_PATH"] = str(ContentPaths.CONTENT_PATH) precommit_env["SYSTEMD_COLORS"] = "1" # for colorful output precommit_env["PRE_COMMIT_COLOR"] = "always" @@ -383,7 +383,7 @@ def group_by_language( ) if not find_path_index: raise Exception(f"Could not find Integrations/Scripts path for {file}") - code_file_path = CONTENT_PATH / Path( + code_file_path = ContentPaths.CONTENT_PATH / Path( *file.parts[: next(find_path_index) + 1] ) if not code_file_path.is_dir(): @@ -429,12 +429,12 @@ def group_by_language( add_related_files( api_module.path if not api_module.path.is_absolute() - else api_module.path.relative_to(CONTENT_PATH) + else api_module.path.relative_to(ContentPaths.CONTENT_PATH) ) | add_related_files( imported_by.path if not imported_by.path.is_absolute() - else imported_by.path.relative_to(CONTENT_PATH) + else imported_by.path.relative_to(ContentPaths.CONTENT_PATH) ) ) logger.debug("Pre-Commit: Finished handling API Modules") @@ -447,11 +447,11 @@ def group_by_language( # the reason we maintain this set is for performance when running with --all-files. It is much faster to exclude. if integration_script.is_unified: exclude_integration_script.add( - integration_script.path.relative_to(CONTENT_PATH) + integration_script.path.relative_to(ContentPaths.CONTENT_PATH) ) else: exclude_integration_script.add( - integration_script.path.parent.relative_to(CONTENT_PATH) + integration_script.path.parent.relative_to(ContentPaths.CONTENT_PATH) ) continue @@ -468,7 +468,7 @@ def group_by_language( }, { ( - integration_script.path.relative_to(CONTENT_PATH) + integration_script.path.relative_to(ContentPaths.CONTENT_PATH) if integration_script.path.is_absolute() else integration_script.path, integration_script, @@ -532,7 +532,7 @@ def pre_commit_manager( int: Return code of pre-commit. """ # We have imports to this module, however it does not exists in the repo. - (CONTENT_PATH / "CommonServerUserPython.py").touch() + (ContentPaths.CONTENT_PATH / "CommonServerUserPython.py").touch() if not any((input_files, staged_only, git_diff, all_files)): logger.info("No arguments were given, running on staged files and git changes.") @@ -689,7 +689,7 @@ def preprocess_files( files_to_run.update(add_related_files(file)) # convert to relative file to content path relative_paths = { - file.relative_to(CONTENT_PATH) if file.is_absolute() else file + file.relative_to(ContentPaths.CONTENT_PATH) if file.is_absolute() else file for file in files_to_run } # filter out files that are not in the content git repo (e.g in .gitignore) diff --git a/demisto_sdk/commands/pre_commit/pre_commit_context.py b/demisto_sdk/commands/pre_commit/pre_commit_context.py index f28555bbe2f..4da8455898d 100644 --- a/demisto_sdk/commands/pre_commit/pre_commit_context.py +++ b/demisto_sdk/commands/pre_commit/pre_commit_context.py @@ -8,7 +8,7 @@ from typing import Dict, List, Optional, Set, Tuple from demisto_sdk.commands.common.constants import CACHE_DIR -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import ( get_file_or_remote, @@ -23,7 +23,7 @@ IS_GITHUB_ACTIONS = string_to_bool(os.getenv("GITHUB_ACTIONS"), False) PRECOMMIT_TEMPLATE_NAME = ".pre-commit-config_template.yaml" -PRECOMMIT_TEMPLATE_PATH = CONTENT_PATH / PRECOMMIT_TEMPLATE_NAME +PRECOMMIT_TEMPLATE_PATH = ContentPaths.CONTENT_PATH / PRECOMMIT_TEMPLATE_NAME PATH = Path(__file__).parents[0].resolve() DEFAULT_PRE_COMMIT_TEMPLATE_PATH = PATH / PRECOMMIT_TEMPLATE_NAME @@ -34,7 +34,7 @@ HOOK_LOG_PATH = Path(ARTIFACTS_FOLDER) / "pre-commit" if ARTIFACTS_FOLDER else None # This has to be relative to content path so the docker will be able to write to it -PRE_COMMIT_FOLDER_SHARED = CONTENT_PATH / ".pre-commit" +PRE_COMMIT_FOLDER_SHARED = ContentPaths.CONTENT_PATH / ".pre-commit" @dataclass diff --git a/demisto_sdk/commands/setup_env/setup_environment.py b/demisto_sdk/commands/setup_env/setup_environment.py index 2bb5ab9ab24..9d4a0355828 100644 --- a/demisto_sdk/commands/setup_env/setup_environment.py +++ b/demisto_sdk/commands/setup_env/setup_environment.py @@ -20,12 +20,7 @@ get_client_from_server_type, ) from demisto_sdk.commands.common.constants import DEF_DOCKER -from demisto_sdk.commands.common.content_constant_paths import ( - COMMON_SERVER_PYTHON_PATH, - CONTENT_PATH, - PYTHONPATH, - PYTHONPATH_STR, -) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.docker.docker_image import DockerImage from demisto_sdk.commands.common.files import FileReadError, TextFile from demisto_sdk.commands.common.handlers import DEFAULT_JSON5_HANDLER as json5 @@ -43,7 +38,7 @@ from demisto_sdk.commands.content_graph.objects.pack import Pack BACKUP_FILES_SUFFIX = ".demisto_sdk_backup" -DOTENV_PATH = CONTENT_PATH / ".env" +DOTENV_PATH = ContentPaths.CONTENT_PATH / ".env" class IDEType(Enum): @@ -69,14 +64,14 @@ def configure_vscode_settings( settings["python.defaultInterpreterPath"] = str(interpreter_path) if integration_script: if devcontainer: - testing_path = f"workspaces/content/{integration_script.path.parent.relative_to(CONTENT_PATH)}" + testing_path = f"workspaces/content/{integration_script.path.parent.relative_to(ContentPaths.CONTENT_PATH)}" else: testing_path = str(integration_script.path.parent) settings["python.testing.cwd"] = testing_path if devcontainer: python_path = get_docker_python_path("/workspaces/content") else: - python_path = [str(path) for path in PYTHONPATH if str(path)] + python_path = [str(path) for path in ContentPaths.PYTHONPATH if str(path)] settings["python.analysis.extraPaths"] = [ path for path in python_path if "site-packages" not in path @@ -87,11 +82,11 @@ def configure_vscode_settings( def get_docker_python_path(docker_prefix: str) -> List[str]: docker_python_path = [] - for path in PYTHONPATH: + for path in ContentPaths.PYTHONPATH: with contextlib.suppress(ValueError): # we can't add paths which is not relative to CONTENT_PATH, and `is_relative_to is not working on python3.8` docker_python_path.append( - f"{docker_prefix}/{path.relative_to(CONTENT_PATH.absolute())}" + f"{docker_prefix}/{path.relative_to(ContentPaths.CONTENT_PATH.absolute())}" ) if ( @@ -100,22 +95,22 @@ def get_docker_python_path(docker_prefix: str) -> List[str]: ): try: common_server_python_contnet = TextFile.read_from_github_api( - str(COMMON_SERVER_PYTHON_PATH / "CommonServerUserPython.py"), + str(ContentPaths.COMMON_SERVER_PYTHON_PATH / "CommonServerUserPython.py"), verify_ssl=False, ) except (FileReadError, ConnectionError, Timeout): logger.error( - f"Could not retrieve common server python content from content github from path {COMMON_SERVER_PYTHON_PATH}/CommonServerUserPython.py" + f"Could not retrieve common server python content from content github from path {ContentPaths.COMMON_SERVER_PYTHON_PATH}/CommonServerUserPython.py" ) raise RuntimeError( "Could not set debug-in-docker on VSCode. Either CONTENT_PATH is not set properly or CommonServerPython could not be read" ) - Path(COMMON_SERVER_PYTHON_PATH).mkdir(parents=True, exist_ok=True) + Path(ContentPaths.COMMON_SERVER_PYTHON_PATH).mkdir(parents=True, exist_ok=True) TextFile.write( common_server_python_contnet, - output_path=COMMON_SERVER_PYTHON_PATH / "CommonServerUserPython.py", + output_path=ContentPaths.COMMON_SERVER_PYTHON_PATH / "CommonServerUserPython.py", ) docker_python_path.append( @@ -243,7 +238,7 @@ def update_pycharm_config_xml_data( for python_path in python_discovery_paths: try: - python_path_relative = python_path.relative_to(CONTENT_PATH) + python_path_relative = python_path.relative_to(ContentPaths.CONTENT_PATH) except ValueError: # Skip paths that are not within the project root logger.debug( @@ -275,23 +270,23 @@ def configure_module_discovery(ide_type: IDEType): ide_type (IDEType): The IDE type to configure """ if ide_type == IDEType.VSCODE: - ide_folder = CONTENT_PATH / ".vscode" + ide_folder = ContentPaths.CONTENT_PATH / ".vscode" ide_folder.mkdir(exist_ok=True, parents=True) configure_vscode_settings(ide_folder=ide_folder) - env_file = CONTENT_PATH / ".env" + env_file = ContentPaths.CONTENT_PATH / ".env" env_vars = dotenv.dotenv_values(env_file) - env_vars["PYTHONPATH"] = PYTHONPATH_STR + env_vars["PYTHONPATH"] = ContentPaths.PYTHONPATH_STR update_dotenv(DOTENV_PATH, env_vars) if ide_type == IDEType.PYCHARM: - python_discovery_paths = PYTHONPATH.copy() + python_discovery_paths = ContentPaths.PYTHONPATH.copy() # Remove 'CONTENT_PATH' from the python discovery paths as it is already configured by default, # and all the configured paths are relative to the project root (which is 'CONTENT_PATH'). - if CONTENT_PATH in python_discovery_paths: - python_discovery_paths.remove(CONTENT_PATH) + if ContentPaths.CONTENT_PATH in python_discovery_paths: + python_discovery_paths.remove(ContentPaths.CONTENT_PATH) - config_file_path = CONTENT_PATH / ".idea" / f"{CONTENT_PATH.name.lower()}.iml" + config_file_path = ContentPaths.CONTENT_PATH / ".idea" / f"{ContentPaths.CONTENT_PATH.name.lower()}.iml" update_pycharm_config_file( file_path=config_file_path, python_discovery_paths=python_discovery_paths, @@ -317,12 +312,12 @@ def build_tasks(): "image": integration_script.docker_image, "volumes": [ { - "localPath": str(CONTENT_PATH), - "containerPath": str(CONTENT_PATH), + "localPath": str(ContentPaths.CONTENT_PATH), + "containerPath": str(ContentPaths.CONTENT_PATH), } ], "env": { - "PYTHONPATH": PYTHONPATH_STR, + "PYTHONPATH": ContentPaths.PYTHONPATH_STR, }, }, }, @@ -346,12 +341,12 @@ def build_tasks(): "image": test_docker_image, "volumes": [ { - "localPath": str(CONTENT_PATH), - "containerPath": str(CONTENT_PATH), + "localPath": str(ContentPaths.CONTENT_PATH), + "containerPath": str(ContentPaths.CONTENT_PATH), } ], "customOptions": f"-w {integration_script.path.parent}", - "env": {"PYTHONPATH": PYTHONPATH_STR}, + "env": {"PYTHONPATH": ContentPaths.PYTHONPATH_STR}, }, }, ], @@ -374,7 +369,7 @@ def build_launch(): "type": "PowerShell", "request": "launch", "script": ( - f"/workspaces/content/{integration_script.path.relative_to(CONTENT_PATH)}" + f"/workspaces/content/{integration_script.path.relative_to(ContentPaths.CONTENT_PATH)}" if devcontainer else str(integration_script.path.with_suffix(".ps1")) ), @@ -394,8 +389,8 @@ def build_launch(): "python": { "pathMappings": [ { - "localRoot": str(CONTENT_PATH), - "remoteRoot": str(CONTENT_PATH), + "localRoot": str(ContentPaths.CONTENT_PATH), + "remoteRoot": str(ContentPaths.CONTENT_PATH), } ], "projectType": "general", @@ -410,8 +405,8 @@ def build_launch(): "python": { "pathMappings": [ { - "localRoot": str(CONTENT_PATH), - "remoteRoot": str(CONTENT_PATH), + "localRoot": str(ContentPaths.CONTENT_PATH), + "remoteRoot": str(ContentPaths.CONTENT_PATH), }, ], "projectType": "general", @@ -423,14 +418,14 @@ def build_launch(): "type": "debugpy", "request": "launch", "program": ( - f"/workspaces/content/{integration_script.path.relative_to(CONTENT_PATH)}" + f"/workspaces/content/{integration_script.path.relative_to(ContentPaths.CONTENT_PATH)}" if devcontainer else str(integration_script.path.with_suffix(".py")) ), "console": "integratedTerminal", "cwd": "${workspaceFolder}", "justMyCode": False, - "env": {"PYTHONPATH": PYTHONPATH_STR}, + "env": {"PYTHONPATH": ContentPaths.PYTHONPATH_STR}, }, { "name": "Python: Debug Tests", @@ -440,7 +435,7 @@ def build_launch(): "purpose": ["debug-test"], "console": "integratedTerminal", "justMyCode": False, - "env": {"PYTHONPATH": PYTHONPATH_STR}, + "env": {"PYTHONPATH": ContentPaths.PYTHONPATH_STR}, }, ], } @@ -694,7 +689,7 @@ def upload_and_create_instance( def add_demistomock_and_commonserveruser(integration_script: IntegrationScript): - source_demisto_mock_path = CONTENT_PATH / "Tests" / "demistomock" / "demistomock.py" + source_demisto_mock_path = ContentPaths.CONTENT_PATH / "Tests" / "demistomock" / "demistomock.py" target_demisto_mock_path = integration_script.path.parent / "demistomock.py" if source_demisto_mock_path.exists(): shutil.copy( @@ -738,7 +733,7 @@ def configure_integration( RuntimeError: If using auto-detection for IDE and it failed, or if the configuration failed (for instance, Docker is turned off) """ - base_path = CONTENT_PATH + base_path = ContentPaths.CONTENT_PATH integration_script = BaseContent.from_path(Path(file_path)) assert isinstance( @@ -746,7 +741,7 @@ def configure_integration( ), "Expected Integration Script" add_demistomock_and_commonserveruser(integration_script) docker_image: Union[str, DockerImage] = integration_script.docker_image - interpreter_path = CONTENT_PATH / ".venv" / "bin" / "python" + interpreter_path = ContentPaths.CONTENT_PATH / ".venv" / "bin" / "python" configure_params(integration_script, secret_id, instance_name, test_module) if not docker_image: docker_image = DEF_DOCKER @@ -796,13 +791,13 @@ def clean_repo(): """ Clean the repository from temporary files like 'CommonServerPython' and API modules created by the 'lint' command. """ - for path in PYTHONPATH: - for temp_file in CONTENT_PATH.rglob(f"{path.name}.py"): + for path in ContentPaths.PYTHONPATH: + for temp_file in ContentPaths.CONTENT_PATH.rglob(f"{path.name}.py"): if temp_file.parent != path and ".venv" not in temp_file.parts: temp_file.unlink(missing_ok=True) - for path in CONTENT_PATH.rglob("*.pyc"): + for path in ContentPaths.CONTENT_PATH.rglob("*.pyc"): path.unlink(missing_ok=True) - for path in CONTENT_PATH.rglob("test_data/__init__.py"): + for path in ContentPaths.CONTENT_PATH.rglob("test_data/__init__.py"): path.unlink(missing_ok=True) @@ -837,9 +832,9 @@ def setup_env( configure_module_discovery(ide_type=ide_type) if not file_paths: - (CONTENT_PATH / "CommonServerUserPython.py").touch() + (ContentPaths.CONTENT_PATH / "CommonServerUserPython.py").touch() if ide_type == IDEType.VSCODE: - ide_folder = CONTENT_PATH / ".vscode" + ide_folder = ContentPaths.CONTENT_PATH / ".vscode" ide_folder.mkdir(exist_ok=True) configure_vscode_settings(ide_folder=ide_folder) for file_path in file_paths: diff --git a/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py b/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py index 1e4dc215ada..ee68d4efb52 100644 --- a/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py +++ b/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py @@ -34,7 +34,7 @@ ModelingRule, SingleModelingRule, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.logger import ( handle_deprecated_args, @@ -142,8 +142,8 @@ def get_relative_path_to_content(path: Path) -> str: Returns: Path: The relative path to the content directory. """ - if path.is_absolute() and path.as_posix().startswith(CONTENT_PATH.as_posix()): - return path.as_posix().replace(f"{CONTENT_PATH.as_posix()}{os.path.sep}", "") + if path.is_absolute() and path.as_posix().startswith(ContentPaths.CONTENT_PATH.as_posix()): + return path.as_posix().replace(f"{ContentPaths.CONTENT_PATH.as_posix()}{os.path.sep}", "") return path.as_posix() diff --git a/demisto_sdk/commands/test_content/test_modeling_rule/tests/test_modeling_rule_test.py b/demisto_sdk/commands/test_content/test_modeling_rule/tests/test_modeling_rule_test.py index 780aba20fac..82b8f87df56 100644 --- a/demisto_sdk/commands/test_content/test_modeling_rule/tests/test_modeling_rule_test.py +++ b/demisto_sdk/commands/test_content/test_modeling_rule/tests/test_modeling_rule_test.py @@ -6,13 +6,13 @@ import typer from freezegun import freeze_time -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths DEFAULT_TEST_EVENT_ID = UUID("00000000-0000-0000-0000-000000000000") class ModelingRuleMock: - path = Path(CONTENT_PATH) + path = Path(ContentPaths.CONTENT_PATH) def normalize_file_name(self): return "test_modeling_rule.yml" diff --git a/demisto_sdk/commands/validate/old_validate_manager.py b/demisto_sdk/commands/validate/old_validate_manager.py index b117b216914..2807a02d972 100644 --- a/demisto_sdk/commands/validate/old_validate_manager.py +++ b/demisto_sdk/commands/validate/old_validate_manager.py @@ -34,10 +34,7 @@ PathLevel, ) from demisto_sdk.commands.common.content import Content -from demisto_sdk.commands.common.content_constant_paths import ( - CONTENT_PATH, - DEFAULT_ID_SET_PATH, -) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.cpu_count import cpu_count from demisto_sdk.commands.common.errors import ( FOUND_FILES_AND_ERRORS, @@ -255,7 +252,7 @@ def __init__( specific_validations=specific_validations ).should_run_validation self.file_path = file_path - self.id_set_path = id_set_path or DEFAULT_ID_SET_PATH + self.id_set_path = id_set_path or ContentPaths.DEFAULT_ID_SET_PATH # create the id_set only once per run. self.id_set_file = self.get_id_set_file( self.skip_id_set_creation, self.id_set_path @@ -359,7 +356,7 @@ def is_node_exist(self) -> bool: bool: True if node exist, else False """ # Check node exist - content_path = CONTENT_PATH + content_path = ContentPaths.CONTENT_PATH stdout, stderr, exit_code = run_command_os("node -v", cwd=content_path) # type: ignore if exit_code: return False @@ -911,7 +908,7 @@ def run_validations_on_file( ReadMeValidator.add_node_env_vars() if ( not ReadMeValidator.are_modules_installed_for_verify( - CONTENT_PATH # type: ignore + ContentPaths.CONTENT_PATH # type: ignore ) and not ReadMeValidator.is_docker_available() ): # shows warning message diff --git a/demisto_sdk/commands/validate/tests/old_validators_test.py b/demisto_sdk/commands/validate/tests/old_validators_test.py index 53825b958c3..10b9c0e3633 100644 --- a/demisto_sdk/commands/validate/tests/old_validators_test.py +++ b/demisto_sdk/commands/validate/tests/old_validators_test.py @@ -19,7 +19,7 @@ FileType, ) from demisto_sdk.commands.common.content.content import Content -from demisto_sdk.commands.common.content_constant_paths import CONF_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.errors import Errors from demisto_sdk.commands.common.git_util import GitUtil from demisto_sdk.commands.common.hook_validations.base_validator import BaseValidator @@ -184,11 +184,11 @@ def setup_class(cls): if not Path(dir_to_create).exists(): cls.CREATED_DIRS.append(dir_to_create) os.makedirs(dir_to_create) - copyfile(CONF_JSON_MOCK_PATH, CONF_PATH) + copyfile(CONF_JSON_MOCK_PATH, ContentPaths.CONF_PATH) @classmethod def teardown_class(cls): - Path(CONF_PATH).unlink() + Path(ContentPaths.CONF_PATH).unlink() for dir_to_delete in cls.CREATED_DIRS: if Path(dir_to_delete).exists(): os.rmdir(dir_to_delete) diff --git a/demisto_sdk/commands/validate/tests/validators_test.py b/demisto_sdk/commands/validate/tests/validators_test.py index 3913c3d8570..eddf07189f0 100644 --- a/demisto_sdk/commands/validate/tests/validators_test.py +++ b/demisto_sdk/commands/validate/tests/validators_test.py @@ -14,7 +14,7 @@ ExecutionMode, GitStatuses, ) -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.git_util import GitUtil from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.content_graph.common import ContentType @@ -65,7 +65,7 @@ INTEGRATION = create_integration_object() INTEGRATION.path = Path( - f"{CONTENT_PATH}/Packs/pack_0/Integrations/integration_0/integration_0.yml" + f"{ContentPaths.CONTENT_PATH}/Packs/pack_0/Integrations/integration_0/integration_0.yml" ) diff --git a/demisto_sdk/commands/validate/validators/GR_validators/GR101_is_using_invalid_from_version.py b/demisto_sdk/commands/validate/validators/GR_validators/GR101_is_using_invalid_from_version.py index a85f7ecb7a3..93c542a2f0a 100644 --- a/demisto_sdk/commands/validate/validators/GR_validators/GR101_is_using_invalid_from_version.py +++ b/demisto_sdk/commands/validate/validators/GR_validators/GR101_is_using_invalid_from_version.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Iterable, List, Union -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.objects import ( CaseField, CaseLayout, @@ -98,7 +98,7 @@ def obtain_invalid_content_items_using_graph( [] if validate_all_files else [ - str(content_item.path.relative_to(CONTENT_PATH)) + str(content_item.path.relative_to(ContentPaths.CONTENT_PATH)) for content_item in content_items ] ) diff --git a/demisto_sdk/commands/validate/validators/GR_validators/GR103_is_using_unknown_content.py b/demisto_sdk/commands/validate/validators/GR_validators/GR103_is_using_unknown_content.py index 98b4d9d2bd2..2393c662cb1 100644 --- a/demisto_sdk/commands/validate/validators/GR_validators/GR103_is_using_unknown_content.py +++ b/demisto_sdk/commands/validate/validators/GR_validators/GR103_is_using_unknown_content.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Iterable, List, Union -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.objects.case_field import CaseField from demisto_sdk.commands.content_graph.objects.case_layout import CaseLayout from demisto_sdk.commands.content_graph.objects.case_layout_rule import CaseLayoutRule @@ -91,7 +91,7 @@ def obtain_invalid_content_items_using_graph( results: List[ValidationResult] = [] file_paths_to_validate = ( [ - str(content_item.path.relative_to(CONTENT_PATH)) + str(content_item.path.relative_to(ContentPaths.CONTENT_PATH)) for content_item in content_items ] if not validate_all_files diff --git a/demisto_sdk/commands/validate/validators/GR_validators/GR104_is_pack_display_name_already_exists.py b/demisto_sdk/commands/validate/validators/GR_validators/GR104_is_pack_display_name_already_exists.py index 941a5bfa465..ca277e47369 100644 --- a/demisto_sdk/commands/validate/validators/GR_validators/GR104_is_pack_display_name_already_exists.py +++ b/demisto_sdk/commands/validate/validators/GR_validators/GR104_is_pack_display_name_already_exists.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Iterable, List -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.objects.pack import Pack from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType from demisto_sdk.commands.validate.validators.base_validator import ( @@ -31,7 +31,7 @@ def obtain_invalid_content_items_using_graph( self, content_items: Iterable[ContentTypes], validate_all_files: bool ) -> List[ValidationResult]: file_paths_to_objects = { - str(content_item.path.relative_to(CONTENT_PATH)): content_item + str(content_item.path.relative_to(ContentPaths.CONTENT_PATH)): content_item for content_item in content_items } content_id_to_objects = {item.object_id: item for item in content_items} # type: ignore[attr-defined] diff --git a/demisto_sdk/commands/validate/validators/GR_validators/GR105_duplicate_content_id.py b/demisto_sdk/commands/validate/validators/GR_validators/GR105_duplicate_content_id.py index 9776e29e45d..cc6d10336eb 100644 --- a/demisto_sdk/commands/validate/validators/GR_validators/GR105_duplicate_content_id.py +++ b/demisto_sdk/commands/validate/validators/GR_validators/GR105_duplicate_content_id.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import Iterable, List, Union -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.objects.case_field import CaseField from demisto_sdk.commands.content_graph.objects.case_layout import CaseLayout from demisto_sdk.commands.content_graph.objects.case_layout_rule import CaseLayoutRule @@ -93,7 +93,7 @@ def obtain_invalid_content_items_using_graph( [] if validate_all_files else [ - str(content_item.path.relative_to(CONTENT_PATH)) + str(content_item.path.relative_to(ContentPaths.CONTENT_PATH)) for content_item in content_items ] ) @@ -102,7 +102,7 @@ def obtain_invalid_content_items_using_graph( validator=self, message=self.error_message.format( content_item.object_id, - Path(duplicate.path).relative_to(CONTENT_PATH), # type: ignore[attr-defined] + Path(duplicate.path).relative_to(ContentPaths.CONTENT_PATH), # type: ignore[attr-defined] ), content_object=content_item, # type: ignore[arg-type] ) diff --git a/demisto_sdk/commands/validate/validators/GR_validators/GR106_is_testplaybook_in_use.py b/demisto_sdk/commands/validate/validators/GR_validators/GR106_is_testplaybook_in_use.py index 93874ce72ff..0cd4dd93cf3 100644 --- a/demisto_sdk/commands/validate/validators/GR_validators/GR106_is_testplaybook_in_use.py +++ b/demisto_sdk/commands/validate/validators/GR_validators/GR106_is_testplaybook_in_use.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Iterable, List -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.objects.conf_json import ConfJSON from demisto_sdk.commands.content_graph.objects.test_playbook import TestPlaybook from demisto_sdk.commands.validate.validators.base_validator import ( @@ -31,7 +31,7 @@ class IsTestPlaybookInUseValidator(BaseValidator[ContentTypes], ABC): def obtain_invalid_content_items_using_graph( self, content_items: Iterable[ContentTypes], validate_all_files: bool ) -> List[ValidationResult]: - conf_data = ConfJSON.from_path(CONTENT_PATH / "Tests/conf.json") + conf_data = ConfJSON.from_path(ContentPaths.CONTENT_PATH / "Tests/conf.json") test_playbooks_ids_to_skip = list( set(conf_data.skipped_tests.keys()) | set(conf_data.reputation_tests) ) diff --git a/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py b/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py index 4ead651f044..3d04b953d8a 100644 --- a/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py +++ b/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Iterable, List, Union -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.objects.case_field import CaseField from demisto_sdk.commands.content_graph.objects.case_layout import CaseLayout from demisto_sdk.commands.content_graph.objects.case_layout_rule import CaseLayoutRule @@ -95,7 +95,7 @@ def obtain_invalid_content_items_using_graph( [] if validate_all_files else [ - str(content_item.path.relative_to(CONTENT_PATH)) + str(content_item.path.relative_to(ContentPaths.CONTENT_PATH)) for content_item in content_items ] ) @@ -106,7 +106,7 @@ def obtain_invalid_content_items_using_graph( deprecated_item_type=item.deprecated_item_type, deprecated_item=item.deprecated_item_id, using_deprecated_item=str( - item_using_deprecated.path.relative_to(CONTENT_PATH) + item_using_deprecated.path.relative_to(ContentPaths.CONTENT_PATH) ), ), content_object=item_using_deprecated, diff --git a/demisto_sdk/commands/validate/validators/SC_validators/SC109_script_name_is_not_unique_validator.py b/demisto_sdk/commands/validate/validators/SC_validators/SC109_script_name_is_not_unique_validator.py index 24bad9b77a1..57baa11d53e 100644 --- a/demisto_sdk/commands/validate/validators/SC_validators/SC109_script_name_is_not_unique_validator.py +++ b/demisto_sdk/commands/validate/validators/SC_validators/SC109_script_name_is_not_unique_validator.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Iterable, List -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.tools import replace_incident_to_alert from demisto_sdk.commands.content_graph.objects.script import Script from demisto_sdk.commands.validate.validators.base_validator import ( @@ -38,7 +38,7 @@ def obtain_invalid_content_items_using_graph( when the script name included `alert`. """ file_paths_to_objects = { - str(content_item.path.relative_to(CONTENT_PATH)): content_item + str(content_item.path.relative_to(ContentPaths.CONTENT_PATH)): content_item for content_item in content_items } query_list = list(file_paths_to_objects) if not validate_all_files else [] diff --git a/demisto_sdk/commands/validate/validators/base_validator.py b/demisto_sdk/commands/validate/validators/base_validator.py index 4bf68b6bc52..6280f6ba203 100644 --- a/demisto_sdk/commands/validate/validators/base_validator.py +++ b/demisto_sdk/commands/validate/validators/base_validator.py @@ -15,7 +15,7 @@ from pydantic import BaseModel from demisto_sdk.commands.common.constants import ExecutionMode, GitStatuses -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import is_abstract_class from demisto_sdk.commands.content_graph.commands.update import update_content_graph @@ -226,13 +226,13 @@ class BaseResult(BaseModel): def format_readable_message(self): path: Path = self.content_object.path if path.is_absolute(): - path = path.relative_to(CONTENT_PATH) + path = path.relative_to(ContentPaths.CONTENT_PATH) return f"{str(path)}: [{self.validator.error_code}] - {self.message}" @property def format_json_message(self): return { - "file path": str(self.content_object.path.relative_to(CONTENT_PATH)), + "file path": str(self.content_object.path.relative_to(ContentPaths.CONTENT_PATH)), "error code": self.validator.error_code, "message": self.message, } @@ -293,13 +293,13 @@ class InvalidContentItemResult(BaseResult, BaseModel): def format_readable_message(self): path: Path = self.path if path.is_absolute(): - path = path.relative_to(CONTENT_PATH) + path = path.relative_to(ContentPaths.CONTENT_PATH) return f"{path}: [{self.error_code}] - {self.message}" @property def format_json_message(self): return { - "file path": str(self.path.relative_to(CONTENT_PATH)), + "file path": str(self.path.relative_to(ContentPaths.CONTENT_PATH)), "error code": self.error_code, "message": self.message, } diff --git a/demisto_sdk/commands/xsoar_linter/xsoar_linter.py b/demisto_sdk/commands/xsoar_linter/xsoar_linter.py index eebd5c98598..67389571bb3 100644 --- a/demisto_sdk/commands/xsoar_linter/xsoar_linter.py +++ b/demisto_sdk/commands/xsoar_linter/xsoar_linter.py @@ -9,7 +9,7 @@ from packaging.version import Version -from demisto_sdk.commands.common.content_constant_paths import PYTHONPATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.cpu_count import cpu_count from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.content_graph.objects import Integration, Script @@ -122,7 +122,7 @@ def build_xsoar_linter_env_var(integration_script: IntegrationScript) -> dict: xsoar_linter_env["commands"] = ",".join( [command.name for command in integration_script.commands] ) - xsoar_linter_env["PYTHONPATH"] = ":".join(str(path) for path in PYTHONPATH) + xsoar_linter_env["PYTHONPATH"] = ":".join(str(path) for path in ContentPaths.PYTHONPATH) return xsoar_linter_env diff --git a/demisto_sdk/scripts/merge_pytest_reports.py b/demisto_sdk/scripts/merge_pytest_reports.py index 3aee643ffea..bebb49d71f2 100644 --- a/demisto_sdk/scripts/merge_pytest_reports.py +++ b/demisto_sdk/scripts/merge_pytest_reports.py @@ -6,10 +6,10 @@ import coverage from junitparser import JUnitXml -from demisto_sdk.commands.common.content_constant_paths import CONTENT_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.logger import logger, logging_setup -PRECOMMIT_FOLDER = CONTENT_PATH / ".pre-commit" +PRECOMMIT_FOLDER = ContentPaths.CONTENT_PATH / ".pre-commit" def fix_coverage_report_path(coverage_file: Path) -> bool: @@ -41,7 +41,7 @@ def fix_coverage_report_path(coverage_file: Path) -> bool: continue file = Path(file).relative_to("/src") if ( - not (CONTENT_PATH / file).exists() + not (ContentPaths.CONTENT_PATH / file).exists() or file.parent.name != file.stem # For example, in `QRadar_v3` directory we only care for `QRadar_v3.py` ): @@ -52,7 +52,7 @@ def fix_coverage_report_path(coverage_file: Path) -> bool: else: cursor.execute( "UPDATE file SET path = ? WHERE id = ?", - (str(CONTENT_PATH / file), id_), + (str(ContentPaths.CONTENT_PATH / file), id_), ) sql_connection.commit() logger.debug("Done editing coverage report") @@ -66,7 +66,7 @@ def fix_coverage_report_path(coverage_file: Path) -> bool: def merge_coverage_report(): - coverage_path = CONTENT_PATH / ".coverage" + coverage_path = ContentPaths.CONTENT_PATH / ".coverage" coverage_path.unlink(missing_ok=True) cov = coverage.Coverage(data_file=coverage_path) # this is the path where the pre-commit created the coverage files @@ -93,7 +93,7 @@ def merge_junit_reports(): report = reports[0] for rep in reports[1:]: report += rep - report.write(str(CONTENT_PATH / ".report_pytest.xml")) + report.write(str(ContentPaths.CONTENT_PATH / ".report_pytest.xml")) for file in report_files: Path(file).unlink(missing_ok=True) logger.info("Junit report was successfully merged.") diff --git a/demisto_sdk/scripts/validate_conf_json.py b/demisto_sdk/scripts/validate_conf_json.py index f7022001f30..e1b545ec5b3 100644 --- a/demisto_sdk/scripts/validate_conf_json.py +++ b/demisto_sdk/scripts/validate_conf_json.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import List, Optional, cast -from demisto_sdk.commands.common.content_constant_paths import CONF_PATH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.logger import logger, logging_setup from demisto_sdk.commands.common.tools import string_to_bool from demisto_sdk.commands.content_graph.commands.update import update_content_graph @@ -15,7 +15,7 @@ class ConfJsonValidator: def __init__( self, - conf_json_path: Path = CONF_PATH, + conf_json_path: Path = ContentPaths.CONF_PATH, graph: Optional[ContentGraphInterface] = None, # Pass None to generate ) -> None: self._conf_path = conf_json_path From be4f402dcd4cdb933db735ef976376e776fffd5f Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 21:42:27 +0200 Subject: [PATCH 07/59] complete content paths replacement --- .../commands/content_graph/objects/pack_metadata.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/demisto_sdk/commands/content_graph/objects/pack_metadata.py b/demisto_sdk/commands/content_graph/objects/pack_metadata.py index 8dcb585415e..d4ca91652e0 100644 --- a/demisto_sdk/commands/content_graph/objects/pack_metadata.py +++ b/demisto_sdk/commands/content_graph/objects/pack_metadata.py @@ -9,9 +9,7 @@ DEFAULT_CONTENT_ITEM_TO_VERSION, MarketplaceVersions, ) -from demisto_sdk.commands.common.content_constant_paths import ( - LANDING_PAGE_SECTIONS_PATH, -) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.handlers import JSON_Handler from demisto_sdk.commands.common.logger import logger from demisto_sdk.commands.common.tools import get_json, is_external_repository @@ -459,10 +457,10 @@ def _get_tags_from_landing_page(self, pack_id: str) -> set: tags: set = set() try: - landing_page_sections = get_json(LANDING_PAGE_SECTIONS_PATH) + landing_page_sections = get_json(ContentPaths.LANDING_PAGE_SECTIONS_PATH) except FileNotFoundError as e: logger.warning( - f"Couldn't find the landing_page file in path {LANDING_PAGE_SECTIONS_PATH}. Skipping collecting tags by landing page sections.\n{e}" + f"Couldn't find the landing_page file in path {ContentPaths.LANDING_PAGE_SECTIONS_PATH}. Skipping collecting tags by landing page sections.\n{e}" ) return tags From dee9a274b32069fb3dba6f2918cf7b51ddb5e065 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 21:50:21 +0200 Subject: [PATCH 08/59] fixes --- .../tests/integration_tests/format_integration_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demisto_sdk/tests/integration_tests/format_integration_test.py b/demisto_sdk/tests/integration_tests/format_integration_test.py index 5d6d3ea258a..3d1a212b5d9 100644 --- a/demisto_sdk/tests/integration_tests/format_integration_test.py +++ b/demisto_sdk/tests/integration_tests/format_integration_test.py @@ -260,7 +260,7 @@ def test_integration_format_configuring_conf_json_no_interactive_positive( # Setting up conf.json conf_json_path = tmp_path / "conf.json" mocker.patch( - "demisto_sdk.commands.format.update_generic_yml.CONF_PATH", conf_json_path + "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", conf_json_path ) with open(conf_json_path, "w") as file: json.dump(CONF_JSON_ORIGINAL_CONTENT, file, indent=4) @@ -313,7 +313,7 @@ def test_integration_format_configuring_conf_json_positive( # Setting up conf.json conf_json_path = tmp_path / "conf.json" mocker.patch( - "demisto_sdk.commands.format.update_generic_yml.CONF_PATH", conf_json_path + "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", conf_json_path ) with open(conf_json_path, "w") as file: json.dump(CONF_JSON_ORIGINAL_CONTENT, file, indent=4) @@ -390,7 +390,7 @@ def test_integration_format_configuring_conf_json_negative( # Setting up conf.json conf_json_path = tmp_path / "conf.json" mocker.patch( - "demisto_sdk.commands.format.update_generic_yml.CONF_PATH", conf_json_path + "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", conf_json_path ) with open(conf_json_path, "w") as file: From 18df18086d8289543c92c4834f5054943898bacf Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 12 Nov 2024 22:01:28 +0200 Subject: [PATCH 09/59] pre-commit fixes --- demisto_sdk/__main__.py | 4 +- .../commands/common/content_constant_paths.py | 38 +++++++++++-------- .../common/hook_validations/conf_json.py | 8 +++- .../common/hook_validations/readme.py | 4 +- demisto_sdk/commands/common/native_image.py | 4 +- .../content_graph/objects/content_item.py | 8 +++- .../commands/content_graph/objects/pack.py | 5 ++- .../content_graph/objects/repository.py | 7 +++- .../commands/pre_commit/hooks/docker.py | 3 +- demisto_sdk/commands/pre_commit/hooks/hook.py | 4 +- .../commands/pre_commit/hooks/sourcery.py | 4 +- .../commands/pre_commit/pre_commit_command.py | 12 ++++-- .../commands/setup_env/setup_environment.py | 17 +++++++-- .../test_modeling_rule/test_modeling_rule.py | 8 +++- ...107_is_deprecated_content_item_in_usage.py | 4 +- .../validate/validators/base_validator.py | 4 +- .../commands/xsoar_linter/xsoar_linter.py | 4 +- .../format_integration_test.py | 9 +++-- .../upload_integration_test.py | 4 +- 19 files changed, 106 insertions(+), 45 deletions(-) diff --git a/demisto_sdk/__main__.py b/demisto_sdk/__main__.py index fed96bbc2c9..26289e59ddf 100644 --- a/demisto_sdk/__main__.py +++ b/demisto_sdk/__main__.py @@ -2709,7 +2709,9 @@ def find_dependencies(ctx, **kwargs): use_pack_metadata = kwargs.get("use_pack_metadata", False) all_packs_dependencies = kwargs.get("all_packs_dependencies", False) get_dependent_on = kwargs.get("get_dependent_on", False) - output_path = kwargs.get("output_path", ContentPaths.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH) + output_path = kwargs.get( + "output_path", ContentPaths.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH + ) dependency = kwargs.get("dependency", "") try: PackDependencies.find_dependencies_manager( diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 3e2fe4b10fc..3027c8874b8 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -9,29 +9,31 @@ class ContentPaths: # Class-level variables (shared across all instances) CONTENT_PATH: Path = Path(get_content_path()) - ALL_PACKS_DEPENDENCIES_DEFAULT_PATH: Path = CONTENT_PATH / "all_packs_dependencies.json" + ALL_PACKS_DEPENDENCIES_DEFAULT_PATH: Path = ( + CONTENT_PATH / "all_packs_dependencies.json" + ) CONF_PATH: Path = CONTENT_PATH / TESTS_DIR / "conf.json" DEFAULT_ID_SET_PATH: Path = CONTENT_PATH / TESTS_DIR / "id_set.json" MP_V2_ID_SET_PATH: Path = CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" XPANSE_ID_SET_PATH: Path = CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" LANDING_PAGE_SECTIONS_PATH: Path = ( - CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" - ) + CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" + ) NATIVE_IMAGE_PATH: Path = CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME COMMON_SERVER_PYTHON_PATH: Path = ( - CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" - ) + CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" + ) DEMISTO_MOCK_PATH: Path = CONTENT_PATH / TESTS_DIR / "demistomock" API_MODULES_SCRIPTS_DIR: Path = CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" PYTHONPATH = [ - path.absolute() - for path in [ - CONTENT_PATH, - COMMON_SERVER_PYTHON_PATH, - DEMISTO_MOCK_PATH, - Path(__file__).parent.parent / "lint" / "resources" / "pylint_plugins", - ] + path.absolute() + for path in [ + CONTENT_PATH, + COMMON_SERVER_PYTHON_PATH, + DEMISTO_MOCK_PATH, + Path(__file__).parent.parent / "lint" / "resources" / "pylint_plugins", ] + ] PYTHONPATH_STR = ":".join(str(path) for path in PYTHONPATH) @classmethod @@ -45,7 +47,9 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: logger.info(f"Updating content_path globally: {content_path}") cls.CONTENT_PATH = Path(content_path) - cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = cls.CONTENT_PATH / "all_packs_dependencies.json" + cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = ( + cls.CONTENT_PATH / "all_packs_dependencies.json" + ) cls.CONF_PATH = cls.CONTENT_PATH / TESTS_DIR / "conf.json" cls.DEFAULT_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set.json" cls.MP_V2_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" @@ -58,7 +62,9 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: cls.CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" ) cls.DEMISTO_MOCK_PATH = cls.CONTENT_PATH / TESTS_DIR / "demistomock" - cls.API_MODULES_SCRIPTS_DIR = cls.CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" + cls.API_MODULES_SCRIPTS_DIR = ( + cls.CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" + ) cls.PYTHONPATH = [ path.absolute() @@ -71,7 +77,9 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: ] if cls.API_MODULES_SCRIPTS_DIR.exists(): - cls.PYTHONPATH.extend(path.absolute() for path in cls.API_MODULES_SCRIPTS_DIR.iterdir()) + cls.PYTHONPATH.extend( + path.absolute() for path in cls.API_MODULES_SCRIPTS_DIR.iterdir() + ) else: logger.debug( "Could not add API modules to 'PYTHONPATH' as the base directory does not exist." diff --git a/demisto_sdk/commands/common/hook_validations/conf_json.py b/demisto_sdk/commands/common/hook_validations/conf_json.py index df0d8671ee9..193052fb5e2 100644 --- a/demisto_sdk/commands/common/hook_validations/conf_json.py +++ b/demisto_sdk/commands/common/hook_validations/conf_json.py @@ -69,7 +69,9 @@ def is_valid_description_in_conf_dict(self, checked_dict): error_message, error_code = Errors.description_missing_from_conf_json( problematic_instances ) - if self.handle_error(error_message, error_code, file_path=ContentPaths.CONF_PATH): + if self.handle_error( + error_message, error_code, file_path=ContentPaths.CONF_PATH + ): self._is_valid = False return self._is_valid @@ -91,7 +93,9 @@ def is_test_in_conf_json(self, file_id): return True error_message, error_code = Errors.test_not_in_conf_json(file_id) - if self.handle_error(error_message, error_code, file_path=ContentPaths.CONF_PATH): + if self.handle_error( + error_message, error_code, file_path=ContentPaths.CONF_PATH + ): return False return True diff --git a/demisto_sdk/commands/common/hook_validations/readme.py b/demisto_sdk/commands/common/hook_validations/readme.py index 6f5c8cb0c49..b25239bb2fb 100644 --- a/demisto_sdk/commands/common/hook_validations/readme.py +++ b/demisto_sdk/commands/common/hook_validations/readme.py @@ -757,7 +757,9 @@ def empty_context_mgr(bool): if mdx_server_is_up(): # this allows for this context to be reentrant logger.debug("server is already up. Not restarting") return empty_context_mgr(True) - if ReadMeValidator.are_modules_installed_for_verify(ContentPaths.CONTENT_PATH): # type: ignore + if ReadMeValidator.are_modules_installed_for_verify( + ContentPaths.CONTENT_PATH + ): # type: ignore ReadMeValidator.add_node_env_vars() return start_local_MDX_server(handle_error, file_path) elif ReadMeValidator.is_docker_available(): diff --git a/demisto_sdk/commands/common/native_image.py b/demisto_sdk/commands/common/native_image.py index be8341517d0..88844aca01d 100644 --- a/demisto_sdk/commands/common/native_image.py +++ b/demisto_sdk/commands/common/native_image.py @@ -68,7 +68,9 @@ def get_instance_from(cls, *args, **kwargs): return cls.from_path(*args, **kwargs) @classmethod - def from_path(cls, native_image_config_file_path: Path = Path(ContentPaths.NATIVE_IMAGE_PATH)): + def from_path( + cls, native_image_config_file_path: Path = Path(ContentPaths.NATIVE_IMAGE_PATH) + ): native_image_config = cls.parse_file(native_image_config_file_path) native_image_config.__docker_images_to_native_images_support() return native_image_config diff --git a/demisto_sdk/commands/content_graph/objects/content_item.py b/demisto_sdk/commands/content_graph/objects/content_item.py index e20879837e6..355e94eb5f6 100644 --- a/demisto_sdk/commands/content_graph/objects/content_item.py +++ b/demisto_sdk/commands/content_graph/objects/content_item.py @@ -62,7 +62,10 @@ def validate_path(cls, v: Path, values) -> Path: return v if not ContentPaths.CONTENT_PATH.name: return ContentPaths.CONTENT_PATH / v - return ContentPaths.CONTENT_PATH.with_name(values.get("source_repo", "content")) / v + return ( + ContentPaths.CONTENT_PATH.with_name(values.get("source_repo", "content")) + / v + ) @staticmethod @abstractmethod @@ -126,7 +129,8 @@ def get_pack( if not pack: if pack_name := get_pack_name(path): pack = BaseContent.from_path( - ContentPaths.CONTENT_PATH / PACKS_FOLDER / pack_name, metadata_only=True + ContentPaths.CONTENT_PATH / PACKS_FOLDER / pack_name, + metadata_only=True, ) # type: ignore[assignment] return pack # type: ignore[return-value] diff --git a/demisto_sdk/commands/content_graph/objects/pack.py b/demisto_sdk/commands/content_graph/objects/pack.py index 51ecec57cf1..bd8694306a5 100644 --- a/demisto_sdk/commands/content_graph/objects/pack.py +++ b/demisto_sdk/commands/content_graph/objects/pack.py @@ -145,7 +145,10 @@ def validate_path(cls, v: Path, values) -> Path: return v if not ContentPaths.CONTENT_PATH.name: return ContentPaths.CONTENT_PATH / v - return ContentPaths.CONTENT_PATH.with_name(values.get("source_repo", "content")) / v + return ( + ContentPaths.CONTENT_PATH.with_name(values.get("source_repo", "content")) + / v + ) @property def is_private(self) -> bool: diff --git a/demisto_sdk/commands/content_graph/objects/repository.py b/demisto_sdk/commands/content_graph/objects/repository.py index 0a7daa6b052..30e0cc43eef 100644 --- a/demisto_sdk/commands/content_graph/objects/repository.py +++ b/demisto_sdk/commands/content_graph/objects/repository.py @@ -19,7 +19,9 @@ @lru_cache -def from_path(path: Path = ContentPaths.CONTENT_PATH, packs_to_parse: Optional[Tuple[str]] = None): +def from_path( + path: Path = ContentPaths.CONTENT_PATH, packs_to_parse: Optional[Tuple[str]] = None +): """ Returns a ContentDTO object with all the packs of the content repository. @@ -45,7 +47,8 @@ class ContentDTO(BaseModel): @staticmethod def from_path( - path: Path = ContentPaths.CONTENT_PATH, packs_to_parse: Optional[Tuple[str, ...]] = None + path: Path = ContentPaths.CONTENT_PATH, + packs_to_parse: Optional[Tuple[str, ...]] = None, ): """ Returns a ContentDTO object with all the packs of the content repository. diff --git a/demisto_sdk/commands/pre_commit/hooks/docker.py b/demisto_sdk/commands/pre_commit/hooks/docker.py index e28f5349d4d..94dde62c7be 100644 --- a/demisto_sdk/commands/pre_commit/hooks/docker.py +++ b/demisto_sdk/commands/pre_commit/hooks/docker.py @@ -365,7 +365,8 @@ def prepare_hook( target = obj.path.parent / Path(file).name if source != target and source.exists() and not target.exists(): shutil.copy( - ContentPaths.CONTENT_PATH / file, obj.path.parent / Path(file).name + ContentPaths.CONTENT_PATH / file, + obj.path.parent / Path(file).name, ) run_isolated = self._get_property("run_isolated", False) config_arg = self._get_config_file_arg() diff --git a/demisto_sdk/commands/pre_commit/hooks/hook.py b/demisto_sdk/commands/pre_commit/hooks/hook.py index 3554db5e541..3283f56d138 100644 --- a/demisto_sdk/commands/pre_commit/hooks/hook.py +++ b/demisto_sdk/commands/pre_commit/hooks/hook.py @@ -210,7 +210,9 @@ def join_files(files: Set[Path], separator: str = "|") -> str: str: The joined string. """ return separator.join( - str(file) if (ContentPaths.CONTENT_PATH / file).is_file() else f"{str(file)}{os.sep}" + str(file) + if (ContentPaths.CONTENT_PATH / file).is_file() + else f"{str(file)}{os.sep}" for file in files ) diff --git a/demisto_sdk/commands/pre_commit/hooks/sourcery.py b/demisto_sdk/commands/pre_commit/hooks/sourcery.py index 67e5c669969..9d0f0f89f46 100644 --- a/demisto_sdk/commands/pre_commit/hooks/sourcery.py +++ b/demisto_sdk/commands/pre_commit/hooks/sourcery.py @@ -32,7 +32,9 @@ def prepare_hook(self) -> GeneratedHooks: Returns: None """ - config_file = ContentPaths.CONTENT_PATH / self._get_property("config_file", ".sourcery.yml") + config_file = ContentPaths.CONTENT_PATH / self._get_property( + "config_file", ".sourcery.yml" + ) if not config_file.exists(): return [] self.base_hook.pop("config_file", None) diff --git a/demisto_sdk/commands/pre_commit/pre_commit_command.py b/demisto_sdk/commands/pre_commit/pre_commit_command.py index 0c1fc426f8c..6e53a520a77 100644 --- a/demisto_sdk/commands/pre_commit/pre_commit_command.py +++ b/demisto_sdk/commands/pre_commit/pre_commit_command.py @@ -301,10 +301,14 @@ def prepare_and_run( ret_val = 0 pre_commit_context.dry_run = dry_run precommit_env = os.environ.copy() - precommit_env["PYTHONPATH"] = ":".join(str(path) for path in ContentPaths.PYTHONPATH) + precommit_env["PYTHONPATH"] = ":".join( + str(path) for path in ContentPaths.PYTHONPATH + ) # The PYTHONPATH should be the same as the PYTHONPATH, but without the site-packages because MYPY does not support it precommit_env["MYPYPATH"] = ":".join( - str(path) for path in sorted(ContentPaths.PYTHONPATH) if "site-packages" not in str(path) + str(path) + for path in sorted(ContentPaths.PYTHONPATH) + if "site-packages" not in str(path) ) precommit_env["DEMISTO_SDK_CONTENT_PATH"] = str(ContentPaths.CONTENT_PATH) precommit_env["SYSTEMD_COLORS"] = "1" # for colorful output @@ -451,7 +455,9 @@ def group_by_language( ) else: exclude_integration_script.add( - integration_script.path.parent.relative_to(ContentPaths.CONTENT_PATH) + integration_script.path.parent.relative_to( + ContentPaths.CONTENT_PATH + ) ) continue diff --git a/demisto_sdk/commands/setup_env/setup_environment.py b/demisto_sdk/commands/setup_env/setup_environment.py index 9d4a0355828..37641b97fec 100644 --- a/demisto_sdk/commands/setup_env/setup_environment.py +++ b/demisto_sdk/commands/setup_env/setup_environment.py @@ -95,7 +95,9 @@ def get_docker_python_path(docker_prefix: str) -> List[str]: ): try: common_server_python_contnet = TextFile.read_from_github_api( - str(ContentPaths.COMMON_SERVER_PYTHON_PATH / "CommonServerUserPython.py"), + str( + ContentPaths.COMMON_SERVER_PYTHON_PATH / "CommonServerUserPython.py" + ), verify_ssl=False, ) except (FileReadError, ConnectionError, Timeout): @@ -110,7 +112,8 @@ def get_docker_python_path(docker_prefix: str) -> List[str]: TextFile.write( common_server_python_contnet, - output_path=ContentPaths.COMMON_SERVER_PYTHON_PATH / "CommonServerUserPython.py", + output_path=ContentPaths.COMMON_SERVER_PYTHON_PATH + / "CommonServerUserPython.py", ) docker_python_path.append( @@ -286,7 +289,11 @@ def configure_module_discovery(ide_type: IDEType): if ContentPaths.CONTENT_PATH in python_discovery_paths: python_discovery_paths.remove(ContentPaths.CONTENT_PATH) - config_file_path = ContentPaths.CONTENT_PATH / ".idea" / f"{ContentPaths.CONTENT_PATH.name.lower()}.iml" + config_file_path = ( + ContentPaths.CONTENT_PATH + / ".idea" + / f"{ContentPaths.CONTENT_PATH.name.lower()}.iml" + ) update_pycharm_config_file( file_path=config_file_path, python_discovery_paths=python_discovery_paths, @@ -689,7 +696,9 @@ def upload_and_create_instance( def add_demistomock_and_commonserveruser(integration_script: IntegrationScript): - source_demisto_mock_path = ContentPaths.CONTENT_PATH / "Tests" / "demistomock" / "demistomock.py" + source_demisto_mock_path = ( + ContentPaths.CONTENT_PATH / "Tests" / "demistomock" / "demistomock.py" + ) target_demisto_mock_path = integration_script.path.parent / "demistomock.py" if source_demisto_mock_path.exists(): shutil.copy( diff --git a/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py b/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py index ee68d4efb52..a7c8fc6f556 100644 --- a/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py +++ b/demisto_sdk/commands/test_content/test_modeling_rule/test_modeling_rule.py @@ -142,8 +142,12 @@ def get_relative_path_to_content(path: Path) -> str: Returns: Path: The relative path to the content directory. """ - if path.is_absolute() and path.as_posix().startswith(ContentPaths.CONTENT_PATH.as_posix()): - return path.as_posix().replace(f"{ContentPaths.CONTENT_PATH.as_posix()}{os.path.sep}", "") + if path.is_absolute() and path.as_posix().startswith( + ContentPaths.CONTENT_PATH.as_posix() + ): + return path.as_posix().replace( + f"{ContentPaths.CONTENT_PATH.as_posix()}{os.path.sep}", "" + ) return path.as_posix() diff --git a/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py b/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py index 3d04b953d8a..6210957d1e3 100644 --- a/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py +++ b/demisto_sdk/commands/validate/validators/GR_validators/GR107_is_deprecated_content_item_in_usage.py @@ -106,7 +106,9 @@ def obtain_invalid_content_items_using_graph( deprecated_item_type=item.deprecated_item_type, deprecated_item=item.deprecated_item_id, using_deprecated_item=str( - item_using_deprecated.path.relative_to(ContentPaths.CONTENT_PATH) + item_using_deprecated.path.relative_to( + ContentPaths.CONTENT_PATH + ) ), ), content_object=item_using_deprecated, diff --git a/demisto_sdk/commands/validate/validators/base_validator.py b/demisto_sdk/commands/validate/validators/base_validator.py index 6280f6ba203..c1c3dd86f72 100644 --- a/demisto_sdk/commands/validate/validators/base_validator.py +++ b/demisto_sdk/commands/validate/validators/base_validator.py @@ -232,7 +232,9 @@ def format_readable_message(self): @property def format_json_message(self): return { - "file path": str(self.content_object.path.relative_to(ContentPaths.CONTENT_PATH)), + "file path": str( + self.content_object.path.relative_to(ContentPaths.CONTENT_PATH) + ), "error code": self.validator.error_code, "message": self.message, } diff --git a/demisto_sdk/commands/xsoar_linter/xsoar_linter.py b/demisto_sdk/commands/xsoar_linter/xsoar_linter.py index 67389571bb3..6711bfca084 100644 --- a/demisto_sdk/commands/xsoar_linter/xsoar_linter.py +++ b/demisto_sdk/commands/xsoar_linter/xsoar_linter.py @@ -122,7 +122,9 @@ def build_xsoar_linter_env_var(integration_script: IntegrationScript) -> dict: xsoar_linter_env["commands"] = ",".join( [command.name for command in integration_script.commands] ) - xsoar_linter_env["PYTHONPATH"] = ":".join(str(path) for path in ContentPaths.PYTHONPATH) + xsoar_linter_env["PYTHONPATH"] = ":".join( + str(path) for path in ContentPaths.PYTHONPATH + ) return xsoar_linter_env diff --git a/demisto_sdk/tests/integration_tests/format_integration_test.py b/demisto_sdk/tests/integration_tests/format_integration_test.py index 3d1a212b5d9..0386d4665cb 100644 --- a/demisto_sdk/tests/integration_tests/format_integration_test.py +++ b/demisto_sdk/tests/integration_tests/format_integration_test.py @@ -260,7 +260,8 @@ def test_integration_format_configuring_conf_json_no_interactive_positive( # Setting up conf.json conf_json_path = tmp_path / "conf.json" mocker.patch( - "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", conf_json_path + "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", + conf_json_path, ) with open(conf_json_path, "w") as file: json.dump(CONF_JSON_ORIGINAL_CONTENT, file, indent=4) @@ -313,7 +314,8 @@ def test_integration_format_configuring_conf_json_positive( # Setting up conf.json conf_json_path = tmp_path / "conf.json" mocker.patch( - "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", conf_json_path + "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", + conf_json_path, ) with open(conf_json_path, "w") as file: json.dump(CONF_JSON_ORIGINAL_CONTENT, file, indent=4) @@ -390,7 +392,8 @@ def test_integration_format_configuring_conf_json_negative( # Setting up conf.json conf_json_path = tmp_path / "conf.json" mocker.patch( - "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", conf_json_path + "demisto_sdk.commands.format.update_generic_yml.ContentPaths.CONF_PATH", + conf_json_path, ) with open(conf_json_path, "w") as file: diff --git a/demisto_sdk/tests/integration_tests/upload_integration_test.py b/demisto_sdk/tests/integration_tests/upload_integration_test.py index fbb0915bf62..1c1e32d48b1 100644 --- a/demisto_sdk/tests/integration_tests/upload_integration_test.py +++ b/demisto_sdk/tests/integration_tests/upload_integration_test.py @@ -63,7 +63,7 @@ def test_integration_upload_pack_positive(demisto_client_mock, mocker): ) mocker.patch.object( content_item, - "CONTENT_PATH", + "ContentPaths.CONTENT_PATH", Path(DEMISTO_SDK_PATH, "tests/test_files/content_repo_example"), ) @@ -122,7 +122,7 @@ def test_integration_upload_pack_with_specific_marketplace(demisto_client_mock, ) mocker.patch.object( content_item, - "CONTENT_PATH", + "ContentPaths.CONTENT_PATH", Path(DEMISTO_SDK_PATH, "tests/test_files/content_repo_example"), ) From 7fb99a202de8b70414bd17397ce97e2ce1f2c654 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Wed, 13 Nov 2024 01:23:53 +0200 Subject: [PATCH 10/59] fix tests --- .../commands/init/tests/contribution_converter_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demisto_sdk/commands/init/tests/contribution_converter_test.py b/demisto_sdk/commands/init/tests/contribution_converter_test.py index 8885d7f3306..3f2518957f9 100644 --- a/demisto_sdk/commands/init/tests/contribution_converter_test.py +++ b/demisto_sdk/commands/init/tests/contribution_converter_test.py @@ -276,7 +276,7 @@ def test_convert_contribution_zip_updated_pack(tmp_path, mocker): # Create fake content repo and contribution zip repo = Repo(repo_dir) mocker.patch( - "demisto_sdk.commands.init.contribution_converter.CONTENT_PATH", repo.path + "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", repo.path ) pack = repo.create_pack("TestPack") integration = pack.create_integration("integration0") @@ -501,7 +501,7 @@ def test_convert_contribution_zip( contribution_zip_dir.mkdir() # Create fake content repo and contribution zip mocker.patch( - "demisto_sdk.commands.init.contribution_converter.CONTENT_PATH", git_repo.path + "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", git_repo.path ) contrib_zip = Contribution(target_dir, "ContribTestPack", git_repo) @@ -633,7 +633,7 @@ def test_convert_contribution_zip_with_args( contribution_zip_dir.mkdir() mocker.patch( - "demisto_sdk.commands.init.contribution_converter.CONTENT_PATH", git_repo.path + "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", git_repo.path ) contrib_zip = Contribution(target_dir, "ContribTestPack", git_repo) # contrib_zip.create_zip(contribution_zip_dir) From 0f391e03680bef317a7d03dcdb8b4b6ba264d772 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Wed, 13 Nov 2024 12:30:44 +0200 Subject: [PATCH 11/59] unittests fix --- .../commands/pre_commit/tests/pre_commit_test.py | 10 +++++----- .../commands/setup_env/tests/setup_environment_test.py | 8 ++++---- demisto_sdk/commands/upload/tests/uploader_test.py | 9 +++++---- .../commands/validate/tests/GR_validators_test.py | 4 ++-- .../commands/validate/tests/SC_validators_test.py | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py b/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py index cf568f4d4dc..1cf5ac31e4d 100644 --- a/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py +++ b/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py @@ -140,7 +140,7 @@ def devtest_side_effect( TEST_DATA_PATH / ".pre-commit-config_template-test.yaml", ) pack1 = repo.create_pack("Pack1") - mocker.patch.object(pre_commit_command, "CONTENT_PATH", Path(repo.path)) + mocker.patch.object(pre_commit_command.ContentPaths, "CONTENT_PATH", Path(repo.path)) mocker.patch.object( pre_commit_command, @@ -239,7 +239,7 @@ def test_handle_api_modules(mocker, git_repo: Repo): integration = pack2.create_integration( "integration1", code="from TestApiModule import *" ) - mocker.patch.object(pre_commit_command, "CONTENT_PATH", Path(git_repo.path)) + mocker.patch.object(pre_commit_command.ContentPaths, "CONTENT_PATH", Path(git_repo.path)) with ChangeCWD(git_repo.path): git_repo.create_graph() files_to_run = group_by_language( @@ -386,7 +386,7 @@ def test_preprocess_files_with_input_yml_files(self, mocker, repo): - Check that the associated python file was gathered correctly. """ pack1 = repo.create_pack("Pack1") - mocker.patch.object(pre_commit_command, "CONTENT_PATH", Path(repo.path)) + mocker.patch.object(pre_commit_command.ContentPaths, "CONTENT_PATH", Path(repo.path)) integration = pack1.create_integration("integration") relative_paths = { @@ -572,7 +572,7 @@ def test_exclude_hooks_by_version(mocker, repo: Repo): "PRECOMMIT_TEMPLATE_PATH", TEST_DATA_PATH / ".pre-commit-config_template-test.yaml", ) - mocker.patch.object(context, "CONTENT_PATH", Path(repo.path)) + mocker.patch.object(context.ContentPaths, "CONTENT_PATH", Path(repo.path)) mocker.patch.object(pre_commit_command, "logger") python_version_to_files = { "2.7": {(Path("file1.py"), None)}, @@ -609,7 +609,7 @@ def test_exclude_hooks_by_support_level(mocker, repo: Repo): "PRECOMMIT_TEMPLATE_PATH", TEST_DATA_PATH / ".pre-commit-config_template-test.yaml", ) - mocker.patch.object(context, "CONTENT_PATH", Path(repo.path)) + mocker.patch.object(context.ContentPaths, "CONTENT_PATH", Path(repo.path)) mocker.patch.object(pre_commit_command, "logger") python_version_to_files = { "2.7": {(Path("file1.py"), Obj())}, diff --git a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py index 1e318e80c3e..f15bd3a26d7 100644 --- a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py +++ b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py @@ -35,18 +35,18 @@ def test_setup_env_vscode(mocker, monkeypatch, pack, create_virtualenv): test_image = "test/python3-sha" params = {"username": "user", "password": "pass"} repo_path = Path(pack.repo_path) - mocker.patch.object(setup_environment, "CONTENT_PATH", repo_path) - mocker.patch.object(setup_environment, "DOTENV_PATH", repo_path / ".env") + mocker.patch.object(setup_environment.ContentPaths, "CONTENT_PATH", repo_path) + mocker.patch.object(setup_environment.ContentPaths, "DOTENV_PATH", repo_path / ".env") mocker.patch.object( - setup_environment, + setup_environment.ContentPaths, "PYTHONPATH", [repo_path / "Packs/Base/Scripts/CommonServerPython"], ) mocker.patch.object(setup_environment, "add_demistomock_and_commonserveruser") - mocker.patch.object(content_item, "CONTENT_PATH", repo_path) + mocker.patch.object(content_item.ContentPaths, "CONTENT_PATH", repo_path) mocker.patch.object( docker_helper.DockerBase, "get_or_create_test_image", diff --git a/demisto_sdk/commands/upload/tests/uploader_test.py b/demisto_sdk/commands/upload/tests/uploader_test.py index 4c066388ef6..04b35f82524 100644 --- a/demisto_sdk/commands/upload/tests/uploader_test.py +++ b/demisto_sdk/commands/upload/tests/uploader_test.py @@ -133,7 +133,7 @@ def test_upload_folder( "upload", ) content_path = f"{git_path()}/demisto_sdk/tests/test_files/" - mocker.patch.object(content_item, "CONTENT_PATH", Path(content_path)) + mocker.patch.object(content_item.ContentPaths, "CONTENT_PATH", Path(content_path)) mocker.patch.object(PackParser, "parse_ignored_errors", return_value={}) path = Path(content_path, path_end) @@ -609,7 +609,7 @@ def test_print_summary_successfully_uploaded_files( import demisto_sdk.commands.content_graph.objects.content_item as content_item mocker.patch.object( - content_item, + content_item.ContentPaths, "CONTENT_PATH", Path(f"{git_path()}/demisto_sdk/tests/test_files"), ) @@ -621,8 +621,7 @@ def test_print_summary_successfully_uploaded_files( uploader.print_summary() assert "UPLOAD SUMMARY:\n" in caplog.text - assert ( - "\n".join( + res = "\n".join( ( "SUCCESSFUL UPLOADS:", "╒═════════════════╤════════╤═════════════╤════════════════╕", @@ -633,6 +632,8 @@ def test_print_summary_successfully_uploaded_files( "", ) ) + assert ( + res in caplog.text ) diff --git a/demisto_sdk/commands/validate/tests/GR_validators_test.py b/demisto_sdk/commands/validate/tests/GR_validators_test.py index d384e0f4f15..5f442e0ab8d 100644 --- a/demisto_sdk/commands/validate/tests/GR_validators_test.py +++ b/demisto_sdk/commands/validate/tests/GR_validators_test.py @@ -83,7 +83,7 @@ def test_IsPackDisplayNameAlreadyExistsValidatorListFiles_obtain_invalid_content - Validate that we got the error messages for the duplicate name. """ mocker.patch.object( - GR104_is_pack_display_name_already_exists, + GR104_is_pack_display_name_already_exists.ContentPaths, "CONTENT_PATH", new=graph_repo.path, ) @@ -122,7 +122,7 @@ def test_IsPackDisplayNameAlreadyExistsValidatorAllFiles_obtain_invalid_content_ - Validate that we got the error messages for the duplicate name. """ mocker.patch.object( - GR104_is_pack_display_name_already_exists, + GR104_is_pack_display_name_already_exists.ContentPaths, "CONTENT_PATH", new=graph_repo.path, ) diff --git a/demisto_sdk/commands/validate/tests/SC_validators_test.py b/demisto_sdk/commands/validate/tests/SC_validators_test.py index c6026977e6c..4410537797d 100644 --- a/demisto_sdk/commands/validate/tests/SC_validators_test.py +++ b/demisto_sdk/commands/validate/tests/SC_validators_test.py @@ -161,7 +161,7 @@ def test_DuplicatedScriptNameValidatorListFiles_obtain_invalid_content_items( - Validate that only the first pair of scripts appear in the results, and the rest of the scripts is valid. """ mocker.patch.object( - SC109_script_name_is_not_unique_validator, + SC109_script_name_is_not_unique_validator.ContentPaths, "CONTENT_PATH", new=graph_repo.path, ) @@ -209,7 +209,7 @@ def test_DuplicatedScriptNameValidatorAllFiles_obtain_invalid_content_items( - Validate that only the first pair of scripts appear in the results, and the rest of the scripts is valid. """ mocker.patch.object( - SC109_script_name_is_not_unique_validator, + SC109_script_name_is_not_unique_validator.ContentPaths, "CONTENT_PATH", new=graph_repo.path, ) From 869d9e8315015bb6b0372e63946017a3f6404153 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Wed, 13 Nov 2024 13:11:58 +0200 Subject: [PATCH 12/59] unittests fix --- .../init/tests/contribution_converter_test.py | 9 +++++--- .../pre_commit/tests/pre_commit_test.py | 12 ++++++++--- .../setup_env/tests/setup_environment_test.py | 4 +++- .../commands/upload/tests/uploader_test.py | 21 ++++++++----------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/demisto_sdk/commands/init/tests/contribution_converter_test.py b/demisto_sdk/commands/init/tests/contribution_converter_test.py index 3f2518957f9..1e4f92f8ca6 100644 --- a/demisto_sdk/commands/init/tests/contribution_converter_test.py +++ b/demisto_sdk/commands/init/tests/contribution_converter_test.py @@ -276,7 +276,8 @@ def test_convert_contribution_zip_updated_pack(tmp_path, mocker): # Create fake content repo and contribution zip repo = Repo(repo_dir) mocker.patch( - "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", repo.path + "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", + repo.path, ) pack = repo.create_pack("TestPack") integration = pack.create_integration("integration0") @@ -501,7 +502,8 @@ def test_convert_contribution_zip( contribution_zip_dir.mkdir() # Create fake content repo and contribution zip mocker.patch( - "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", git_repo.path + "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", + git_repo.path, ) contrib_zip = Contribution(target_dir, "ContribTestPack", git_repo) @@ -633,7 +635,8 @@ def test_convert_contribution_zip_with_args( contribution_zip_dir.mkdir() mocker.patch( - "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", git_repo.path + "demisto_sdk.commands.init.contribution_converter.ContentPaths.CONTENT_PATH", + git_repo.path, ) contrib_zip = Contribution(target_dir, "ContribTestPack", git_repo) # contrib_zip.create_zip(contribution_zip_dir) diff --git a/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py b/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py index 1cf5ac31e4d..ec0bb70fc34 100644 --- a/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py +++ b/demisto_sdk/commands/pre_commit/tests/pre_commit_test.py @@ -140,7 +140,9 @@ def devtest_side_effect( TEST_DATA_PATH / ".pre-commit-config_template-test.yaml", ) pack1 = repo.create_pack("Pack1") - mocker.patch.object(pre_commit_command.ContentPaths, "CONTENT_PATH", Path(repo.path)) + mocker.patch.object( + pre_commit_command.ContentPaths, "CONTENT_PATH", Path(repo.path) + ) mocker.patch.object( pre_commit_command, @@ -239,7 +241,9 @@ def test_handle_api_modules(mocker, git_repo: Repo): integration = pack2.create_integration( "integration1", code="from TestApiModule import *" ) - mocker.patch.object(pre_commit_command.ContentPaths, "CONTENT_PATH", Path(git_repo.path)) + mocker.patch.object( + pre_commit_command.ContentPaths, "CONTENT_PATH", Path(git_repo.path) + ) with ChangeCWD(git_repo.path): git_repo.create_graph() files_to_run = group_by_language( @@ -386,7 +390,9 @@ def test_preprocess_files_with_input_yml_files(self, mocker, repo): - Check that the associated python file was gathered correctly. """ pack1 = repo.create_pack("Pack1") - mocker.patch.object(pre_commit_command.ContentPaths, "CONTENT_PATH", Path(repo.path)) + mocker.patch.object( + pre_commit_command.ContentPaths, "CONTENT_PATH", Path(repo.path) + ) integration = pack1.create_integration("integration") relative_paths = { diff --git a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py index f15bd3a26d7..20c9fd431b1 100644 --- a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py +++ b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py @@ -36,7 +36,9 @@ def test_setup_env_vscode(mocker, monkeypatch, pack, create_virtualenv): params = {"username": "user", "password": "pass"} repo_path = Path(pack.repo_path) mocker.patch.object(setup_environment.ContentPaths, "CONTENT_PATH", repo_path) - mocker.patch.object(setup_environment.ContentPaths, "DOTENV_PATH", repo_path / ".env") + mocker.patch.object( + setup_environment.ContentPaths, "DOTENV_PATH", repo_path / ".env" + ) mocker.patch.object( setup_environment.ContentPaths, diff --git a/demisto_sdk/commands/upload/tests/uploader_test.py b/demisto_sdk/commands/upload/tests/uploader_test.py index 04b35f82524..12aeccd8857 100644 --- a/demisto_sdk/commands/upload/tests/uploader_test.py +++ b/demisto_sdk/commands/upload/tests/uploader_test.py @@ -622,20 +622,17 @@ def test_print_summary_successfully_uploaded_files( assert "UPLOAD SUMMARY:\n" in caplog.text res = "\n".join( - ( - "SUCCESSFUL UPLOADS:", - "╒═════════════════╤════════╤═════════════╤════════════════╕", - "│ NAME │ TYPE │ PACK NAME │ PACK VERSION │", - "╞═════════════════╪════════╪═════════════╪════════════════╡", - "│ DummyScript.yml │ Script │ DummyPack │ 1.0.0 │", - "╘═════════════════╧════════╧═════════════╧════════════════╛", - "", - ) + ( + "SUCCESSFUL UPLOADS:", + "╒═════════════════╤════════╤═════════════╤════════════════╕", + "│ NAME │ TYPE │ PACK NAME │ PACK VERSION │", + "╞═════════════════╪════════╪═════════════╪════════════════╡", + "│ DummyScript.yml │ Script │ DummyPack │ 1.0.0 │", + "╘═════════════════╧════════╧═════════════╧════════════════╛", + "", ) - assert ( - res - in caplog.text ) + assert res in caplog.text def test_print_summary_failed_uploaded(self, caplog, mocker): """ From 53671989d83b7bf5a7fd215d8b5b29f1d17c1ba7 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Wed, 13 Nov 2024 13:27:30 +0200 Subject: [PATCH 13/59] tests fixes --- demisto_sdk/commands/pre_commit/hooks/docker.py | 2 +- .../tests/integration_tests/upload_integration_test.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/demisto_sdk/commands/pre_commit/hooks/docker.py b/demisto_sdk/commands/pre_commit/hooks/docker.py index 94dde62c7be..82bd6bc4c00 100644 --- a/demisto_sdk/commands/pre_commit/hooks/docker.py +++ b/demisto_sdk/commands/pre_commit/hooks/docker.py @@ -89,7 +89,7 @@ def get_docker_python_path(drop_site_packages: bool = False) -> str: Returns: A PYTHONPATH formatted string """ path_to_replace = str(Path(ContentPaths.CONTENT_PATH).absolute()) - docker_path = [str(path).replace(path_to_replace, "/src") for path in PYTHONPATH] + docker_path = [str(path).replace(path_to_replace, "/src") for path in ContentPaths.PYTHONPATH] if drop_site_packages: docker_path = [p for p in docker_path if "site-packages" not in p] path = ":".join(docker_path) diff --git a/demisto_sdk/tests/integration_tests/upload_integration_test.py b/demisto_sdk/tests/integration_tests/upload_integration_test.py index 1c1e32d48b1..5c0554a3562 100644 --- a/demisto_sdk/tests/integration_tests/upload_integration_test.py +++ b/demisto_sdk/tests/integration_tests/upload_integration_test.py @@ -62,8 +62,8 @@ def test_integration_upload_pack_positive(demisto_client_mock, mocker): DEMISTO_SDK_PATH, "tests/test_files/content_repo_example/Packs/FeedAzure" ) mocker.patch.object( - content_item, - "ContentPaths.CONTENT_PATH", + content_item.ContentPaths, + "CONTENT_PATH", Path(DEMISTO_SDK_PATH, "tests/test_files/content_repo_example"), ) @@ -121,8 +121,8 @@ def test_integration_upload_pack_with_specific_marketplace(demisto_client_mock, "tests/test_files/content_repo_example/Packs/ExamplePack/Integrations", ) mocker.patch.object( - content_item, - "ContentPaths.CONTENT_PATH", + content_item.ContentPaths, + "CONTENT_PATH", Path(DEMISTO_SDK_PATH, "tests/test_files/content_repo_example"), ) From 68cbd969551767bb80b4cc90192b7ed4dba210d1 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Wed, 13 Nov 2024 14:07:07 +0200 Subject: [PATCH 14/59] test fixes --- demisto_sdk/commands/pre_commit/hooks/docker.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/commands/pre_commit/hooks/docker.py b/demisto_sdk/commands/pre_commit/hooks/docker.py index 82bd6bc4c00..971ff2cfae3 100644 --- a/demisto_sdk/commands/pre_commit/hooks/docker.py +++ b/demisto_sdk/commands/pre_commit/hooks/docker.py @@ -89,7 +89,9 @@ def get_docker_python_path(drop_site_packages: bool = False) -> str: Returns: A PYTHONPATH formatted string """ path_to_replace = str(Path(ContentPaths.CONTENT_PATH).absolute()) - docker_path = [str(path).replace(path_to_replace, "/src") for path in ContentPaths.PYTHONPATH] + docker_path = [ + str(path).replace(path_to_replace, "/src") for path in ContentPaths.PYTHONPATH + ] if drop_site_packages: docker_path = [p for p in docker_path if "site-packages" not in p] path = ":".join(docker_path) From baf7eb5d6fd3d5d7ddafb6c40baecfa9d1999945 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 10:34:44 +0200 Subject: [PATCH 15/59] test fixes --- conftest.py | 2 -- demisto_sdk/commands/setup_env/tests/setup_environment_test.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index 29c2810cd6a..9f3ec18d44c 100644 --- a/conftest.py +++ b/conftest.py @@ -99,9 +99,7 @@ def graph_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Ge """ import demisto_sdk.commands.content_graph.neo4j_service as neo4j_service import demisto_sdk.commands.content_graph.objects.base_content as bc - repo = get_repo(request, tmp_path_factory) - bc.ContentPaths.update_content_path(Path(repo.path)) neo4j_path = bc.ContentPaths.CONTENT_PATH.parent.parent / "neo4j" diff --git a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py index 20c9fd431b1..81b13fdff45 100644 --- a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py +++ b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py @@ -37,7 +37,7 @@ def test_setup_env_vscode(mocker, monkeypatch, pack, create_virtualenv): repo_path = Path(pack.repo_path) mocker.patch.object(setup_environment.ContentPaths, "CONTENT_PATH", repo_path) mocker.patch.object( - setup_environment.ContentPaths, "DOTENV_PATH", repo_path / ".env" + setup_environment, "DOTENV_PATH", repo_path / ".env" ) mocker.patch.object( From 3fa8e86eae2bbf627d9882bbf365e4ae7142ed6a Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 10:49:24 +0200 Subject: [PATCH 16/59] Introducing 'DEMISTO_SDK_SKIP_LOGGER_SETUP' envvar. --- demisto_sdk/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/__init__.py b/demisto_sdk/__init__.py index 5bf2275f6b7..a9cb11e55df 100644 --- a/demisto_sdk/__init__.py +++ b/demisto_sdk/__init__.py @@ -1,4 +1,6 @@ -if __name__ in ["__main__", "demisto_sdk"]: +import os + +if not os.environ.get("DEMISTO_SDK_SKIP_LOGGER_SETUP", False): from demisto_sdk.commands.common.logger import logging_setup logging_setup(initial=True, calling_function="__init__") From 6649827539e7c4a45cfe36868dceacf3aa28fb24 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 10:49:39 +0200 Subject: [PATCH 17/59] ruff --- conftest.py | 1 + .../commands/setup_env/tests/setup_environment_test.py | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index 9f3ec18d44c..fdb7a59f10d 100644 --- a/conftest.py +++ b/conftest.py @@ -99,6 +99,7 @@ def graph_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Ge """ import demisto_sdk.commands.content_graph.neo4j_service as neo4j_service import demisto_sdk.commands.content_graph.objects.base_content as bc + repo = get_repo(request, tmp_path_factory) bc.ContentPaths.update_content_path(Path(repo.path)) neo4j_path = bc.ContentPaths.CONTENT_PATH.parent.parent / "neo4j" diff --git a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py index 81b13fdff45..0371ffcd073 100644 --- a/demisto_sdk/commands/setup_env/tests/setup_environment_test.py +++ b/demisto_sdk/commands/setup_env/tests/setup_environment_test.py @@ -36,9 +36,7 @@ def test_setup_env_vscode(mocker, monkeypatch, pack, create_virtualenv): params = {"username": "user", "password": "pass"} repo_path = Path(pack.repo_path) mocker.patch.object(setup_environment.ContentPaths, "CONTENT_PATH", repo_path) - mocker.patch.object( - setup_environment, "DOTENV_PATH", repo_path / ".env" - ) + mocker.patch.object(setup_environment, "DOTENV_PATH", repo_path / ".env") mocker.patch.object( setup_environment.ContentPaths, From 35eb0ce908bbed706e57374bf329f78fb9e19335 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 11:47:04 +0200 Subject: [PATCH 18/59] logger setup envvar resolution --- demisto_sdk/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/__init__.py b/demisto_sdk/__init__.py index a9cb11e55df..d0c7c923c87 100644 --- a/demisto_sdk/__init__.py +++ b/demisto_sdk/__init__.py @@ -1,6 +1,6 @@ import os -if not os.environ.get("DEMISTO_SDK_SKIP_LOGGER_SETUP", False): +if not os.environ.get("DEMISTO_SDK_SKIP_LOGGER_SETUP").lower() in ['true', 'yes', '1']: from demisto_sdk.commands.common.logger import logging_setup logging_setup(initial=True, calling_function="__init__") From 157040f254c8b031c789f15e7327a4cf8600104b Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 12:22:51 +0200 Subject: [PATCH 19/59] ruff --- demisto_sdk/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/__init__.py b/demisto_sdk/__init__.py index d0c7c923c87..81d1498c526 100644 --- a/demisto_sdk/__init__.py +++ b/demisto_sdk/__init__.py @@ -1,6 +1,10 @@ import os -if not os.environ.get("DEMISTO_SDK_SKIP_LOGGER_SETUP").lower() in ['true', 'yes', '1']: +if os.environ.get("DEMISTO_SDK_SKIP_LOGGER_SETUP", "False").lower() not in [ + "true", + "yes", + "1", +]: from demisto_sdk.commands.common.logger import logging_setup logging_setup(initial=True, calling_function="__init__") From 2b1c50248d1eecf0b1a3cd6e8bc0030528aef509 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 13:42:17 +0200 Subject: [PATCH 20/59] set CONTENT_PATH within graph creation --- demisto_sdk/commands/content_graph/content_graph_builder.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/demisto_sdk/commands/content_graph/content_graph_builder.py b/demisto_sdk/commands/content_graph/content_graph_builder.py index ef6a73ffa6e..1209777bfff 100644 --- a/demisto_sdk/commands/content_graph/content_graph_builder.py +++ b/demisto_sdk/commands/content_graph/content_graph_builder.py @@ -45,6 +45,8 @@ def _parse_and_model_content( self, packs_to_parse: Optional[Tuple[str, ...]] = None ) -> None: content_dto: ContentDTO = self._create_content_dto(packs_to_parse) + from demisto_sdk.commands.common.content_constant_paths import ContentPaths + ContentPaths.update_content_path(ContentDTO.path) self._collect_nodes_and_relationships_from_model(content_dto) def _create_content_dto(self, packs: Optional[Tuple[str, ...]]) -> ContentDTO: From 97819c9d5ca0ed98fab5406746104e6871db26c5 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 14:51:27 +0200 Subject: [PATCH 21/59] update content path in graph creation --- demisto_sdk/commands/content_graph/content_graph_builder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/commands/content_graph/content_graph_builder.py b/demisto_sdk/commands/content_graph/content_graph_builder.py index 1209777bfff..d4bcc31b2ec 100644 --- a/demisto_sdk/commands/content_graph/content_graph_builder.py +++ b/demisto_sdk/commands/content_graph/content_graph_builder.py @@ -46,7 +46,8 @@ def _parse_and_model_content( ) -> None: content_dto: ContentDTO = self._create_content_dto(packs_to_parse) from demisto_sdk.commands.common.content_constant_paths import ContentPaths - ContentPaths.update_content_path(ContentDTO.path) + + ContentPaths.update_content_path(content_dto.path) self._collect_nodes_and_relationships_from_model(content_dto) def _create_content_dto(self, packs: Optional[Tuple[str, ...]]) -> ContentDTO: From 5659403511b149662a7d1cdee8219ff79fefbe26 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 15:05:19 +0200 Subject: [PATCH 22/59] update content path in graph creation --- demisto_sdk/commands/common/content_constant_paths.py | 2 +- demisto_sdk/commands/content_graph/content_graph_builder.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 3027c8874b8..09e2fb30ff7 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -46,7 +46,7 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: """ logger.info(f"Updating content_path globally: {content_path}") - cls.CONTENT_PATH = Path(content_path) + cls.CONTENT_PATH = Path(get_content_path(content_path)) cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = ( cls.CONTENT_PATH / "all_packs_dependencies.json" ) diff --git a/demisto_sdk/commands/content_graph/content_graph_builder.py b/demisto_sdk/commands/content_graph/content_graph_builder.py index d4bcc31b2ec..2d3502970e2 100644 --- a/demisto_sdk/commands/content_graph/content_graph_builder.py +++ b/demisto_sdk/commands/content_graph/content_graph_builder.py @@ -1,6 +1,7 @@ import gc from typing import Optional, Tuple +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.common import Nodes, Relationships from demisto_sdk.commands.content_graph.interface.graph import ContentGraphInterface from demisto_sdk.commands.content_graph.objects.repository import ( @@ -45,7 +46,6 @@ def _parse_and_model_content( self, packs_to_parse: Optional[Tuple[str, ...]] = None ) -> None: content_dto: ContentDTO = self._create_content_dto(packs_to_parse) - from demisto_sdk.commands.common.content_constant_paths import ContentPaths ContentPaths.update_content_path(content_dto.path) self._collect_nodes_and_relationships_from_model(content_dto) From 7d61313a86906cb1613cb161aa3e9b52a37081d5 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 15:13:11 +0200 Subject: [PATCH 23/59] mypy fix --- demisto_sdk/commands/common/content_constant_paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 09e2fb30ff7..531613f0a4a 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -46,7 +46,7 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: """ logger.info(f"Updating content_path globally: {content_path}") - cls.CONTENT_PATH = Path(get_content_path(content_path)) + cls.CONTENT_PATH = Path(get_content_path(Path(content_path))) cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = ( cls.CONTENT_PATH / "all_packs_dependencies.json" ) From 11ab75efb3968821acb863223197d56c0e00b15b Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 15:46:17 +0200 Subject: [PATCH 24/59] content paths fix --- .../commands/common/content_constant_paths.py | 18 +++++++++--------- .../commands/pre_commit/pre_commit_context.py | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 531613f0a4a..256b3c953f6 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -46,22 +46,22 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: """ logger.info(f"Updating content_path globally: {content_path}") - cls.CONTENT_PATH = Path(get_content_path(Path(content_path))) + cls.CONTENT_PATH: Path = Path(get_content_path(Path(content_path))) cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = ( cls.CONTENT_PATH / "all_packs_dependencies.json" ) - cls.CONF_PATH = cls.CONTENT_PATH / TESTS_DIR / "conf.json" - cls.DEFAULT_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set.json" - cls.MP_V2_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" - cls.XPANSE_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" - cls.LANDING_PAGE_SECTIONS_PATH = ( + cls.CONF_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "conf.json" + cls.DEFAULT_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set.json" + cls.MP_V2_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" + cls.XPANSE_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" + cls.LANDING_PAGE_SECTIONS_PATH: Path = ( cls.CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" ) - cls.NATIVE_IMAGE_PATH = cls.CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME - cls.COMMON_SERVER_PYTHON_PATH = ( + cls.NATIVE_IMAGE_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME + cls.COMMON_SERVER_PYTHON_PATH: Path = ( cls.CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" ) - cls.DEMISTO_MOCK_PATH = cls.CONTENT_PATH / TESTS_DIR / "demistomock" + cls.DEMISTO_MOCK_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "demistomock" cls.API_MODULES_SCRIPTS_DIR = ( cls.CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" ) diff --git a/demisto_sdk/commands/pre_commit/pre_commit_context.py b/demisto_sdk/commands/pre_commit/pre_commit_context.py index 4da8455898d..d784385f1cc 100644 --- a/demisto_sdk/commands/pre_commit/pre_commit_context.py +++ b/demisto_sdk/commands/pre_commit/pre_commit_context.py @@ -55,6 +55,7 @@ class PreCommitContext: docker_image: Optional[str] = None dry_run: bool = False pre_commit_template_path: Path = PRECOMMIT_TEMPLATE_PATH + default_config_file def __post_init__(self): """ From 511f3c7d1ec46120b73dbb7de1afa63be4b9e044 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 15:52:44 +0200 Subject: [PATCH 25/59] revert --- demisto_sdk/commands/common/content_constant_paths.py | 8 ++++++-- demisto_sdk/commands/pre_commit/pre_commit_context.py | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 256b3c953f6..ba11d9ca561 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -53,11 +53,15 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: cls.CONF_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "conf.json" cls.DEFAULT_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set.json" cls.MP_V2_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" - cls.XPANSE_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" + cls.XPANSE_ID_SET_PATH: Path = ( + cls.CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" + ) cls.LANDING_PAGE_SECTIONS_PATH: Path = ( cls.CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" ) - cls.NATIVE_IMAGE_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME + cls.NATIVE_IMAGE_PATH: Path = ( + cls.CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME + ) cls.COMMON_SERVER_PYTHON_PATH: Path = ( cls.CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" ) diff --git a/demisto_sdk/commands/pre_commit/pre_commit_context.py b/demisto_sdk/commands/pre_commit/pre_commit_context.py index d784385f1cc..4da8455898d 100644 --- a/demisto_sdk/commands/pre_commit/pre_commit_context.py +++ b/demisto_sdk/commands/pre_commit/pre_commit_context.py @@ -55,7 +55,6 @@ class PreCommitContext: docker_image: Optional[str] = None dry_run: bool = False pre_commit_template_path: Path = PRECOMMIT_TEMPLATE_PATH - default_config_file def __post_init__(self): """ From f222dc24cc4f836f17dd888586ccba57d3b9f71c Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 15:59:57 +0200 Subject: [PATCH 26/59] precommit --- .../commands/common/content_constant_paths.py | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index ba11d9ca561..531613f0a4a 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -46,26 +46,22 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: """ logger.info(f"Updating content_path globally: {content_path}") - cls.CONTENT_PATH: Path = Path(get_content_path(Path(content_path))) + cls.CONTENT_PATH = Path(get_content_path(Path(content_path))) cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = ( cls.CONTENT_PATH / "all_packs_dependencies.json" ) - cls.CONF_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "conf.json" - cls.DEFAULT_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set.json" - cls.MP_V2_ID_SET_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" - cls.XPANSE_ID_SET_PATH: Path = ( - cls.CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" - ) - cls.LANDING_PAGE_SECTIONS_PATH: Path = ( + cls.CONF_PATH = cls.CONTENT_PATH / TESTS_DIR / "conf.json" + cls.DEFAULT_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set.json" + cls.MP_V2_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set_mp_v2.json" + cls.XPANSE_ID_SET_PATH = cls.CONTENT_PATH / TESTS_DIR / "id_set_xpanse.json" + cls.LANDING_PAGE_SECTIONS_PATH = ( cls.CONTENT_PATH / TESTS_DIR / "Marketplace" / "landingPage_sections.json" ) - cls.NATIVE_IMAGE_PATH: Path = ( - cls.CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME - ) - cls.COMMON_SERVER_PYTHON_PATH: Path = ( + cls.NATIVE_IMAGE_PATH = cls.CONTENT_PATH / TESTS_DIR / NATIVE_IMAGE_FILE_NAME + cls.COMMON_SERVER_PYTHON_PATH = ( cls.CONTENT_PATH / "Packs" / "Base" / "Scripts" / "CommonServerPython" ) - cls.DEMISTO_MOCK_PATH: Path = cls.CONTENT_PATH / TESTS_DIR / "demistomock" + cls.DEMISTO_MOCK_PATH = cls.CONTENT_PATH / TESTS_DIR / "demistomock" cls.API_MODULES_SCRIPTS_DIR = ( cls.CONTENT_PATH / "Packs" / "ApiModules" / "Scripts" ) From 2978afffa7d5936dd6cab5db38bf82a4fc652b45 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 14 Nov 2024 16:36:39 +0200 Subject: [PATCH 27/59] fixes --- TestSuite/repo.py | 2 ++ demisto_sdk/commands/common/content_constant_paths.py | 1 + 2 files changed, 3 insertions(+) diff --git a/TestSuite/repo.py b/TestSuite/repo.py index b19a53702c7..eb28aedbf7f 100644 --- a/TestSuite/repo.py +++ b/TestSuite/repo.py @@ -4,6 +4,7 @@ from typing import List, Optional from demisto_sdk.commands.common.constants import DEMISTO_GIT_PRIMARY_BRANCH +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.git_util import GitUtil from demisto_sdk.commands.content_graph.commands.create import create_content_graph from demisto_sdk.commands.content_graph.interface import ( @@ -43,6 +44,7 @@ def __init__(self, tmpdir: Path, init_git: bool = False): self._packs_path: Path = tmpdir / "Packs" self._packs_path.mkdir() self.path = str(self._tmpdir) + ContentPaths.update_content_path(self.path) # Initiate ./Tests/ dir self._test_dir = tmpdir / "Tests" diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 531613f0a4a..7b5cccbe4fe 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -47,6 +47,7 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: logger.info(f"Updating content_path globally: {content_path}") cls.CONTENT_PATH = Path(get_content_path(Path(content_path))) + logger.info(f"CONTENT_PATH Type: {type(cls.CONTENT_PATH)}") cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = ( cls.CONTENT_PATH / "all_packs_dependencies.json" ) From 77800e76c723a22c6e2b91c82bf5af84f650c8e2 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 02:07:55 +0200 Subject: [PATCH 28/59] fix graph tests --- conftest.py | 14 ++++++++------ .../commands/common/content_constant_paths.py | 2 +- .../content_graph/content_graph_builder.py | 4 +--- .../content_graph/tests/format_with_graph_test.py | 1 - .../content_graph/tests/graph_validator_test.py | 2 ++ 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/conftest.py b/conftest.py index fdb7a59f10d..6d85437b076 100644 --- a/conftest.py +++ b/conftest.py @@ -2,7 +2,6 @@ import os import shutil -from pathlib import Path from typing import Generator from unittest import mock @@ -24,13 +23,17 @@ def get_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo: - tmp_dir = _mk_tmp(request, tmp_path_factory) - return Repo(tmp_dir) + content_tmp_dir = _mk_tmp(request, tmp_path_factory) / "content" + content_tmp_dir.mkdir() + return Repo(content_tmp_dir) def get_git_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo: - tmp_dir = _mk_tmp(request, tmp_path_factory) - return Repo(tmp_dir, init_git=True) + content_tmp_dir = ( + _mk_tmp(request, tmp_path_factory).with_name("content") / "content" + ) + content_tmp_dir.mkdir() + return Repo(content_tmp_dir, init_git=True) def get_pack(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Pack: @@ -101,7 +104,6 @@ def graph_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Ge import demisto_sdk.commands.content_graph.objects.base_content as bc repo = get_repo(request, tmp_path_factory) - bc.ContentPaths.update_content_path(Path(repo.path)) neo4j_path = bc.ContentPaths.CONTENT_PATH.parent.parent / "neo4j" mock.patch.object(ContentGraphInterface, "repo_path", bc.ContentPaths.CONTENT_PATH) diff --git a/demisto_sdk/commands/common/content_constant_paths.py b/demisto_sdk/commands/common/content_constant_paths.py index 7b5cccbe4fe..f45dd9978a9 100644 --- a/demisto_sdk/commands/common/content_constant_paths.py +++ b/demisto_sdk/commands/common/content_constant_paths.py @@ -46,7 +46,7 @@ def update_content_path(cls, content_path: Union[str, Path]) -> None: """ logger.info(f"Updating content_path globally: {content_path}") - cls.CONTENT_PATH = Path(get_content_path(Path(content_path))) + cls.CONTENT_PATH = Path(content_path) logger.info(f"CONTENT_PATH Type: {type(cls.CONTENT_PATH)}") cls.ALL_PACKS_DEPENDENCIES_DEFAULT_PATH = ( cls.CONTENT_PATH / "all_packs_dependencies.json" diff --git a/demisto_sdk/commands/content_graph/content_graph_builder.py b/demisto_sdk/commands/content_graph/content_graph_builder.py index 2d3502970e2..8f5988aceb5 100644 --- a/demisto_sdk/commands/content_graph/content_graph_builder.py +++ b/demisto_sdk/commands/content_graph/content_graph_builder.py @@ -1,7 +1,6 @@ import gc from typing import Optional, Tuple -from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.content_graph.common import Nodes, Relationships from demisto_sdk.commands.content_graph.interface.graph import ContentGraphInterface from demisto_sdk.commands.content_graph.objects.repository import ( @@ -46,8 +45,7 @@ def _parse_and_model_content( self, packs_to_parse: Optional[Tuple[str, ...]] = None ) -> None: content_dto: ContentDTO = self._create_content_dto(packs_to_parse) - - ContentPaths.update_content_path(content_dto.path) + # ContentPaths.update_content_path(content_dto.path) self._collect_nodes_and_relationships_from_model(content_dto) def _create_content_dto(self, packs: Optional[Tuple[str, ...]]) -> ContentDTO: diff --git a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py index 56f2d68f9dc..dec0e547e2a 100644 --- a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py @@ -61,7 +61,6 @@ def setup_method(mocker, tmp_path_factory, repo: Repo): @pytest.fixture def repository(mocker, repo) -> ContentDTO: repository = ContentDTO( - path=Path(repo.path), packs=[], ) relationships = { diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index 0a56acd06fd..977d0f25908 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -9,6 +9,7 @@ SKIP_PREPARE_SCRIPT_NAME, MarketplaceVersions, ) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.docker.docker_image import DockerImage from demisto_sdk.commands.common.hook_validations.graph_validator import GraphValidator from demisto_sdk.commands.common.legacy_git_tools import git_path @@ -373,6 +374,7 @@ def repository(mocker) -> ContentDTO: "demisto_sdk.commands.content_graph.content_graph_builder.ContentGraphBuilder._create_content_dto", return_value=repository, ) + ContentPaths.update_content_path(repository.path) return repository From 5e3e6d54e1672e3f3566601014a425404acf4426 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 11:31:49 +0200 Subject: [PATCH 29/59] fix graph tests --- .../commands/content_graph/content_graph_builder.py | 1 - .../commands/content_graph/tests/graph_validator_test.py | 7 +++---- .../content_graph/tests/update_content_graph_test.py | 5 ++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/demisto_sdk/commands/content_graph/content_graph_builder.py b/demisto_sdk/commands/content_graph/content_graph_builder.py index 8f5988aceb5..ef6a73ffa6e 100644 --- a/demisto_sdk/commands/content_graph/content_graph_builder.py +++ b/demisto_sdk/commands/content_graph/content_graph_builder.py @@ -45,7 +45,6 @@ def _parse_and_model_content( self, packs_to_parse: Optional[Tuple[str, ...]] = None ) -> None: content_dto: ContentDTO = self._create_content_dto(packs_to_parse) - # ContentPaths.update_content_path(content_dto.path) self._collect_nodes_and_relationships_from_model(content_dto) def _create_content_dto(self, packs: Optional[Tuple[str, ...]]) -> ContentDTO: diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index 977d0f25908..36651b750c0 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -65,8 +65,10 @@ def setup_method(mocker, tmp_path_factory): @pytest.fixture def repository(mocker) -> ContentDTO: + repo_path = ContentPaths.CONTENT_PATH.with_name("content") + ContentPaths.update_content_path(repo_path) repository = ContentDTO( - path=GIT_PATH, + path=repo_path, packs=[], ) relationships = { @@ -374,13 +376,10 @@ def repository(mocker) -> ContentDTO: "demisto_sdk.commands.content_graph.content_graph_builder.ContentGraphBuilder._create_content_dto", return_value=repository, ) - ContentPaths.update_content_path(repository.path) return repository # HELPERS - - def mock_dependency(source: str, target: str, mandatory: bool = True) -> Dict[str, Any]: return { "source_id": source, diff --git a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py index c596beb36ff..ecde316b0ec 100644 --- a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py @@ -6,6 +6,7 @@ import demisto_sdk.commands.content_graph.neo4j_service as neo4j_service from demisto_sdk.commands.common.constants import MarketplaceVersions +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.legacy_git_tools import git_path from demisto_sdk.commands.content_graph.commands.create import ( create_content_graph, @@ -68,8 +69,10 @@ def setup_method(mocker, tmp_path_factory): @pytest.fixture def repository(mocker) -> ContentDTO: + repo_path = ContentPaths.CONTENT_PATH.with_name("content") + ContentPaths.update_content_path(repo_path) repository = ContentDTO( - path=GIT_PATH, + path=repo_path, packs=[], ) relationships = { From 4d6fd25c6ff5bfa7dfd1f2d4dfa60a20b6cfbb58 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 11:41:34 +0200 Subject: [PATCH 30/59] fix graph tests --- .../commands/content_graph/tests/update_content_graph_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py index ecde316b0ec..f0211f5f378 100644 --- a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py @@ -70,6 +70,7 @@ def setup_method(mocker, tmp_path_factory): @pytest.fixture def repository(mocker) -> ContentDTO: repo_path = ContentPaths.CONTENT_PATH.with_name("content") + repo_path.mkdir() ContentPaths.update_content_path(repo_path) repository = ContentDTO( path=repo_path, From b7dc0de3ab82b666b0b0126a712966fe4006bb17 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 11:48:54 +0200 Subject: [PATCH 31/59] fix graph tests --- demisto_sdk/commands/content_graph/tests/graph_validator_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index 36651b750c0..0d4e2e36ea8 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -66,6 +66,7 @@ def setup_method(mocker, tmp_path_factory): @pytest.fixture def repository(mocker) -> ContentDTO: repo_path = ContentPaths.CONTENT_PATH.with_name("content") + repo_path.mkdir() ContentPaths.update_content_path(repo_path) repository = ContentDTO( path=repo_path, From 521b4b0f3c2a3975c810b876c1336e73939135a4 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 11:59:19 +0200 Subject: [PATCH 32/59] fix graph tests --- .../commands/content_graph/tests/graph_validator_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index 0d4e2e36ea8..60b11564b9a 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -66,7 +66,7 @@ def setup_method(mocker, tmp_path_factory): @pytest.fixture def repository(mocker) -> ContentDTO: repo_path = ContentPaths.CONTENT_PATH.with_name("content") - repo_path.mkdir() + repo_path.mkdir(exist_ok=True) ContentPaths.update_content_path(repo_path) repository = ContentDTO( path=repo_path, From c670acf9cb358ad81357c1a4097a683a029bf000 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 12:01:42 +0200 Subject: [PATCH 33/59] fix graph tests --- .../commands/content_graph/tests/graph_validator_test.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index 60b11564b9a..39cf42be192 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path from typing import Any, Callable, Dict, List, Optional @@ -62,12 +63,18 @@ def setup_method(mocker, tmp_path_factory): }, ) +def mk_content_dir(repo_path: Path): + if repo_path.exists(): + shutil.rmtree(repo_path) + repo_path.mkdir() + @pytest.fixture def repository(mocker) -> ContentDTO: repo_path = ContentPaths.CONTENT_PATH.with_name("content") - repo_path.mkdir(exist_ok=True) + mk_content_dir(repo_path) ContentPaths.update_content_path(repo_path) + repository = ContentDTO( path=repo_path, packs=[], From 4b3b257cd3a4765847a6c805b5e0ea92b18489dc Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 12:03:45 +0200 Subject: [PATCH 34/59] fix graph tests --- .../commands/content_graph/tests/graph_validator_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index 39cf42be192..f9196f8ceef 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -63,6 +63,7 @@ def setup_method(mocker, tmp_path_factory): }, ) + def mk_content_dir(repo_path: Path): if repo_path.exists(): shutil.rmtree(repo_path) @@ -74,7 +75,7 @@ def repository(mocker) -> ContentDTO: repo_path = ContentPaths.CONTENT_PATH.with_name("content") mk_content_dir(repo_path) ContentPaths.update_content_path(repo_path) - + repository = ContentDTO( path=repo_path, packs=[], From c33d65621a8e05c4906256edf529526cea608b8f Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 13:21:57 +0200 Subject: [PATCH 35/59] fix graph tests --- conftest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index 6d85437b076..4daf5b5fd24 100644 --- a/conftest.py +++ b/conftest.py @@ -29,9 +29,7 @@ def get_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo def get_git_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo: - content_tmp_dir = ( - _mk_tmp(request, tmp_path_factory).with_name("content") / "content" - ) + content_tmp_dir = _mk_tmp(request, tmp_path_factory) / "content" content_tmp_dir.mkdir() return Repo(content_tmp_dir, init_git=True) From 181c2bfe561497fcd96da3af12f5dbe146b875ba Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 14:45:53 +0200 Subject: [PATCH 36/59] fix graph tests --- .../commands/content_graph/commands/get_relationships.py | 4 ++-- .../content_graph/tests/create_content_graph_test.py | 8 ++++++-- .../content_graph/tests/update_content_graph_test.py | 9 ++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/demisto_sdk/commands/content_graph/commands/get_relationships.py b/demisto_sdk/commands/content_graph/commands/get_relationships.py index 949b3e3424f..319e00a3adf 100644 --- a/demisto_sdk/commands/content_graph/commands/get_relationships.py +++ b/demisto_sdk/commands/content_graph/commands/get_relationships.py @@ -248,12 +248,12 @@ def path_to_str( ) -> str: def node_to_str(node_data: dict) -> str: name = f"{node_data['name']}" - content_type = f"{node_data['content_type']}" + content_type = f"{node_data['content_type']}" path = node_data["path"] return f"• ({name}:{content_type} {{path: {path}}})\n" def rel_to_str(rel: RelationshipType, props: dict) -> str: - return f" └─ [{rel}]{props or ''} ↴\n" + return f" └─ [{rel}]{props or ''} ↴\n" path_str = "" for idx, path_element in enumerate(path): diff --git a/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py index 536679da348..e568cfa3747 100644 --- a/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py @@ -9,6 +9,7 @@ SKIP_PREPARE_SCRIPT_NAME, MarketplaceVersions, ) +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.docker.docker_image import DockerImage from demisto_sdk.commands.content_graph.common import ( ContentType, @@ -38,9 +39,12 @@ @pytest.fixture -def repository(mocker): +def repository(mocker, tmp_path: Path): + content_temp_dir = tmp_path / "content" + content_temp_dir.mkdir() + ContentPaths.update_content_path(content_temp_dir) + repository = ContentDTO( - path=Path(), packs=[], ) mocker.patch( diff --git a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py index f0211f5f378..e9828347897 100644 --- a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path from typing import Any, Callable, Dict, List from zipfile import ZipFile @@ -67,10 +68,16 @@ def setup_method(mocker, tmp_path_factory): ) +def mk_content_dir(repo_path: Path): + if repo_path.exists(): + shutil.rmtree(repo_path) + repo_path.mkdir() + + @pytest.fixture def repository(mocker) -> ContentDTO: repo_path = ContentPaths.CONTENT_PATH.with_name("content") - repo_path.mkdir() + mk_content_dir(repo_path) ContentPaths.update_content_path(repo_path) repository = ContentDTO( path=repo_path, From fa4f18f01a74c67d6f7a6b9b978a9b18f0612a2f Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 15:26:07 +0200 Subject: [PATCH 37/59] fix graph tests --- .../content_graph/tests/update_content_graph_test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py index e9828347897..34c2fde7e56 100644 --- a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py @@ -217,9 +217,12 @@ def mock__create_content_dto(packs_to_update: List[str]) -> ContentDTO: @pytest.fixture -def external_repository(mocker) -> ContentDTO: +def external_repository(mocker, tmp_path: Path) -> ContentDTO: + content_temp_dir = tmp_path / "content" + content_temp_dir.mkdir() + ContentPaths.update_content_path(content_temp_dir) + repository = ContentDTO( - path=GIT_PATH, packs=[], ) From 29043d659f339b1c13934c9a018c72684cef35ce Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 15:38:24 +0200 Subject: [PATCH 38/59] fix graph tests --- demisto_sdk/commands/validate/tests/test_tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index 4f439345d75..c7893586b9d 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -1,3 +1,4 @@ +import os import tempfile from pathlib import Path from typing import Any, Dict, List, Optional, cast @@ -55,7 +56,9 @@ from TestSuite.file import File from TestSuite.repo import Repo -REPO = Repo(tmpdir=Path(tempfile.mkdtemp()), init_git=True) +content_temp_dir = Path(os.path.join(tempfile.mkdtemp(), "content")) +content_temp_dir.mkdir() +REPO = Repo(tmpdir=content_temp_dir, init_git=True) def create_integration_object( From 64745f14290e6b0fa34e2a342921ab315efc1c50 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 17:57:56 +0200 Subject: [PATCH 39/59] fix graph tests --- .../tests/parsers_and_models_test.py | 10 +-- .../commands/validate/tests/test_tools.py | 71 ++++++++++--------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py b/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py index f91e445b9e1..3fd22bb3525 100644 --- a/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py +++ b/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py @@ -28,10 +28,10 @@ from demisto_sdk.commands.content_graph.parsers.pack import PackParser from demisto_sdk.commands.content_graph.tests.test_tools import load_json, load_yaml from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_classifier_object, create_integration_object, create_pack_object, + get_repo, ) from TestSuite.pack import Pack from TestSuite.repo import Repo @@ -284,7 +284,7 @@ def run( class TestParsersAndModels: - def test_classifier_parser_below_min_marketplace_version(self): + def test_classifier_parser_below_min_marketplace_version(self, git_repo): """ Given: - A pack with a classifier. @@ -298,7 +298,7 @@ def test_classifier_parser_below_min_marketplace_version(self): ClassifierParser, ) - with ChangeCWD(REPO.path): + with ChangeCWD(git_repo.path): classifier = create_classifier_object(paths=["toVersion"], values=["5.9.9"]) classifier_path = Path(classifier.path) with pytest.raises(NotAContentItemException): @@ -3057,7 +3057,7 @@ def test_support_attribute_in_integration_object( Then: - Ensure that the support attribute of the Integration object is set to the expected support level, e.g., the integration support level if it is not an empty string, or the pack support level otherwise. """ - with ChangeCWD(REPO.path): + with ChangeCWD(get_repo().path): test_integration = create_integration_object( paths=["supportlevelheader"], values=[integration_support], @@ -3080,7 +3080,7 @@ def test_layout_parser_group(): """ from demisto_sdk.commands.content_graph.parsers.layout import LayoutParser - pack = REPO.create_pack("TestPack") + pack = get_repo().create_pack("TestPack") layout = pack.create_layoutcontainer( "TestLayoutscontainer", content={ diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index c7893586b9d..3e6f3c81449 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -56,9 +56,12 @@ from TestSuite.file import File from TestSuite.repo import Repo -content_temp_dir = Path(os.path.join(tempfile.mkdtemp(), "content")) -content_temp_dir.mkdir() -REPO = Repo(tmpdir=content_temp_dir, init_git=True) + +def get_repo(): + content_temp_dir = Path(os.path.join(tempfile.mkdtemp(), "content")) + content_temp_dir.mkdir() + + return Repo(tmpdir=content_temp_dir, init_git=True) def create_integration_object( @@ -83,7 +86,7 @@ def create_integration_object( yml_content = load_yaml("integration.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_repo.create_pack() if pack_info: pack.set_data(**pack_info) @@ -122,7 +125,7 @@ def create_parsing_rule_object( """ yml_content = load_yaml("parsing_rule.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() parsing_rule = pack.create_parsing_rule("TestParsingRule", yml_content) parser = ParsingRuleParser(Path(parsing_rule.path), list(MarketplaceVersions)) return ParsingRule.from_orm(parser) @@ -143,7 +146,7 @@ def create_correlation_rule_object( """ yml_content = load_yaml("correlation_rule_test.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_correlation_rule(name="correlation_rule", content=yml_content) return cast( CorrelationRule, BaseContent.from_path(Path(pack.correlation_rules[0].path)) @@ -168,7 +171,7 @@ def create_playbook_object( """ yml_content = load_yaml("playbook.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() if pack_info: pack.set_data(**pack_info) additional_params = {} @@ -218,7 +221,7 @@ def create_modeling_rule_object( """ yml_content = load_yaml("modeling_rule.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_modeling_rule(yml=yml_content, rules=rules, schema=schema) return cast(ModelingRule, BaseContent.from_path(Path(pack.modeling_rules[0].path))) @@ -238,7 +241,7 @@ def create_ps_integration_object( """ yml_content = load_yaml("ps_integration.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() integration = pack.create_integration(yml=yml_content) integration.code = File( Path(f"{integration.path}/integration_0.ps1"), integration.repo_path @@ -272,7 +275,7 @@ def create_script_object( yml_content = load_yaml("script.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() if pack_info: pack.set_data(**pack_info) if readme_content is not None: @@ -309,7 +312,7 @@ def create_pack_object( json_content = load_json("pack_metadata.json") update_keys(json_content, paths, values) remove_fields_from_dict(json_content, fields_to_delete) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack_path = Path(pack.path) if release_note_content is not None: @@ -374,7 +377,7 @@ def create_classifier_object( """ json_content = load_json("classifier.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_classifier(name="test_classifier", content=json_content) return cast(Classifier, BaseContent.from_path(Path(pack.classifiers[0].path))) @@ -393,7 +396,7 @@ def create_list_object( """ json_content = load_json("list.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_list(name="list", content=json_content) return cast(ListObject, BaseContent.from_path(Path(pack.lists[0].path))) @@ -411,7 +414,7 @@ def create_job_object( The job object. """ json_content = {} - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_job(name="job", is_feed=True) if paths and values: with open(pack.jobs[0].path) as f: @@ -436,7 +439,7 @@ def create_dashboard_object( """ json_content = load_json("dashboard.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_dashboard(name="dashboard", content=json_content) return cast(Dashboard, BaseContent.from_path(Path(pack.dashboards[0].path))) @@ -455,7 +458,7 @@ def create_incident_type_object( """ json_content = load_json("incident_type.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_incident_type(name="incident_type", content=json_content) return cast(IncidentType, BaseContent.from_path(Path(pack.incident_types[0].path))) @@ -476,7 +479,7 @@ def create_incident_field_object( """ json_content = load_json("incident_field.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() if pack_info: pack.set_data(**pack_info) pack.create_incident_field(name="incident_field", content=json_content) @@ -499,7 +502,7 @@ def create_report_object( """ json_content = load_json("report.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_report(name="report", content=json_content) return cast(Report, BaseContent.from_path(Path(pack.reports[0].path))) @@ -518,7 +521,7 @@ def create_xsiam_report_object( """ json_content = load_json("xsiam_report.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_xsiam_report(name="xsiam_report", content=json_content) return cast(XSIAMReport, BaseContent.from_path(Path(pack.xsiam_reports[0].path))) @@ -537,7 +540,7 @@ def create_xsiam_dashboard_object( """ json_content = load_json("xsiam_dashboard.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_xsiam_dashboard(name="xsiam_dashboard", content=json_content) return cast( XSIAMDashboard, BaseContent.from_path(Path(pack.xsiam_dashboards[0].path)) @@ -565,7 +568,7 @@ def create_xdrc_template_object( update_keys(json_content, json_paths, json_values) yml_content = load_yaml("xdrc_template.yml") update_keys(json_content, yml_paths, yml_values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_xdrc_template( name="xdrc_template", json_content=json_content, yaml_content=yml_content ) @@ -593,7 +596,7 @@ def create_assets_modeling_rule_object( update_keys(json_content, json_paths, json_values) yml_content = load_yaml("assets_modeling_rule.yml") update_keys(json_content, yml_paths, yml_values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_assets_modeling_rule( name="assets_modeling_rule", schema=json_content, yml=yml_content ) @@ -617,7 +620,7 @@ def create_trigger_object( """ json_content = load_json("trigger.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_trigger(name="trigger", content=json_content) return cast(Trigger, BaseContent.from_path(Path(pack.triggers[0].path))) @@ -636,7 +639,7 @@ def create_layout_object( """ json_content = load_json("layoutscontainer.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_layout(name="layout", content=json_content) return cast(Layout, BaseContent.from_path(Path(pack.layouts[0].path))) @@ -655,7 +658,7 @@ def create_widget_object( """ json_content = load_json("widget.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_widget(name="widget", content=json_content) return cast(Widget, BaseContent.from_path(Path(pack.widgets[0].path))) @@ -674,7 +677,7 @@ def create_indicator_field_object( """ json_content = load_json("indicator_field.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_indicator_field(name="indicator_field", content=json_content) return cast( IndicatorField, BaseContent.from_path(Path(pack.indicator_fields[0].path)) @@ -690,7 +693,7 @@ def create_wizard_object(dict_to_update: Optional[Any] = None) -> Wizard: Returns: The wizard object. """ - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_wizard(name="test_wizard") if dict_to_update: pack.wizards[0].update(dict_to_update) @@ -711,7 +714,7 @@ def create_generic_definition_object( """ json_content = load_json("generic_definition.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_generic_definition(name="generic_definition", content=json_content) return cast( GenericDefinition, BaseContent.from_path(Path(pack.generic_definitions[0].path)) @@ -732,7 +735,7 @@ def create_generic_field_object( """ json_content = load_json("generic_field.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_generic_field(name="generic_field", content=json_content) return cast(GenericField, BaseContent.from_path(Path(pack.generic_fields[0].path))) @@ -751,7 +754,7 @@ def create_generic_type_object( """ json_content = load_json("generic_type.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_generic_type(name="generic_type", content=json_content) return cast(GenericType, BaseContent.from_path(Path(pack.generic_types[0].path))) @@ -770,7 +773,7 @@ def create_generic_module_object( """ json_content = load_json("generic_module.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_generic_module(name="generic_module", content=json_content) return cast( GenericModule, BaseContent.from_path(Path(pack.generic_modules[0].path)) @@ -791,7 +794,7 @@ def create_incoming_mapper_object( """ json_content = load_json("incoming_mapper.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_mapper(name="incoming_mapper", content=json_content) return cast(Mapper, BaseContent.from_path(Path(pack.mappers[0].path))) @@ -810,7 +813,7 @@ def create_outgoing_mapper_object( """ json_content = load_json("outgoing_mapper.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_mapper(name="outgoing_mapper", content=json_content) return BaseContent.from_path(Path(pack.mappers[0].path)) @@ -829,7 +832,7 @@ def create_indicator_type_object( """ json_content = load_json("indicator_type.json") update_keys(json_content, paths, values) - pack = REPO.create_pack() + pack = get_repo().create_pack() pack.create_indicator_type(name="indicator_type", content=json_content) return cast( IndicatorType, BaseContent.from_path(Path(pack.indicator_types[0].path)) From 5e75193a6d9adbf24142e2685bd046613be86818 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Mon, 18 Nov 2024 18:21:36 +0200 Subject: [PATCH 40/59] fix graph tests --- demisto_sdk/commands/validate/tests/test_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index 3e6f3c81449..0af1333f277 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -86,7 +86,7 @@ def create_integration_object( yml_content = load_yaml("integration.yml") update_keys(yml_content, paths, values) - pack = get_repo.create_pack() + pack = get_repo().create_pack() if pack_info: pack.set_data(**pack_info) From 81f13b79a5ecc3dddaa92ce1077729b2aec44cd9 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 19 Nov 2024 11:52:20 +0200 Subject: [PATCH 41/59] fix graph tests --- .../tests/parsers_and_models_test.py | 5 +- .../commands/validate/tests/test_tools.py | 193 +++++++++++++----- 2 files changed, 141 insertions(+), 57 deletions(-) diff --git a/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py b/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py index 3fd22bb3525..3ce263239d8 100644 --- a/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py +++ b/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py @@ -3057,11 +3057,14 @@ def test_support_attribute_in_integration_object( Then: - Ensure that the support attribute of the Integration object is set to the expected support level, e.g., the integration support level if it is not an empty string, or the pack support level otherwise. """ - with ChangeCWD(get_repo().path): + repo = get_repo() + repo_path = repo.path + with ChangeCWD(repo_path): test_integration = create_integration_object( paths=["supportlevelheader"], values=[integration_support], pack_info={"support": pack_support}, + repo=repo, ) assert test_integration.support == expected_support diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index 0af1333f277..1d914c118b9 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -73,12 +73,14 @@ def create_integration_object( name: Optional[str] = None, code: Optional[str] = None, unit_test_name: Optional[str] = None, + repo: Repo = get_repo(), ) -> Integration: """Creating an integration object with altered fields from a default integration yml structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The integration object. @@ -86,7 +88,7 @@ def create_integration_object( yml_content = load_yaml("integration.yml") update_keys(yml_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() if pack_info: pack.set_data(**pack_info) @@ -113,19 +115,21 @@ def create_integration_object( def create_parsing_rule_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> ParsingRule: - """Creating an parsing_rule object with altered fields from a default parsing_rule yml structure. + """Creating a parsing_rule object with altered fields from a default parsing_rule yml structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The parsing_rule object. """ yml_content = load_yaml("parsing_rule.yml") update_keys(yml_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() parsing_rule = pack.create_parsing_rule("TestParsingRule", yml_content) parser = ParsingRuleParser(Path(parsing_rule.path), list(MarketplaceVersions)) return ParsingRule.from_orm(parser) @@ -134,19 +138,21 @@ def create_parsing_rule_object( def create_correlation_rule_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> CorrelationRule: """Creating an correlation_rule object with altered fields from a default correlation_rule yml structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The correlation_rule object. """ yml_content = load_yaml("correlation_rule_test.yml") update_keys(yml_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_correlation_rule(name="correlation_rule", content=yml_content) return cast( CorrelationRule, BaseContent.from_path(Path(pack.correlation_rules[0].path)) @@ -158,6 +164,7 @@ def create_playbook_object( values: Optional[List[Any]] = None, pack_info: Optional[Dict[str, Any]] = None, readme_content: Optional[str] = None, + repo: Repo = get_repo(), ) -> Playbook: """Creating a playbook object with altered fields from a default playbook yml structure. @@ -166,12 +173,13 @@ def create_playbook_object( values (Optional[List[Any]]): The values to update. pack_info (Optional[List[str]]): The playbook's pack name. readme_content (Optional[List[Any]]): The playbook's readme. + repo: Containing repository object. New temporary repo is created by default. Returns: The playbook object. """ yml_content = load_yaml("playbook.yml") update_keys(yml_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() if pack_info: pack.set_data(**pack_info) additional_params = {} @@ -209,19 +217,20 @@ def create_modeling_rule_object( values: Optional[List[Any]] = None, rules: Optional[str] = None, schema: Optional[dict] = None, + repo: Repo = get_repo(), ) -> ModelingRule: """Creating an modeling_rule object with altered fields from a default modeling_rule yml structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. - + repo: Containing repository object. New temporary repo is created by default. Returns: The modeling_rule object. """ yml_content = load_yaml("modeling_rule.yml") update_keys(yml_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_modeling_rule(yml=yml_content, rules=rules, schema=schema) return cast(ModelingRule, BaseContent.from_path(Path(pack.modeling_rules[0].path))) @@ -229,19 +238,20 @@ def create_modeling_rule_object( def create_ps_integration_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Integration: """Creating an integration object with altered fields from a default integration yml structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. - + repo: Containing repository object. New temporary repo is created by default. Returns: The integration object. """ yml_content = load_yaml("ps_integration.yml") update_keys(yml_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() integration = pack.create_integration(yml=yml_content) integration.code = File( Path(f"{integration.path}/integration_0.ps1"), integration.repo_path @@ -258,13 +268,15 @@ def create_script_object( name: Optional[str] = None, code: Optional[str] = None, test_code: Optional[str] = None, + repo: Repo = get_repo(), ) -> Script: """Creating an script object with altered fields from a default script yml structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. - pack_name (str): The name of the pack that the script will be inside of + pack_name (str): The name of the pack that the script will be inside of. + repo: Containing repository object. New temporary repo is created by default. Returns: The script object. @@ -275,7 +287,7 @@ def create_script_object( yml_content = load_yaml("script.yml") update_keys(yml_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() if pack_info: pack.set_data(**pack_info) if readme_content is not None: @@ -299,12 +311,14 @@ def create_pack_object( name: Optional[str] = None, release_note_content: Optional[str] = None, bc_release_note_content: Optional[List[Dict[str, str]]] = None, + repo: Repo = get_repo(), ) -> Pack: """Creating an pack object with altered fields from a default pack_metadata json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The pack_metadata object. @@ -312,7 +326,7 @@ def create_pack_object( json_content = load_json("pack_metadata.json") update_keys(json_content, paths, values) remove_fields_from_dict(json_content, fields_to_delete) - pack = get_repo().create_pack() + pack = repo.create_pack() pack_path = Path(pack.path) if release_note_content is not None: @@ -356,7 +370,8 @@ def create_pack_object( def remove_fields_from_dict( - json_content: dict, fields_to_delete: Optional[List[str]] = None + json_content: dict, + fields_to_delete: Optional[List[str]] = None, ): if fields_to_delete: for field in fields_to_delete: @@ -364,57 +379,66 @@ def remove_fields_from_dict( def create_classifier_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Classifier: """Creating an classifier object with altered fields from a default classifier json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The classifier object. """ json_content = load_json("classifier.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_classifier(name="test_classifier", content=json_content) return cast(Classifier, BaseContent.from_path(Path(pack.classifiers[0].path))) def create_list_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> ListObject: """Creating an list object with altered fields from a default list json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The list object. """ json_content = load_json("list.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_list(name="list", content=json_content) return cast(ListObject, BaseContent.from_path(Path(pack.lists[0].path))) def create_job_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Job: """Creating an job object with altered fields from a default job json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The job object. """ json_content = {} - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_job(name="job", is_feed=True) if paths and values: with open(pack.jobs[0].path) as f: @@ -426,39 +450,45 @@ def create_job_object( def create_dashboard_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Dashboard: """Creating an dashboard object with altered fields from a default dashboard json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The dashboard object. """ json_content = load_json("dashboard.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_dashboard(name="dashboard", content=json_content) return cast(Dashboard, BaseContent.from_path(Path(pack.dashboards[0].path))) def create_incident_type_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> IncidentType: """Creating an incident_type object with altered fields from a default incident_type json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The incident_type object. """ json_content = load_json("incident_type.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_incident_type(name="incident_type", content=json_content) return cast(IncidentType, BaseContent.from_path(Path(pack.incident_types[0].path))) @@ -467,19 +497,21 @@ def create_incident_field_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, pack_info: Optional[Dict[str, Any]] = None, + repo: Repo = get_repo(), ) -> IncidentField: """Creating an incident_field object with altered fields from a default incident_field json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The incident_field object. """ json_content = load_json("incident_field.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() if pack_info: pack.set_data(**pack_info) pack.create_incident_field(name="incident_field", content=json_content) @@ -489,58 +521,67 @@ def create_incident_field_object( def create_report_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Report: """Creating an report object with altered fields from a default report json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The report object. """ json_content = load_json("report.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_report(name="report", content=json_content) return cast(Report, BaseContent.from_path(Path(pack.reports[0].path))) def create_xsiam_report_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> XSIAMReport: """Creating an xsiam_report object with altered fields from a default xsiam_report json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The xsiam_report object. """ json_content = load_json("xsiam_report.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_xsiam_report(name="xsiam_report", content=json_content) return cast(XSIAMReport, BaseContent.from_path(Path(pack.xsiam_reports[0].path))) def create_xsiam_dashboard_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> XSIAMDashboard: """Creating an xsiam_dashboard object with altered fields from a default xsiam_dashboard json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The xsiam_dashboard object. """ json_content = load_json("xsiam_dashboard.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_xsiam_dashboard(name="xsiam_dashboard", content=json_content) return cast( XSIAMDashboard, BaseContent.from_path(Path(pack.xsiam_dashboards[0].path)) @@ -552,6 +593,7 @@ def create_xdrc_template_object( json_values: Optional[List[Any]] = None, yml_paths: Optional[List[str]] = None, yml_values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> XDRCTemplate: """Creating an xdrc_template object with altered fields from a default xdrc_template json and yml structures. @@ -560,6 +602,7 @@ def create_xdrc_template_object( json_values (Optional[List[Any]]): The values to update for the json file. yml_paths (Optional[List[str]]): The keys to update for the yml file. yml_values (Optional[List[Any]]): The values to update for the yml file. + repo: Containing repository object. New temporary repo is created by default. Returns: The xdrc_template object. @@ -568,7 +611,7 @@ def create_xdrc_template_object( update_keys(json_content, json_paths, json_values) yml_content = load_yaml("xdrc_template.yml") update_keys(json_content, yml_paths, yml_values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_xdrc_template( name="xdrc_template", json_content=json_content, yaml_content=yml_content ) @@ -580,6 +623,7 @@ def create_assets_modeling_rule_object( json_values: Optional[List[Any]] = None, yml_paths: Optional[List[str]] = None, yml_values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> AssetsModelingRule: """Creating an assets_modeling_rule object with altered fields from a default assets_modeling_rule json and yml structures. @@ -588,6 +632,7 @@ def create_assets_modeling_rule_object( json_values (Optional[List[Any]]): The values to update for the json file. yml_paths (Optional[List[str]]): The keys to update for the yml file. yml_values (Optional[List[Any]]): The values to update for the yml file. + repo: Containing repository object. New temporary repo is created by default. Returns: The assets_modeling_rule object. @@ -596,7 +641,7 @@ def create_assets_modeling_rule_object( update_keys(json_content, json_paths, json_values) yml_content = load_yaml("assets_modeling_rule.yml") update_keys(json_content, yml_paths, yml_values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_assets_modeling_rule( name="assets_modeling_rule", schema=json_content, yml=yml_content ) @@ -607,93 +652,108 @@ def create_assets_modeling_rule_object( def create_trigger_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Trigger: """Creating an trigger object with altered fields from a default trigger json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The trigger object. """ json_content = load_json("trigger.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_trigger(name="trigger", content=json_content) return cast(Trigger, BaseContent.from_path(Path(pack.triggers[0].path))) def create_layout_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Layout: """Creating an layout object with altered fields from a default layout json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The layout object. """ json_content = load_json("layoutscontainer.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_layout(name="layout", content=json_content) return cast(Layout, BaseContent.from_path(Path(pack.layouts[0].path))) def create_widget_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Widget: """Creating an widget object with altered fields from a default widget json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The widget object. """ json_content = load_json("widget.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_widget(name="widget", content=json_content) return cast(Widget, BaseContent.from_path(Path(pack.widgets[0].path))) def create_indicator_field_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> IndicatorField: """Creating an indicator_field object with altered fields from a default indicator_field json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The indicator_field object. """ json_content = load_json("indicator_field.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_indicator_field(name="indicator_field", content=json_content) return cast( IndicatorField, BaseContent.from_path(Path(pack.indicator_fields[0].path)) ) -def create_wizard_object(dict_to_update: Optional[Any] = None) -> Wizard: +def create_wizard_object( + dict_to_update: Optional[Any] = None, repo: Repo = get_repo() +) -> Wizard: """Creating a wizard object with altered fields from a default wizard json structure. Args: dict_to_update (Optional[Any], optional): The dict to update into the wizards dict. + repo: Containing repository object. New temporary repo is created by default. Returns: The wizard object. """ - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_wizard(name="test_wizard") if dict_to_update: pack.wizards[0].update(dict_to_update) @@ -701,20 +761,23 @@ def create_wizard_object(dict_to_update: Optional[Any] = None) -> Wizard: def create_generic_definition_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> GenericDefinition: """Creating an generic_definition object with altered fields from a default generic_definition json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The generic_definition object. """ json_content = load_json("generic_definition.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_generic_definition(name="generic_definition", content=json_content) return cast( GenericDefinition, BaseContent.from_path(Path(pack.generic_definitions[0].path)) @@ -722,58 +785,67 @@ def create_generic_definition_object( def create_generic_field_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> GenericField: """Creating an generic_field object with altered fields from a default generic_field json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The generic_field object. """ json_content = load_json("generic_field.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_generic_field(name="generic_field", content=json_content) return cast(GenericField, BaseContent.from_path(Path(pack.generic_fields[0].path))) def create_generic_type_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> GenericType: """Creating an generic_type object with altered fields from a default generic_type json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The generic_type object. """ json_content = load_json("generic_type.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_generic_type(name="generic_type", content=json_content) return cast(GenericType, BaseContent.from_path(Path(pack.generic_types[0].path))) def create_generic_module_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> GenericModule: """Creating an generic_module object with altered fields from a default generic_module json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The generic_module object. """ json_content = load_json("generic_module.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_generic_module(name="generic_module", content=json_content) return cast( GenericModule, BaseContent.from_path(Path(pack.generic_modules[0].path)) @@ -781,58 +853,67 @@ def create_generic_module_object( def create_incoming_mapper_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> Mapper: """Creating an incoming_mapper object with altered fields from a default incoming_mapper json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The incoming_mapper object. """ json_content = load_json("incoming_mapper.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_mapper(name="incoming_mapper", content=json_content) return cast(Mapper, BaseContent.from_path(Path(pack.mappers[0].path))) def create_outgoing_mapper_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ): """Creating an outgoing_mapper object with altered fields from a default outgoing_mapper json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The outgoing_mapper object. """ json_content = load_json("outgoing_mapper.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_mapper(name="outgoing_mapper", content=json_content) return BaseContent.from_path(Path(pack.mappers[0].path)) def create_indicator_type_object( - paths: Optional[List[str]] = None, values: Optional[List[Any]] = None + paths: Optional[List[str]] = None, + values: Optional[List[Any]] = None, + repo: Repo = get_repo(), ) -> IndicatorType: """Creating an indicator_type object with altered fields from a default indicator_type json structure. Args: paths (Optional[List[str]]): The keys to update. values (Optional[List[Any]]): The values to update. + repo: Containing repository object. New temporary repo is created by default. Returns: The indicator_type object. """ json_content = load_json("indicator_type.json") update_keys(json_content, paths, values) - pack = get_repo().create_pack() + pack = repo.create_pack() pack.create_indicator_type(name="indicator_type", content=json_content) return cast( IndicatorType, BaseContent.from_path(Path(pack.indicator_types[0].path)) From e15309947fb77fb0f55d172198e5250df464389b Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 19 Nov 2024 12:11:03 +0200 Subject: [PATCH 42/59] fix graph tests --- .../tests/parsers_and_models_test.py | 10 +-- .../commands/validate/tests/test_tools.py | 66 +++++++++---------- .../unify_integration_test.py | 7 +- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py b/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py index 3ce263239d8..d370273fd02 100644 --- a/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py +++ b/demisto_sdk/commands/content_graph/tests/parsers_and_models_test.py @@ -31,7 +31,7 @@ create_classifier_object, create_integration_object, create_pack_object, - get_repo, + get_temp_repo, ) from TestSuite.pack import Pack from TestSuite.repo import Repo @@ -299,7 +299,9 @@ def test_classifier_parser_below_min_marketplace_version(self, git_repo): ) with ChangeCWD(git_repo.path): - classifier = create_classifier_object(paths=["toVersion"], values=["5.9.9"]) + classifier = create_classifier_object( + paths=["toVersion"], values=["5.9.9"], repo=git_repo + ) classifier_path = Path(classifier.path) with pytest.raises(NotAContentItemException): ClassifierParser(classifier_path, list(MarketplaceVersions)) @@ -3057,7 +3059,7 @@ def test_support_attribute_in_integration_object( Then: - Ensure that the support attribute of the Integration object is set to the expected support level, e.g., the integration support level if it is not an empty string, or the pack support level otherwise. """ - repo = get_repo() + repo = get_temp_repo() repo_path = repo.path with ChangeCWD(repo_path): test_integration = create_integration_object( @@ -3083,7 +3085,7 @@ def test_layout_parser_group(): """ from demisto_sdk.commands.content_graph.parsers.layout import LayoutParser - pack = get_repo().create_pack("TestPack") + pack = get_temp_repo().create_pack("TestPack") layout = pack.create_layoutcontainer( "TestLayoutscontainer", content={ diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index 90756a8ba3e..f3ba42e3b8f 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -59,7 +59,7 @@ from TestSuite.repo import Repo -def get_repo(): +def get_temp_repo(): content_temp_dir = Path(os.path.join(tempfile.mkdtemp(), "content")) content_temp_dir.mkdir() @@ -75,7 +75,7 @@ def create_integration_object( name: Optional[str] = None, code: Optional[str] = None, unit_test_name: Optional[str] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Integration: """Creating an integration object with altered fields from a default integration yml structure. @@ -117,7 +117,7 @@ def create_integration_object( def create_parsing_rule_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> ParsingRule: """Creating a parsing_rule object with altered fields from a default parsing_rule yml structure. @@ -140,7 +140,7 @@ def create_parsing_rule_object( def create_correlation_rule_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> CorrelationRule: """Creating an correlation_rule object with altered fields from a default correlation_rule yml structure. @@ -166,7 +166,7 @@ def create_playbook_object( values: Optional[List[Any]] = None, pack_info: Optional[Dict[str, Any]] = None, readme_content: Optional[str] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Playbook: """Creating a playbook object with altered fields from a default playbook yml structure. @@ -214,7 +214,7 @@ def create_test_playbook_object( """ yml_content = load_yaml("playbook.yml") update_keys(yml_content, paths, values) - pack = REPO.create_pack() + pack = get_temp_repo().create_pack() if pack_info: pack.set_data(**pack_info) additional_params = {} @@ -252,7 +252,7 @@ def create_modeling_rule_object( values: Optional[List[Any]] = None, rules: Optional[str] = None, schema: Optional[dict] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> ModelingRule: """Creating an modeling_rule object with altered fields from a default modeling_rule yml structure. @@ -273,7 +273,7 @@ def create_modeling_rule_object( def create_ps_integration_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Integration: """Creating an integration object with altered fields from a default integration yml structure. @@ -303,7 +303,7 @@ def create_script_object( name: Optional[str] = None, code: Optional[str] = None, test_code: Optional[str] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Script: """Creating an script object with altered fields from a default script yml structure. @@ -346,7 +346,7 @@ def create_pack_object( name: Optional[str] = None, release_note_content: Optional[str] = None, bc_release_note_content: Optional[List[Dict[str, str]]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Pack: """Creating an pack object with altered fields from a default pack_metadata json structure. @@ -416,7 +416,7 @@ def remove_fields_from_dict( def create_classifier_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Classifier: """Creating an classifier object with altered fields from a default classifier json structure. @@ -438,7 +438,7 @@ def create_classifier_object( def create_list_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> ListObject: """Creating an list object with altered fields from a default list json structure. @@ -460,7 +460,7 @@ def create_list_object( def create_job_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Job: """Creating an job object with altered fields from a default job json structure. @@ -487,7 +487,7 @@ def create_job_object( def create_dashboard_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Dashboard: """Creating an dashboard object with altered fields from a default dashboard json structure. @@ -509,7 +509,7 @@ def create_dashboard_object( def create_incident_type_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> IncidentType: """Creating an incident_type object with altered fields from a default incident_type json structure. @@ -532,7 +532,7 @@ def create_incident_field_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, pack_info: Optional[Dict[str, Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> IncidentField: """Creating an incident_field object with altered fields from a default incident_field json structure. @@ -558,7 +558,7 @@ def create_incident_field_object( def create_report_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Report: """Creating an report object with altered fields from a default report json structure. @@ -580,7 +580,7 @@ def create_report_object( def create_xsiam_report_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> XSIAMReport: """Creating an xsiam_report object with altered fields from a default xsiam_report json structure. @@ -602,7 +602,7 @@ def create_xsiam_report_object( def create_xsiam_dashboard_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> XSIAMDashboard: """Creating an xsiam_dashboard object with altered fields from a default xsiam_dashboard json structure. @@ -628,7 +628,7 @@ def create_xdrc_template_object( json_values: Optional[List[Any]] = None, yml_paths: Optional[List[str]] = None, yml_values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> XDRCTemplate: """Creating an xdrc_template object with altered fields from a default xdrc_template json and yml structures. @@ -658,7 +658,7 @@ def create_assets_modeling_rule_object( json_values: Optional[List[Any]] = None, yml_paths: Optional[List[str]] = None, yml_values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> AssetsModelingRule: """Creating an assets_modeling_rule object with altered fields from a default assets_modeling_rule json and yml structures. @@ -689,7 +689,7 @@ def create_assets_modeling_rule_object( def create_trigger_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Trigger: """Creating an trigger object with altered fields from a default trigger json structure. @@ -711,7 +711,7 @@ def create_trigger_object( def create_layout_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Layout: """Creating an layout object with altered fields from a default layout json structure. @@ -733,7 +733,7 @@ def create_layout_object( def create_widget_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Widget: """Creating an widget object with altered fields from a default widget json structure. @@ -755,7 +755,7 @@ def create_widget_object( def create_indicator_field_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> IndicatorField: """Creating an indicator_field object with altered fields from a default indicator_field json structure. @@ -777,7 +777,7 @@ def create_indicator_field_object( def create_wizard_object( - dict_to_update: Optional[Any] = None, repo: Repo = get_repo() + dict_to_update: Optional[Any] = None, repo: Repo = get_temp_repo() ) -> Wizard: """Creating a wizard object with altered fields from a default wizard json structure. @@ -798,7 +798,7 @@ def create_wizard_object( def create_generic_definition_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> GenericDefinition: """Creating an generic_definition object with altered fields from a default generic_definition json structure. @@ -822,7 +822,7 @@ def create_generic_definition_object( def create_generic_field_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> GenericField: """Creating an generic_field object with altered fields from a default generic_field json structure. @@ -844,7 +844,7 @@ def create_generic_field_object( def create_generic_type_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> GenericType: """Creating an generic_type object with altered fields from a default generic_type json structure. @@ -866,7 +866,7 @@ def create_generic_type_object( def create_generic_module_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> GenericModule: """Creating an generic_module object with altered fields from a default generic_module json structure. @@ -890,7 +890,7 @@ def create_generic_module_object( def create_incoming_mapper_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> Mapper: """Creating an incoming_mapper object with altered fields from a default incoming_mapper json structure. @@ -912,7 +912,7 @@ def create_incoming_mapper_object( def create_outgoing_mapper_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ): """Creating an outgoing_mapper object with altered fields from a default outgoing_mapper json structure. @@ -934,7 +934,7 @@ def create_outgoing_mapper_object( def create_indicator_type_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_repo(), + repo: Repo = get_temp_repo(), ) -> IndicatorType: """Creating an indicator_type object with altered fields from a default indicator_type json structure. diff --git a/demisto_sdk/tests/integration_tests/unify_integration_test.py b/demisto_sdk/tests/integration_tests/unify_integration_test.py index de14bc0a6d0..145aa507e9d 100644 --- a/demisto_sdk/tests/integration_tests/unify_integration_test.py +++ b/demisto_sdk/tests/integration_tests/unify_integration_test.py @@ -10,7 +10,7 @@ from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.handlers import DEFAULT_YAML_HANDLER as yaml from demisto_sdk.commands.common.legacy_git_tools import git_path -from demisto_sdk.commands.validate.tests.test_tools import REPO +from demisto_sdk.commands.validate.tests.test_tools import get_temp_repo from demisto_sdk.tests.test_files.validate_integration_test_valid_types import ( DASHBOARD, GENERIC_MODULE, @@ -326,7 +326,8 @@ def test_layout_unify(self, mocker, monkeypatch): - make sure the 'fromServerVersion' and 'fromVersion' are the same. - make sure the 'toVersion' and 'toServerVersion' are the same. """ - pack = REPO.create_pack("test") + repo = get_temp_repo() + pack = repo.create_pack("test") layout = pack.create_layoutcontainer( name="test", content=json.load( @@ -338,7 +339,7 @@ def test_layout_unify(self, mocker, monkeypatch): output = "test.json" - with ChangeCWD(REPO.path): + with ChangeCWD(repo.path): runner = CliRunner(mix_stderr=False) result = runner.invoke( main, [UNIFY_CMD, "-i", f"{layout.path}", "-o", output] From fa41bd29c16bd906750d304c0b3a7837c35d398c Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 19 Nov 2024 14:39:16 +0200 Subject: [PATCH 43/59] fix integration tests --- .../integration_tests/modeling_rules_integration_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demisto_sdk/tests/integration_tests/modeling_rules_integration_test.py b/demisto_sdk/tests/integration_tests/modeling_rules_integration_test.py index bbcf721bbf3..8727e915764 100644 --- a/demisto_sdk/tests/integration_tests/modeling_rules_integration_test.py +++ b/demisto_sdk/tests/integration_tests/modeling_rules_integration_test.py @@ -992,13 +992,15 @@ def test_the_test_modeling_rule_command_results_with_ignored_validations( "0", ], ) + schema_path = Path(pack.modeling_rules[0].schema.path).relative_to( + pack.repo_path + ) # Assert assert result.exit_code == 0 assert "All mappings validated successfully" in result.output # make sure the schema validation was skipped. - schema_path = pack.modeling_rules[0].schema.path assert ( - f"Skipping the validation to check that the schema {schema_path} is aligned with TestData file" + f"Skipping the validation to check that the schema {str(schema_path)} is aligned with TestData file" in result.output ) except typer.Exit: From d95d5a0facd9c1678958b79309fa75b69faf6bc4 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Tue, 19 Nov 2024 15:31:52 +0200 Subject: [PATCH 44/59] fix unit tests --- .../validate/tests/BA_validators_test.py | 27 +++-- .../validate/tests/BC_validators_test.py | 105 +++++++++++++----- .../validate/tests/IF_validators_test.py | 21 ++-- .../validate/tests/IN_validators_test.py | 56 +++++++--- .../validate/tests/PA_validators_test.py | 14 ++- .../validate/tests/RM_validators_test.py | 5 +- .../validate/tests/SC_validators_test.py | 9 +- .../commands/validate/tests/test_tools.py | 62 +++++------ 8 files changed, 203 insertions(+), 96 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/BA_validators_test.py b/demisto_sdk/commands/validate/tests/BA_validators_test.py index e3d0244c035..173a612989a 100644 --- a/demisto_sdk/commands/validate/tests/BA_validators_test.py +++ b/demisto_sdk/commands/validate/tests/BA_validators_test.py @@ -10,7 +10,6 @@ XSOAR_SUPPORT, ) from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_assets_modeling_rule_object, create_classifier_object, create_correlation_rule_object, @@ -43,6 +42,7 @@ create_xdrc_template_object, create_xsiam_dashboard_object, create_xsiam_report_object, + get_temp_repo, ) from demisto_sdk.commands.validate.validators.BA_validators.BA100_is_valid_version import ( IsValidVersionValidator, @@ -2096,17 +2096,20 @@ def test_IsHaveUnitTestFileValidator_obtain_invalid_content_items__all_valid(): Then - Make sure no failures are returned. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( name="MyIntegration0", unit_test_name="MyIntegration0", pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), create_integration_object( name="MyIntegration0", unit_test_name="MyIntegration0", pack_info={"support": PARTNER_SUPPORT}, + repo=repo, ), ] @@ -2127,12 +2130,14 @@ def test_IsHaveUnitTestFileValidator_obtain_invalid_content_items__invalid_item( Then - Make sure one failure is returned and the error message is correct. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( name="MyIntegration0", unit_test_name="myintegration0", pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] @@ -2163,7 +2168,8 @@ def test_is_valid_context_path_depth_command(): Then - Make sure one failure is returned and the error message is correct. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( paths=["script.commands"], @@ -2190,6 +2196,7 @@ def test_is_valid_context_path_depth_command(): ] ], pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] expected_msg = "The level of depth for context output path for command: ip In the yml should be less or equal to 5 check the following outputs:\npath_1.2.3.4.5.6\n" @@ -2212,7 +2219,8 @@ def test_is_valid_context_path_depth_script(): Then - Make sure one failure is returned and the error message is correct. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_script_object( paths=["outputs"], @@ -2226,6 +2234,7 @@ def test_is_valid_context_path_depth_script(): ] ], pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] expected_msg = "The level of depth for context output path for script: myScript In the yml should be less or equal to 5 check the following outputs:\ntest.test.1.2.3.4.5.6" @@ -2248,7 +2257,8 @@ def test_is_valid_context_path_depth_command_multiple_invalid_outputs(): Then - Make sure the paths exist in the error message that is returned """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( paths=["script.commands"], @@ -2280,6 +2290,7 @@ def test_is_valid_context_path_depth_command_multiple_invalid_outputs(): ] ], pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] @@ -2305,7 +2316,8 @@ def test_is_valid_context_path_depth_command_multiple_commands_with_invalid_outp Then - Make sure the paths exist in the error message that is returned """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( paths=["script.commands"], @@ -2360,6 +2372,7 @@ def test_is_valid_context_path_depth_command_multiple_commands_with_invalid_outp ] ], pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] invalid_path_ip_1 = "path_1.2.3.4.5.6" diff --git a/demisto_sdk/commands/validate/tests/BC_validators_test.py b/demisto_sdk/commands/validate/tests/BC_validators_test.py index 9b219a44732..3345afd5f71 100644 --- a/demisto_sdk/commands/validate/tests/BC_validators_test.py +++ b/demisto_sdk/commands/validate/tests/BC_validators_test.py @@ -9,7 +9,6 @@ from demisto_sdk.commands.content_graph.objects.mapper import Mapper from demisto_sdk.commands.content_graph.objects.script import Script from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_incident_field_object, create_incident_type_object, create_incoming_mapper_object, @@ -17,6 +16,7 @@ create_old_file_pointers, create_pack_object, create_script_object, + get_temp_repo, ) from demisto_sdk.commands.validate.validators.BC_validators.BC100_breaking_backwards_subtype import ( BreakingBackwardsSubtypeValidator, @@ -385,10 +385,15 @@ def test_WasMarketplaceModifiedValidator__modified_item_has_only_one_marketplace - Case 2: Should pass the validation since the user did not remove any marketplace. - Case 3: Should pass the validation since the user did not remove any marketplace. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): modified_content_items = [ - create_integration_object(pack_info={"marketplaces": in_pack_marketplaces}), - create_script_object(pack_info={"marketplaces": in_pack_marketplaces}), + create_integration_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + create_script_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), ] old_content_items = [create_integration_object(), create_script_object()] @@ -433,12 +438,20 @@ def test_WasMarketplaceModifiedValidator__modified_item_has_only_one_marketplace - Case 1: Should fail the validation since the user removed marketplaces. - Case 2: Should fail the validation since the user replaced one marketplace with a different one. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): modified_content_items = [ - create_integration_object(pack_info={"marketplaces": in_pack_marketplaces}), - create_script_object(pack_info={"marketplaces": in_pack_marketplaces}), + create_integration_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + create_script_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + ] + old_content_items = [ + create_integration_object(repo=repo), + create_script_object(repo=repo), ] - old_content_items = [create_integration_object(), create_script_object()] modified_content_items[0].marketplaces = modified_content_items[ 1 @@ -483,12 +496,20 @@ def test_WasMarketplaceModifiedValidator__old_item_has_only_one_marketplace__pas - Case 1: Should pass the validation since the user added marketplaces or removed all marketplaces which is equal to adding all marketplaces. - Case 2: Should pass the validation since the user added marketplaces or removed all marketplaces which is equal to adding all marketplaces. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): modified_content_items = [ - create_integration_object(pack_info={"marketplaces": in_pack_marketplaces}), - create_script_object(pack_info={"marketplaces": in_pack_marketplaces}), + create_integration_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + create_script_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + ] + old_content_items = [ + create_integration_object(repo=repo), + create_script_object(repo=repo), ] - old_content_items = [create_integration_object(), create_script_object()] modified_content_items[0].marketplaces = modified_content_items[ 1 @@ -521,15 +542,23 @@ def test_WasMarketplaceModifiedValidator__old_item_has_only_one_marketplace__fai - Should fail the validation since the user replaced one marketplace with a different one. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): modified_marketplaces = XSOAR_MARKETPLACE in_pack_marketplaces = ALL_MARKETPLACES_FOR_IN_PACK modified_content_items = [ - create_integration_object(pack_info={"marketplaces": in_pack_marketplaces}), - create_script_object(pack_info={"marketplaces": in_pack_marketplaces}), + create_integration_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + create_script_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + ] + old_content_items = [ + create_integration_object(repo=repo), + create_script_object(repo=repo), ] - old_content_items = [create_integration_object(), create_script_object()] modified_content_items[0].marketplaces = modified_content_items[ 1 @@ -575,12 +604,20 @@ def test_WasMarketplaceModifiedValidator__old_and_modified_items_have_all_market - Case 1: Should pass the validation since the user added marketplaces or removed all marketplaces which is equal to adding all marketplaces. - Case 2: Should pass the validation since the user didn't change anything or removed all marketplaces which is equal to adding all marketplaces. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): modified_content_items = [ - create_integration_object(pack_info={"marketplaces": in_pack_marketplaces}), - create_script_object(pack_info={"marketplaces": in_pack_marketplaces}), + create_integration_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + create_script_object( + pack_info={"marketplaces": in_pack_marketplaces}, repo=repo + ), + ] + old_content_items = [ + create_integration_object(repo=repo), + create_script_object(repo=repo), ] - old_content_items = [create_integration_object(), create_script_object()] create_old_file_pointers(modified_content_items, old_content_items) @@ -684,15 +721,23 @@ def test_WasMarketplaceModifiedValidator__renamed__fails(): - Should fail the validation since moving to a different pack with less marketplaces is not allowed. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): renamed_content_items = [ - create_integration_object(pack_info={"marketplaces": XSOAR_MARKETPLACE}), - create_script_object(pack_info={"marketplaces": XSOAR_MARKETPLACE}), + create_integration_object( + pack_info={"marketplaces": XSOAR_MARKETPLACE}, repo=repo + ), + create_script_object( + pack_info={"marketplaces": XSOAR_MARKETPLACE}, repo=repo + ), ] renamed_content_items[0].git_status = renamed_content_items[1].git_status = ( GitStatuses.RENAMED ) - old_content_items = [create_integration_object(), create_script_object()] + old_content_items = [ + create_integration_object(repo=repo), + create_script_object(repo=repo), + ] old_content_items[0].marketplaces = old_content_items[1].marketplaces = ( ALL_MARKETPLACES_FOR_IN_PACK @@ -724,19 +769,23 @@ def test_WasMarketplaceModifiedValidator__renamed__passes(): - Should pass the validation since the new host has all marketplaces in pack level. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): renamed_content_items = [ create_integration_object( - pack_info={"marketplaces": ALL_MARKETPLACES_FOR_IN_PACK} + pack_info={"marketplaces": ALL_MARKETPLACES_FOR_IN_PACK}, repo=repo ), create_script_object( - pack_info={"marketplaces": ALL_MARKETPLACES_FOR_IN_PACK} + pack_info={"marketplaces": ALL_MARKETPLACES_FOR_IN_PACK}, repo=repo ), ] renamed_content_items[0].git_status = renamed_content_items[1].git_status = ( GitStatuses.RENAMED ) - old_content_items = [create_integration_object(), create_script_object()] + old_content_items = [ + create_integration_object(repo=repo), + create_script_object(repo=repo), + ] old_content_items[0].marketplaces = old_content_items[1].marketplaces = ( XSOAR_MARKETPLACE diff --git a/demisto_sdk/commands/validate/tests/IF_validators_test.py b/demisto_sdk/commands/validate/tests/IF_validators_test.py index 55e346dab7b..b167a900b43 100644 --- a/demisto_sdk/commands/validate/tests/IF_validators_test.py +++ b/demisto_sdk/commands/validate/tests/IF_validators_test.py @@ -4,9 +4,9 @@ from demisto_sdk.commands.content_graph.objects.incident_field import IncidentField from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_incident_field_object, create_old_file_pointers, + get_temp_repo, ) from demisto_sdk.commands.validate.validators.IF_validators.IF100_is_valid_name_and_cli_name import ( IsValidNameAndCliNameValidator, @@ -281,9 +281,12 @@ def test_NameFieldPrefixValidator_obtain_invalid_content_items_without_item_pref """ # not valid pack_name = "Foo" - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): # Create an Incident field so that there is no prefix name of the pack in the name field - content_item = create_incident_field_object(pack_info={"name": pack_name}) + content_item = create_incident_field_object( + pack_info={"name": pack_name}, repo=repo + ) assert not content_item.name.startswith(pack_name) results = NameFieldPrefixValidator().obtain_invalid_content_items( [content_item] @@ -334,10 +337,11 @@ def test_NameFieldPrefixValidator_obtain_invalid_content_items_with_item_prefix( - Ensure that no ValidationResult returned when prefix name is in itemPrefix which is in pack_metadata """ + repo = get_temp_repo() # not valid - with ChangeCWD(REPO.path): + with ChangeCWD(repo.path): content_item = create_incident_field_object( - pack_info={"name": "Foo", "itemPrefix": item_prefix} + pack_info={"name": "Foo", "itemPrefix": item_prefix}, repo=repo ) results = NameFieldPrefixValidator().obtain_invalid_content_items( [content_item] @@ -364,8 +368,11 @@ def test_NameFieldPrefixValidator_obtain_invalid_content_items_with_special_pack Then: - Ensure that no ValidationResult returned """ - with ChangeCWD(REPO.path): - content_item = create_incident_field_object(pack_info={"name": special_pack}) + repo = get_temp_repo() + with ChangeCWD(repo.path): + content_item = create_incident_field_object( + pack_info={"name": special_pack}, repo=repo + ) assert not NameFieldPrefixValidator().obtain_invalid_content_items( [content_item] ) diff --git a/demisto_sdk/commands/validate/tests/IN_validators_test.py b/demisto_sdk/commands/validate/tests/IN_validators_test.py index 4ff896d7302..33e51899154 100644 --- a/demisto_sdk/commands/validate/tests/IN_validators_test.py +++ b/demisto_sdk/commands/validate/tests/IN_validators_test.py @@ -23,10 +23,10 @@ ) from demisto_sdk.commands.content_graph.objects.integration import Integration from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_integration_object, create_old_file_pointers, create_script_object, + get_temp_repo, ) from demisto_sdk.commands.validate.validators.IN_validators.IN100_is_valid_proxy_and_insecure import ( IsValidProxyAndInsecureValidator, @@ -4951,12 +4951,19 @@ def test_IsContainingFromLicenseInParamsValidator_obtain_invalid_content_items__ Then - Make sure the validation pass for all. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ - create_integration_object(pack_info={"support": XSOAR_SUPPORT}), - create_integration_object(pack_info={"support": PARTNER_SUPPORT}), - create_integration_object(pack_info={"support": DEVELOPER_SUPPORT}), - create_integration_object(pack_info={"support": COMMUNITY_SUPPORT}), + create_integration_object(pack_info={"support": XSOAR_SUPPORT}, repo=repo), + create_integration_object( + pack_info={"support": PARTNER_SUPPORT}, repo=repo + ), + create_integration_object( + pack_info={"support": DEVELOPER_SUPPORT}, repo=repo + ), + create_integration_object( + pack_info={"support": COMMUNITY_SUPPORT}, repo=repo + ), create_integration_object( paths=["configuration"], values=[ @@ -4971,6 +4978,7 @@ def test_IsContainingFromLicenseInParamsValidator_obtain_invalid_content_items__ ] ], pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] @@ -4995,7 +5003,8 @@ def test_IsContainingFromLicenseInParamsValidator_obtain_invalid_content_items__ Then - Make sure the validation fail and the right error message is returned. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( paths=["configuration"], @@ -5011,6 +5020,7 @@ def test_IsContainingFromLicenseInParamsValidator_obtain_invalid_content_items__ ] ], pack_info={"support": PARTNER_SUPPORT}, + repo=repo, ), create_integration_object( paths=["configuration"], @@ -5026,6 +5036,7 @@ def test_IsContainingFromLicenseInParamsValidator_obtain_invalid_content_items__ ] ], pack_info={"support": DEVELOPER_SUPPORT}, + repo=repo, ), create_integration_object( paths=["configuration"], @@ -5041,6 +5052,7 @@ def test_IsContainingFromLicenseInParamsValidator_obtain_invalid_content_items__ ] ], pack_info={"support": COMMUNITY_SUPPORT}, + repo=repo, ), ] @@ -5118,7 +5130,8 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_v Then - Make sure the validation pass for all. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( paths=["configuration"], @@ -5141,6 +5154,7 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_v ] ], pack_info={"support": PARTNER_SUPPORT}, + repo=repo, ), create_integration_object( paths=["configuration"], @@ -5163,6 +5177,7 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_v ] ], pack_info={"support": DEVELOPER_SUPPORT}, + repo=repo, ), create_integration_object( paths=["configuration"], @@ -5185,6 +5200,7 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_v ] ], pack_info={"support": COMMUNITY_SUPPORT}, + repo=repo, ), create_integration_object( paths=["configuration"], @@ -5206,6 +5222,7 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_v ] ], pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] @@ -5225,7 +5242,8 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_i Then - Make sure the validation fail and the right error message is returned. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( paths=["configuration"], @@ -5241,6 +5259,7 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_i ] ], pack_info={"support": XSOAR_SUPPORT}, + repo=repo, ), ] @@ -5397,7 +5416,8 @@ def test_IsNameContainIncidentInCorePackValidator_obtain_invalid_content_items( "demisto_sdk.commands.validate.validators.IN_validators.IN139_is_name_contain_incident_in_core_pack.get_core_pack_list", return_value=["pack_no_1", "pack_no_2", "pack_no_4"], ) - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): results = ( IsNameContainIncidentInCorePackValidator().obtain_invalid_content_items( content_items @@ -5426,29 +5446,36 @@ def test_IsPartnerCollectorHasXsoarSupportLevelValidator_obtain_invalid_content_ Then - Make sure the validation pass for all. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( pack_info={"support": XSOAR_SUPPORT}, paths=["script.isfetchevents"], values=[True], + repo=repo, ), create_integration_object( pack_info={"support": PARTNER_SUPPORT}, paths=["supportlevelheader", "script.isfetchevents"], values=[XSOAR_SUPPORT, True], + repo=repo, ), create_integration_object( pack_info={"support": XSOAR_SUPPORT}, paths=["script.isfetcheventsandassets"], values=[True], + repo=repo, ), create_integration_object( pack_info={"support": PARTNER_SUPPORT}, paths=["supportlevelheader", "script.isfetcheventsandassets"], values=[XSOAR_SUPPORT, True], + repo=repo, + ), + create_integration_object( + pack_info={"support": PARTNER_SUPPORT}, repo=repo ), - create_integration_object(pack_info={"support": PARTNER_SUPPORT}), ] results = IsPartnerCollectorHasXsoarSupportLevelValidator().obtain_invalid_content_items( @@ -5469,17 +5496,20 @@ def test_IsPartnerCollectorHasXsoarSupportLevelValidator_obtain_invalid_content_ Then - Make sure the validation fail and the right error message is returned. """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): content_items = [ create_integration_object( pack_info={"support": PARTNER_SUPPORT}, paths=["script.isfetchevents"], values=[True], + repo=repo, ), create_integration_object( pack_info={"support": PARTNER_SUPPORT}, paths=["script.isfetcheventsandassets"], values=[True], + repo=repo, ), ] diff --git a/demisto_sdk/commands/validate/tests/PA_validators_test.py b/demisto_sdk/commands/validate/tests/PA_validators_test.py index 75c191bb86c..718da0540e4 100644 --- a/demisto_sdk/commands/validate/tests/PA_validators_test.py +++ b/demisto_sdk/commands/validate/tests/PA_validators_test.py @@ -21,13 +21,13 @@ from demisto_sdk.commands.content_graph.objects.base_content import BaseNode from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFile from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_integration_object, create_modeling_rule_object, create_old_file_pointers, create_pack_object, create_playbook_object, create_script_object, + get_temp_repo, ) from demisto_sdk.commands.validate.validators.base_validator import BaseValidator from demisto_sdk.commands.validate.validators.PA_validators.PA100_valid_tags_prefixes import ( @@ -1702,9 +1702,10 @@ def test_PackMetadataVersionShouldBeRaisedValidator( "`demisto-sdk update-release-notes -i Packs/{pack} -u " "(major|minor|revision|documentation)` for a specific pack and version." ) - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): integration = create_integration_object( - pack_info={"currentVersion": current_version} + pack_info={"currentVersion": current_version}, repo=repo ) pack = integration.in_pack integration.git_status = GitStatuses.MODIFIED @@ -1744,8 +1745,11 @@ def test_PackMetadataVersionShouldBeRaisedValidator_metadata_change(mocker): ) old_version = "1.0.0" current_version = "1.0.0" - with ChangeCWD(REPO.path): - pack = create_pack_object(["currentVersion", "price"], [current_version, 5]) + repo = get_temp_repo() + with ChangeCWD(repo.path): + pack = create_pack_object( + ["currentVersion", "price"], [current_version, 5], repo=repo + ) old_pack = pack.copy(deep=True) old_pack.current_version = old_version diff --git a/demisto_sdk/commands/validate/tests/RM_validators_test.py b/demisto_sdk/commands/validate/tests/RM_validators_test.py index e5e7a8a3d0e..0e9965c6481 100644 --- a/demisto_sdk/commands/validate/tests/RM_validators_test.py +++ b/demisto_sdk/commands/validate/tests/RM_validators_test.py @@ -5,12 +5,12 @@ from demisto_sdk.commands.common.tools import find_pack_folder from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_doc_file_object, create_integration_object, create_pack_object, create_playbook_object, create_script_object, + get_temp_repo, ) from demisto_sdk.commands.validate.validators.base_validator import ValidationResult from demisto_sdk.commands.validate.validators.RM_validators.RM100_no_empty_sections import ( @@ -329,7 +329,8 @@ def test_IsImageExistsInReadmeValidator_obtain_invalid_content_items( expected_number_of_failures, expected_msgs, ): - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): for content_item, file_name in zip(content_items, doc_files_name): if file_name: create_doc_file_object(find_pack_folder(content_item.path), file_name) diff --git a/demisto_sdk/commands/validate/tests/SC_validators_test.py b/demisto_sdk/commands/validate/tests/SC_validators_test.py index 4410537797d..8598ab979e7 100644 --- a/demisto_sdk/commands/validate/tests/SC_validators_test.py +++ b/demisto_sdk/commands/validate/tests/SC_validators_test.py @@ -3,8 +3,8 @@ MarketplaceVersions, ) from demisto_sdk.commands.validate.tests.test_tools import ( - REPO, create_script_object, + get_temp_repo, ) from demisto_sdk.commands.validate.validators.base_validator import BaseValidator from demisto_sdk.commands.validate.validators.SC_validators import ( @@ -80,7 +80,8 @@ def test_IsScriptArgumentsContainIncidentWordValidatorCorePacks_obtain_invalid_c Then: - make sure the script with the argument that has "incident" fails the validation """ - with ChangeCWD(REPO.path): + repo = get_temp_repo() + with ChangeCWD(repo.path): mocker.patch( "demisto_sdk.commands.validate.validators.SC_validators.SC105_incident_not_in_args_validator_core_packs.get_core_pack_list", return_value=["PackWithInvalidScript"], @@ -94,6 +95,7 @@ def test_IsScriptArgumentsContainIncidentWordValidatorCorePacks_obtain_invalid_c [{"name": "incident-id", "description": "test"}], ], pack_info={"name": "PackWithInvalidScript"}, + repo=repo, ), create_script_object( paths=["args"], @@ -107,8 +109,9 @@ def test_IsScriptArgumentsContainIncidentWordValidatorCorePacks_obtain_invalid_c ], ], pack_info={"name": "PackWithValidScript"}, + repo=repo, ), - create_script_object(), + create_script_object(repo=repo), ) results = IsScriptArgumentsContainIncidentWordValidatorCorePacks().obtain_invalid_content_items( diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index f3ba42e3b8f..5da7ad0f3f6 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -59,7 +59,7 @@ from TestSuite.repo import Repo -def get_temp_repo(): +def get_temp_repo() -> Repo: content_temp_dir = Path(os.path.join(tempfile.mkdtemp(), "content")) content_temp_dir.mkdir() @@ -75,7 +75,7 @@ def create_integration_object( name: Optional[str] = None, code: Optional[str] = None, unit_test_name: Optional[str] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Integration: """Creating an integration object with altered fields from a default integration yml structure. @@ -117,7 +117,7 @@ def create_integration_object( def create_parsing_rule_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> ParsingRule: """Creating a parsing_rule object with altered fields from a default parsing_rule yml structure. @@ -140,7 +140,7 @@ def create_parsing_rule_object( def create_correlation_rule_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> CorrelationRule: """Creating an correlation_rule object with altered fields from a default correlation_rule yml structure. @@ -166,7 +166,7 @@ def create_playbook_object( values: Optional[List[Any]] = None, pack_info: Optional[Dict[str, Any]] = None, readme_content: Optional[str] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Playbook: """Creating a playbook object with altered fields from a default playbook yml structure. @@ -252,7 +252,7 @@ def create_modeling_rule_object( values: Optional[List[Any]] = None, rules: Optional[str] = None, schema: Optional[dict] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> ModelingRule: """Creating an modeling_rule object with altered fields from a default modeling_rule yml structure. @@ -273,7 +273,7 @@ def create_modeling_rule_object( def create_ps_integration_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Integration: """Creating an integration object with altered fields from a default integration yml structure. @@ -303,7 +303,7 @@ def create_script_object( name: Optional[str] = None, code: Optional[str] = None, test_code: Optional[str] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Script: """Creating an script object with altered fields from a default script yml structure. @@ -346,7 +346,7 @@ def create_pack_object( name: Optional[str] = None, release_note_content: Optional[str] = None, bc_release_note_content: Optional[List[Dict[str, str]]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Pack: """Creating an pack object with altered fields from a default pack_metadata json structure. @@ -416,7 +416,7 @@ def remove_fields_from_dict( def create_classifier_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Classifier: """Creating an classifier object with altered fields from a default classifier json structure. @@ -438,7 +438,7 @@ def create_classifier_object( def create_list_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> ListObject: """Creating an list object with altered fields from a default list json structure. @@ -460,7 +460,7 @@ def create_list_object( def create_job_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Job: """Creating an job object with altered fields from a default job json structure. @@ -487,7 +487,7 @@ def create_job_object( def create_dashboard_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Dashboard: """Creating an dashboard object with altered fields from a default dashboard json structure. @@ -509,7 +509,7 @@ def create_dashboard_object( def create_incident_type_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> IncidentType: """Creating an incident_type object with altered fields from a default incident_type json structure. @@ -532,7 +532,7 @@ def create_incident_field_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, pack_info: Optional[Dict[str, Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> IncidentField: """Creating an incident_field object with altered fields from a default incident_field json structure. @@ -558,7 +558,7 @@ def create_incident_field_object( def create_report_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Report: """Creating an report object with altered fields from a default report json structure. @@ -580,7 +580,7 @@ def create_report_object( def create_xsiam_report_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> XSIAMReport: """Creating an xsiam_report object with altered fields from a default xsiam_report json structure. @@ -602,7 +602,7 @@ def create_xsiam_report_object( def create_xsiam_dashboard_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> XSIAMDashboard: """Creating an xsiam_dashboard object with altered fields from a default xsiam_dashboard json structure. @@ -628,7 +628,7 @@ def create_xdrc_template_object( json_values: Optional[List[Any]] = None, yml_paths: Optional[List[str]] = None, yml_values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> XDRCTemplate: """Creating an xdrc_template object with altered fields from a default xdrc_template json and yml structures. @@ -658,7 +658,7 @@ def create_assets_modeling_rule_object( json_values: Optional[List[Any]] = None, yml_paths: Optional[List[str]] = None, yml_values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> AssetsModelingRule: """Creating an assets_modeling_rule object with altered fields from a default assets_modeling_rule json and yml structures. @@ -689,7 +689,7 @@ def create_assets_modeling_rule_object( def create_trigger_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Trigger: """Creating an trigger object with altered fields from a default trigger json structure. @@ -711,7 +711,7 @@ def create_trigger_object( def create_layout_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Layout: """Creating an layout object with altered fields from a default layout json structure. @@ -733,7 +733,7 @@ def create_layout_object( def create_widget_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Widget: """Creating an widget object with altered fields from a default widget json structure. @@ -755,7 +755,7 @@ def create_widget_object( def create_indicator_field_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> IndicatorField: """Creating an indicator_field object with altered fields from a default indicator_field json structure. @@ -798,7 +798,7 @@ def create_wizard_object( def create_generic_definition_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> GenericDefinition: """Creating an generic_definition object with altered fields from a default generic_definition json structure. @@ -822,7 +822,7 @@ def create_generic_definition_object( def create_generic_field_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> GenericField: """Creating an generic_field object with altered fields from a default generic_field json structure. @@ -844,7 +844,7 @@ def create_generic_field_object( def create_generic_type_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> GenericType: """Creating an generic_type object with altered fields from a default generic_type json structure. @@ -866,7 +866,7 @@ def create_generic_type_object( def create_generic_module_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> GenericModule: """Creating an generic_module object with altered fields from a default generic_module json structure. @@ -890,7 +890,7 @@ def create_generic_module_object( def create_incoming_mapper_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> Mapper: """Creating an incoming_mapper object with altered fields from a default incoming_mapper json structure. @@ -912,7 +912,7 @@ def create_incoming_mapper_object( def create_outgoing_mapper_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ): """Creating an outgoing_mapper object with altered fields from a default outgoing_mapper json structure. @@ -934,7 +934,7 @@ def create_outgoing_mapper_object( def create_indicator_type_object( paths: Optional[List[str]] = None, values: Optional[List[Any]] = None, - repo: Repo = get_temp_repo(), + repo=get_temp_repo(), ) -> IndicatorType: """Creating an indicator_type object with altered fields from a default indicator_type json structure. From ddede7737c896fd5a7c4c44c9dc2cbf14ec5d368 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 21 Nov 2024 10:54:08 +0200 Subject: [PATCH 45/59] fix BA validator test --- .../validate/tests/BA_validators_test.py | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/BA_validators_test.py b/demisto_sdk/commands/validate/tests/BA_validators_test.py index 173a612989a..85a5772eb0e 100644 --- a/demisto_sdk/commands/validate/tests/BA_validators_test.py +++ b/demisto_sdk/commands/validate/tests/BA_validators_test.py @@ -1275,14 +1275,14 @@ def test_IsEntityNameContainExcludedWordValidator( [create_pack_object(), create_pack_object()], 1, [ - "Pack for content item '/newPackName' and all related files were changed from 'pack_171' to 'newPackName', please undo." + "Pack for content item '/newPackName' and all related files were changed from 'pack_1' to 'newPackName', please undo." ], ), ( [create_integration_object(), create_integration_object()], 1, [ - "Pack for content item '/newPackName/Integrations/integration_0/integration_0.yml' and all related files were changed from 'pack_173' to 'newPackName', please undo." + "Pack for content item '/newPackName/Integrations/integration_0/integration_0.yml' and all related files were changed from 'pack_25' to 'newPackName', please undo." ], ), ( @@ -1292,7 +1292,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/ParsingRules/TestParsingRule/TestParsingRule.yml' and all related files were changed from 'pack_175' to 'newPackName', please undo." + "Pack for content item '/newPackName/ParsingRules/TestParsingRule/TestParsingRule.yml' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1302,7 +1302,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/CorrelationRules/correlation_rule.yml' and all related files were changed from 'pack_177' to 'newPackName', please undo." + "Pack for content item '/newPackName/CorrelationRules/correlation_rule.yml' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1312,7 +1312,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Playbooks/playbook-0.yml' and all related files were changed from 'pack_179' to 'newPackName', please undo." + "Pack for content item '/newPackName/Playbooks/playbook-0.yml' and all related files were changed from 'pack_12' to 'newPackName', please undo." ], ), ( @@ -1322,7 +1322,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/ModelingRules/modelingrule_0/modelingrule_0.yml' and all related files were changed from 'pack_181' to 'newPackName', please undo." + "Pack for content item '/newPackName/ModelingRules/modelingrule_0/modelingrule_0.yml' and all related files were changed from 'pack_1' to 'newPackName', please undo." ], ), ( @@ -1332,7 +1332,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Integrations/integration_0/integration_0.yml' and all related files were changed from 'pack_183' to 'newPackName', please undo." + "Pack for content item '/newPackName/Integrations/integration_0/integration_0.yml' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1342,7 +1342,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Scripts/script0/script0.yml' and all related files were changed from 'pack_185' to 'newPackName', please undo." + "Pack for content item '/newPackName/Scripts/script0/script0.yml' and all related files were changed from 'pack_10' to 'newPackName', please undo." ], ), ( @@ -1352,7 +1352,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Classifiers/classifier-test_classifier.json' and all related files were changed from 'pack_187' to 'newPackName', please undo." + "Pack for content item '/newPackName/Classifiers/classifier-test_classifier.json' and all related files were changed from 'pack_9' to 'newPackName', please undo." ], ), ( @@ -1362,7 +1362,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Lists/list-list.json' and all related files were changed from 'pack_189' to 'newPackName', please undo." + "Pack for content item '/newPackName/Lists/list-list.json' and all related files were changed from 'pack_8' to 'newPackName', please undo." ], ), ( @@ -1372,7 +1372,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Jobs/job-job.json' and all related files were changed from 'pack_191' to 'newPackName', please undo." + "Pack for content item '/newPackName/Jobs/job-job.json' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1382,7 +1382,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Dashboards/dashboard-dashboard.json' and all related files were changed from 'pack_193' to 'newPackName', please undo." + "Pack for content item '/newPackName/Dashboards/dashboard-dashboard.json' and all related files were changed from 'pack_6' to 'newPackName', please undo." ], ), ( @@ -1392,7 +1392,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/IncidentTypes/incidenttype-incident_type.json' and all related files were changed from 'pack_195' to 'newPackName', please undo." + "Pack for content item '/newPackName/IncidentTypes/incidenttype-incident_type.json' and all related files were changed from 'pack_9' to 'newPackName', please undo." ], ), ( @@ -1402,7 +1402,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/IncidentFields/incidentfield-incident_field.json' and all related files were changed from 'pack_197' to 'newPackName', please undo." + "Pack for content item '/newPackName/IncidentFields/incidentfield-incident_field.json' and all related files were changed from 'pack_12' to 'newPackName', please undo." ], ), ( @@ -1412,7 +1412,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Reports/report-report.json' and all related files were changed from 'pack_199' to 'newPackName', please undo." + "Pack for content item '/newPackName/Reports/report-report.json' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1422,7 +1422,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/XSIAMReports/xsiam_report.json' and all related files were changed from 'pack_201' to 'newPackName', please undo." + "Pack for content item '/newPackName/XSIAMReports/xsiam_report.json' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1432,7 +1432,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/XSIAMDashboards/xsiam_dashboard.json' and all related files were changed from 'pack_203' to 'newPackName', please undo." + "Pack for content item '/newPackName/XSIAMDashboards/xsiam_dashboard.json' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1442,7 +1442,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/XDRCTemplates/pack_205_xdrc_template/xdrc_template.json' and all related files were changed from 'pack_205' to 'newPackName', please undo." + "Pack for content item '/newPackName/XDRCTemplates/pack_1_xdrc_template/xdrc_template.json' and all related files were changed from 'pack_1' to 'newPackName', please undo." ], ), ( @@ -1452,7 +1452,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/AssetsModelingRules/assets_modeling_rule/assets_modeling_rule.yml' and all related files were changed from 'pack_207' to 'newPackName', please undo." + "Pack for content item '/newPackName/AssetsModelingRules/assets_modeling_rule/assets_modeling_rule.yml' and all related files were changed from 'pack_4' to 'newPackName', please undo." ], ), ( @@ -1462,7 +1462,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Triggers/trigger.json' and all related files were changed from 'pack_209' to 'newPackName', please undo." + "Pack for content item '/newPackName/Triggers/trigger.json' and all related files were changed from 'pack_1' to 'newPackName', please undo." ], ), ( @@ -1472,7 +1472,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Layouts/layout-layout.json' and all related files were changed from 'pack_211' to 'newPackName', please undo." + "Pack for content item '/newPackName/Layouts/layout-layout.json' and all related files were changed from 'pack_5' to 'newPackName', please undo." ], ), ( @@ -1482,7 +1482,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Widgets/widget-widget.json' and all related files were changed from 'pack_213' to 'newPackName', please undo." + "Pack for content item '/newPackName/Widgets/widget-widget.json' and all related files were changed from 'pack_5' to 'newPackName', please undo." ], ), ( @@ -1492,7 +1492,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/IndicatorFields/indicatorfield-indicator_field.json' and all related files were changed from 'pack_215' to 'newPackName', please undo." + "Pack for content item '/newPackName/IndicatorFields/indicatorfield-indicator_field.json' and all related files were changed from 'pack_21' to 'newPackName', please undo." ], ), ( @@ -1502,7 +1502,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Wizards/wizard-test_wizard.json' and all related files were changed from 'pack_217' to 'newPackName', please undo." + "Pack for content item '/newPackName/Wizards/wizard-test_wizard.json' and all related files were changed from 'pack_10' to 'newPackName', please undo." ], ), ( @@ -1512,7 +1512,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/GenericDefinitions/genericdefinition-generic_definition.json' and all related files were changed from 'pack_219' to 'newPackName', please undo." + "Pack for content item '/newPackName/GenericDefinitions/genericdefinition-generic_definition.json' and all related files were changed from 'pack_5' to 'newPackName', please undo." ], ), ( @@ -1522,7 +1522,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/GenericFields/generic_field/genericfield-generic_field.json' and all related files were changed from 'pack_221' to 'newPackName', please undo." + "Pack for content item '/newPackName/GenericFields/generic_field/genericfield-generic_field.json' and all related files were changed from 'pack_7' to 'newPackName', please undo." ], ), ( @@ -1532,7 +1532,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/GenericTypes/generic_type/generictype-generic_type.json' and all related files were changed from 'pack_223' to 'newPackName', please undo." + "Pack for content item '/newPackName/GenericTypes/generic_type/generictype-generic_type.json' and all related files were changed from 'pack_5' to 'newPackName', please undo." ], ), ( @@ -1542,7 +1542,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/GenericModules/genericmodule-generic_module.json' and all related files were changed from 'pack_225' to 'newPackName', please undo." + "Pack for content item '/newPackName/GenericModules/genericmodule-generic_module.json' and all related files were changed from 'pack_5' to 'newPackName', please undo." ], ), ( @@ -1552,7 +1552,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Classifiers/classifier-mapper-incoming_mapper.json' and all related files were changed from 'pack_227' to 'newPackName', please undo." + "Pack for content item '/newPackName/Classifiers/classifier-mapper-incoming_mapper.json' and all related files were changed from 'pack_5' to 'newPackName', please undo." ], ), ( @@ -1562,7 +1562,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/Classifiers/classifier-mapper-outgoing_mapper.json' and all related files were changed from 'pack_229' to 'newPackName', please undo." + "Pack for content item '/newPackName/Classifiers/classifier-mapper-outgoing_mapper.json' and all related files were changed from 'pack_5' to 'newPackName', please undo." ], ), ( @@ -1572,7 +1572,7 @@ def test_IsEntityNameContainExcludedWordValidator( ], 1, [ - "Pack for content item '/newPackName/IndicatorTypes/reputation-indicator_type.json' and all related files were changed from 'pack_231' to 'newPackName', please undo." + "Pack for content item '/newPackName/IndicatorTypes/reputation-indicator_type.json' and all related files were changed from 'pack_1' to 'newPackName', please undo." ], ), ], @@ -1602,12 +1602,8 @@ def test_ValidPackNameValidator_obtain_invalid_content_items( content_items[1].path = new_path results = PackNameValidator().obtain_invalid_content_items(content_items) assert len(results) == expected_number_of_failures - assert all( - [ - result.message == expected_msg - for result, expected_msg in zip(results, expected_msgs) - ] - ) + for result, expected_msg in zip(results, expected_msgs): + assert result.message == expected_msg @pytest.mark.parametrize( From 6427d91cb0f92bec42a24e1cbadfb84dea207ac5 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 21 Nov 2024 10:59:35 +0200 Subject: [PATCH 46/59] fix BA validator test --- .../commands/validate/tests/BA_validators_test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/BA_validators_test.py b/demisto_sdk/commands/validate/tests/BA_validators_test.py index 85a5772eb0e..84646a7f9e5 100644 --- a/demisto_sdk/commands/validate/tests/BA_validators_test.py +++ b/demisto_sdk/commands/validate/tests/BA_validators_test.py @@ -1613,34 +1613,34 @@ def test_ValidPackNameValidator_obtain_invalid_content_items( pytest.param( [create_integration_object(readme_content="test-module")], 1, - "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_233/Integrations/integration_0/README.md", + "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_27/Integrations/integration_0/README.md", id="invalid: integration readme", ), pytest.param( [create_integration_object(description_content="test-module")], 1, - "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_234/Integrations/integration_0/integration_0_description.md", + "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_28/Integrations/integration_0/integration_0_description.md", id="invalid: integration description", ), pytest.param([create_script_object()], 0, "", id="valid: script"), pytest.param( [create_script_object(readme_content="test-module ")], 1, - "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_236/Scripts/script0/README.md", + "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_12/Scripts/script0/README.md", id="invalid: script readme", ), pytest.param([create_playbook_object()], 0, "", id="valid: playbook"), pytest.param( [create_playbook_object(readme_content="test-module ")], 1, - "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_238/Playbooks/playbook-0_README.md", + "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_14/Playbooks/playbook-0_README.md", id="invalid: playbook readme", ), pytest.param([create_pack_object()], 0, "", id="valid: pack"), pytest.param( [create_pack_object(readme_text="test-module ")], 1, - "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_240/README.md", + "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_3/README.md", id="invalid: pack readme", ), pytest.param( @@ -1650,7 +1650,7 @@ def test_ValidPackNameValidator_obtain_invalid_content_items( ) ], 1, - "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_241/ReleaseNotes/1_0_1.md", + "Found internal terms in a customer-facing documentation: found test-module in Packs/pack_4/ReleaseNotes/1_0_1.md", id="invalid: pack release note", ), ], From a5fbdc887cc5b2d83a5823d0eb6b398b7e3367b1 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 21 Nov 2024 11:03:08 +0200 Subject: [PATCH 47/59] fix GR validators tests --- demisto_sdk/commands/validate/tests/GR_validators_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demisto_sdk/commands/validate/tests/GR_validators_test.py b/demisto_sdk/commands/validate/tests/GR_validators_test.py index 5f442e0ab8d..126bb1d676b 100644 --- a/demisto_sdk/commands/validate/tests/GR_validators_test.py +++ b/demisto_sdk/commands/validate/tests/GR_validators_test.py @@ -1,3 +1,5 @@ +from pathlib import Path + import pytest from pytest_mock import MockerFixture @@ -85,7 +87,7 @@ def test_IsPackDisplayNameAlreadyExistsValidatorListFiles_obtain_invalid_content mocker.patch.object( GR104_is_pack_display_name_already_exists.ContentPaths, "CONTENT_PATH", - new=graph_repo.path, + new=Path(graph_repo.path), ) graph_repo.create_pack(name="pack1") From 1d2a4d74f9f671337120879a452e6495b96e72f4 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 21 Nov 2024 13:34:14 +0200 Subject: [PATCH 48/59] fix validate tests --- demisto_sdk/commands/common/tools.py | 4 +- .../validate/tests/RM_validators_test.py | 403 +++++++++--------- .../commands/validate/tests/test_tools.py | 26 +- .../RM114_is_image_exists_in_readme.py | 4 +- 4 files changed, 229 insertions(+), 208 deletions(-) diff --git a/demisto_sdk/commands/common/tools.py b/demisto_sdk/commands/common/tools.py index 40ee9eea5cd..306842683e8 100644 --- a/demisto_sdk/commands/common/tools.py +++ b/demisto_sdk/commands/common/tools.py @@ -4443,10 +4443,8 @@ def extract_image_paths_from_str( ) -> List[str]: """ Args: - local_paths (List[str]): list of file paths - is_lower (bool): True to check when line is lower cased. - to_split (bool): True to split the line in order to search specific word text (str): The readme content to search. + regex_str (str): regex to search for. Returns: list of lines which contains the given text. diff --git a/demisto_sdk/commands/validate/tests/RM_validators_test.py b/demisto_sdk/commands/validate/tests/RM_validators_test.py index 0e9965c6481..f1b2ab44f67 100644 --- a/demisto_sdk/commands/validate/tests/RM_validators_test.py +++ b/demisto_sdk/commands/validate/tests/RM_validators_test.py @@ -68,26 +68,26 @@ "content_items, expected_number_of_failures, expected_msgs", [ ( - [ - create_pack_object(readme_text="This is a valid readme."), - create_pack_object(readme_text=""), - ], - 0, - [], + [ + create_pack_object(readme_text="This is a valid readme."), + create_pack_object(readme_text=""), + ], + 0, + [], ), ( - [create_pack_object(readme_text="Invalid readme\nBSD\nCopyright")], - 1, - [ - "Invalid keywords related to Copyrights (BSD, MIT, Copyright, proprietary) were found in lines: 2, 3. Copyright section cannot be part of pack readme." - ], + [create_pack_object(readme_text="Invalid readme\nBSD\nCopyright")], + 1, + [ + "Invalid keywords related to Copyrights (BSD, MIT, Copyright, proprietary) were found in lines: 2, 3. Copyright section cannot be part of pack readme." + ], ), ], ) def test_IsContainCopyRightSectionValidator_obtain_invalid_content_items( - content_items, - expected_number_of_failures, - expected_msgs, + content_items, + expected_number_of_failures, + expected_msgs, ): """ Given @@ -119,48 +119,48 @@ def test_IsContainCopyRightSectionValidator_obtain_invalid_content_items( "content_items, expected_number_of_failures, expected_msgs", [ ( - [ - create_pack_object( - paths=["support"], - values=["partner"], - readme_text="This is a valid readme.", - ), # valid readme with partner support - create_pack_object( - readme_text="" - ), # empty readme but with no partner support and no playbooks - create_pack_object( - readme_text="This is valid readme", playbooks=1 - ), # should pass as it has a valid readme and playbooks - ], - 0, - [], + [ + create_pack_object( + paths=["support"], + values=["partner"], + readme_text="This is a valid readme.", + ), # valid readme with partner support + create_pack_object( + readme_text="" + ), # empty readme but with no partner support and no playbooks + create_pack_object( + readme_text="This is valid readme", playbooks=1 + ), # should pass as it has a valid readme and playbooks + ], + 0, + [], ), ( - [ - create_pack_object( - paths=["support"], values=["partner"], readme_text="" - ), - ], # empty readme with partner support, not valid - 1, - [ - "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information", - ], + [ + create_pack_object( + paths=["support"], values=["partner"], readme_text="" + ), + ], # empty readme with partner support, not valid + 1, + [ + "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information", + ], ), ( - [ - create_pack_object(readme_text="", playbooks=1) - ], # empty readme with playbooks, not valid - 1, - [ - "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information" - ], + [ + create_pack_object(readme_text="", playbooks=1) + ], # empty readme with playbooks, not valid + 1, + [ + "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information" + ], ), ], ) def test_empty_readme_validator( - content_items, - expected_number_of_failures, - expected_msgs, + content_items, + expected_number_of_failures, + expected_msgs, ): """ Given: @@ -194,36 +194,36 @@ def test_empty_readme_validator( [ ([create_integration_object()], 0), ( - [ - create_integration_object( - readme_content='Alt text' - ) - ], - 1, + [ + create_integration_object( + readme_content='Alt text' + ) + ], + 1, ), ( - [ - create_script_object( - readme_content='Alt text' - ) - ], - 1, + [ + create_script_object( + readme_content='Alt text' + ) + ], + 1, ), ( - [ - create_pack_object( - readme_text='Alt text' - ) - ], - 1, + [ + create_pack_object( + readme_text='Alt text' + ) + ], + 1, ), ( - [ - create_playbook_object( - readme_content='Alt text' - ) - ], - 1, + [ + create_playbook_object( + readme_content='Alt text' + ) + ], + 1, ), ], ) @@ -254,82 +254,98 @@ def test_is_image_path_validator(content_items, expected_number_of_failures): ] ) +def create_content_items_1(temp_repo): + return [ + create_playbook_object( + readme_content="This is a valid readme without any images.", + pack_info={"name": "test1"}, + repo=temp_repo + ), + create_playbook_object( + readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.png)", + pack_info={"name": "test2"}, + repo=temp_repo + ), + create_playbook_object(readme_content="", pack_info={"name": "test1"}), + create_integration_object( + readme_content="This is a valid readme without any images.", + pack_info={"name": "test3"}, + repo=temp_repo + ), + create_integration_object( + readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.png)", + pack_info={"name": "test4"}, + repo=temp_repo + ), + create_integration_object( + readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.jpg)", + pack_info={"name": "test5"}, + repo=temp_repo + ), + create_integration_object( + readme_content="", pack_info={"name": "test6"}, repo=temp_repo + ) + ] + +def create_content_item_2(temp_repo): + return [ + create_playbook_object( + readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png), ", + pack_info={"name": "test1"}, + repo=temp_repo + ), + create_integration_object( + readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png)", + pack_info={"name": "test2"}, + repo=temp_repo + ), + create_playbook_object( + readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png ), ", + pack_info={"name": "test3"}, + repo=temp_repo + ), + create_integration_object( + readme_content="This is not a valid readme if this file doesn't exists ![example image]( ../doc_files/example.png)", + pack_info={"name": "test4"}, + repo=temp_repo + ), + create_integration_object( + readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.jpg)", + pack_info={"name": "test5"}, + repo=temp_repo + ) + ] @pytest.mark.parametrize( - "content_items, doc_files_name, expected_number_of_failures, expected_msgs", + "create_content_items_func, doc_files_name, expected_number_of_failures, expected_msgs", [ + # ( + # create_content_items_1, + # [None, "example.png", None, None, "example.png", "example.jpg", None], + # 0, + # [], + # ), ( - [ - create_playbook_object( - readme_content="This is a valid readme without any images.", - pack_info={"name": "test1"}, - ), - create_playbook_object( - readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.png)", - pack_info={"name": "test1"}, - ), - create_playbook_object(readme_content="", pack_info={"name": "test1"}), - create_integration_object( - readme_content="This is a valid readme without any images.", - pack_info={"name": "test2"}, - ), - create_integration_object( - readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.png)", - pack_info={"name": "test2"}, - ), - create_integration_object( - readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.jpg)", - pack_info={"name": "test2"}, - ), - create_integration_object( - readme_content="", pack_info={"name": "test2"} - ), - ], - [None, "example.png", None, None, "example.png", "example.jpg", None], - 0, - [], - ), - ( - [ - create_playbook_object( - readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png), ", - pack_info={"name": "test1"}, - ), - create_integration_object( - readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png)", - pack_info={"name": "test2"}, - ), - create_playbook_object( - readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png ), ", - pack_info={"name": "test3"}, - ), - create_integration_object( - readme_content="This is not a valid readme if this file doesn't exists ![example image]( ../doc_files/example.png)", - pack_info={"name": "test4"}, - ), - create_integration_object( - readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.jpg)", - pack_info={"name": "test5"}, - ), - ], - [None, None, "example.png", "example.png", None], - 5, - [ - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test1/doc_files/example.png", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test2/doc_files/example.png", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test3/doc_files/example.png", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test5/doc_files/example.jpg", - ], + create_content_item_2, + [None, None, "example.png", "example.png", None], + 5, + [ + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test1/doc_files/example.png", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test2/doc_files/example.png", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test3/doc_files/example.png ", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test4/ doc_files/example.png", + ], ), ], ) def test_IsImageExistsInReadmeValidator_obtain_invalid_content_items( - content_items, - doc_files_name, - expected_number_of_failures, - expected_msgs, + create_content_items_func, + doc_files_name, + expected_number_of_failures, + expected_msgs, ): repo = get_temp_repo() + content_items = create_content_items_func(repo) with ChangeCWD(repo.path): for content_item, file_name in zip(content_items, doc_files_name): if file_name: @@ -339,12 +355,9 @@ def test_IsImageExistsInReadmeValidator_obtain_invalid_content_items( content_items ) assert len(results) == expected_number_of_failures - assert all( - [ - (result.message, expected_msg) - for result, expected_msg in zip(results, expected_msgs) - ] - ) + for result, expected_msg in zip(results, expected_msgs): + result_message = result.message + assert result.message == expected_msg def test_IsPackReadmeNotEqualPackDescriptionValidator_not_valid(): @@ -396,39 +409,39 @@ def test_IsPackReadmeNotEqualPackDescriptionValidator_valid(): "content_items, expected_number_of_failures, expected_msgs", [ ( - [ - create_playbook_object(), - create_playbook_object(), - ], - 1, - [ - "The Playbook 'Detonate File - JoeSecurity V2' doesn't have a README file. Please add a README.md file in the content item's directory." - ], + [ + create_playbook_object(), + create_playbook_object(), + ], + 1, + [ + "The Playbook 'Detonate File - JoeSecurity V2' doesn't have a README file. Please add a README.md file in the content item's directory." + ], ), ( - [ - create_script_object(), - create_script_object(), - ], - 1, - [ - "The Script 'myScript' doesn't have a README file. Please add a README.md file in the content item's directory." - ], + [ + create_script_object(), + create_script_object(), + ], + 1, + [ + "The Script 'myScript' doesn't have a README file. Please add a README.md file in the content item's directory." + ], ), ( - [ - create_integration_object(), - create_integration_object(), - ], - 1, - [ - "The Integration 'TestIntegration' doesn't have a README file. Please add a README.md file in the content item's directory." - ], + [ + create_integration_object(), + create_integration_object(), + ], + 1, + [ + "The Integration 'TestIntegration' doesn't have a README file. Please add a README.md file in the content item's directory." + ], ), ], ) def test_IsReadmeExistsValidator_obtain_invalid_content_items( - content_items, expected_number_of_failures, expected_msgs + content_items, expected_number_of_failures, expected_msgs ): """ Given: @@ -539,7 +552,7 @@ def test_ImagePathIntegrationValidator_obtain_invalid_content_items_invalid_case content_items = [ create_integration_object( readme_content=" Readme contains absolute path:\n 'Here is an image:\n" - " ![Example Image](https://www.example.com/images/example_image.jpg)", + " ![Example Image](https://www.example.com/images/example_image.jpg)", description_content="valid description ![Example Image](../../content/image.jpg)", ), ] @@ -593,8 +606,8 @@ def test_ImagePathOnlyReadMeValidator_obtain_invalid_content_items_invalid_case( content_items = [ create_integration_object( readme_content=" Readme contains absolute path:\n 'Here is an image:\n" - " ![Example Image](https://www.example.com/images/example_image.jpg)" - " ![Example Image](../../content/image.jpg)", + " ![Example Image](https://www.example.com/images/example_image.jpg)" + " ![Example Image](../../content/image.jpg)", ), ] expected = ( @@ -714,8 +727,8 @@ def test_get_command_context_path_from_readme_file_missing_from_yml(): integrations ) assert ( - results[0].message - == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from yml: Test.Path1\n" + results[0].message + == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from yml: Test.Path1\n" ) @@ -762,8 +775,8 @@ def test_get_command_context_path_from_readme_file_missing_from_readme(): [content_item] ) assert ( - results[0].message - == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from readme: Test.Path2\n" + results[0].message + == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from readme: Test.Path2\n" ) @@ -870,12 +883,12 @@ def test_get_command_context_path_from_readme_file_multiple_commands(): ) assert len(results) == 1 assert ( - "command1:\nThe following outputs are missing from readme: Test.Path2\n" - in results[0].message + "command1:\nThe following outputs are missing from readme: Test.Path2\n" + in results[0].message ) assert ( - "command2:\nThe following outputs are missing from yml: Test.Path3\nThe following outputs are missing from readme: Test.Path4\n" - in results[0].message + "command2:\nThe following outputs are missing from yml: Test.Path3\nThe following outputs are missing from readme: Test.Path4\n" + in results[0].message ) @@ -1062,33 +1075,33 @@ def test_valid_sections(file_input): "file_input, section", [ ( - "##### Required Permissions\n**FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions\n**FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "##### Required Permissions **FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions **FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "This integration was integrated and tested with version xx of integration v2.", - "version xx", + "This integration was integrated and tested with version xx of integration v2.", + "version xx", ), ( - "##Dummy Integration\n this integration is for getting started and learn how to build an " - "integration. some extra text here", - "getting started and learn how to build an integration", + "##Dummy Integration\n this integration is for getting started and learn how to build an " + "integration. some extra text here", + "getting started and learn how to build an integration", ), ( - "In this readme template all required notes should be replaced.\n# %%UPDATE%% ", - "%%UPDATE%%", + "In this readme template all required notes should be replaced.\n# %%UPDATE%% ", + "%%UPDATE%%", ), ], ) diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index 5da7ad0f3f6..5c68ff7bd26 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -90,9 +90,10 @@ def create_integration_object( yml_content = load_yaml("integration.yml") update_keys(yml_content, paths, values) - pack = repo.create_pack() if pack_info: - pack.set_data(**pack_info) + pack = repo.create_pack(**pack_info) + else: + pack = repo.create_pack() additional_params = {} @@ -142,7 +143,7 @@ def create_correlation_rule_object( values: Optional[List[Any]] = None, repo=get_temp_repo(), ) -> CorrelationRule: - """Creating an correlation_rule object with altered fields from a default correlation_rule yml structure. + """Creating a correlation_rule object with altered fields from a default correlation_rule yml structure. Args: paths (Optional[List[str]]): The keys to update. @@ -181,9 +182,11 @@ def create_playbook_object( """ yml_content = load_yaml("playbook.yml") update_keys(yml_content, paths, values) - pack = repo.create_pack() if pack_info: - pack.set_data(**pack_info) + pack = repo.create_pack(**pack_info) + else: + pack = repo.create_pack() + additional_params = {} if readme_content is not None: @@ -201,6 +204,7 @@ def create_test_playbook_object( values: Optional[List[Any]] = None, pack_info: Optional[Dict[str, Any]] = None, readme_content: Optional[str] = None, + repo=get_temp_repo(), ) -> TestPlaybook: """Creating a test playbook object with altered fields from a default test playbook yml structure. @@ -209,14 +213,17 @@ def create_test_playbook_object( values (Optional[List[Any]]): The values to update. pack_info (Optional[List[str]]): The playbook's pack name. readme_content (Optional[List[Any]]): The playbook's readme. + repo: Containing repository object. New temporary repo is created by default. + Returns: The test playbook object. """ yml_content = load_yaml("playbook.yml") update_keys(yml_content, paths, values) - pack = get_temp_repo().create_pack() if pack_info: - pack.set_data(**pack_info) + pack = repo.create_pack(**pack_info) + else: + pack = repo.create_pack() additional_params = {} if readme_content is not None: @@ -322,9 +329,10 @@ def create_script_object( yml_content = load_yaml("script.yml") update_keys(yml_content, paths, values) - pack = repo.create_pack() if pack_info: - pack.set_data(**pack_info) + pack = repo.create_pack(**pack_info) + else: + pack = repo.create_pack() if readme_content is not None: additional_params["readme"] = readme_content diff --git a/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py b/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py index 9610840b862..d4224e81d61 100644 --- a/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py +++ b/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py @@ -27,7 +27,8 @@ class IsImageExistsInReadmeValidator(BaseValidator[ContentTypes]): description = ( "Validate that images placed under doc_files folder and used in README exist." ) - error_message = "The following images do not exist or have additional characters present in their declaration within the README: {0}" + error_message = ("The following images do not exist or have additional characters present in their declaration " + "within the README: {0}") rationale = "Missing images are not shown in rendered markdown" related_field = "" is_auto_fixable = False @@ -36,6 +37,7 @@ class IsImageExistsInReadmeValidator(BaseValidator[ContentTypes]): def obtain_invalid_content_items( self, content_items: Iterable[ContentTypes] ) -> List[ValidationResult]: + return [ ValidationResult( validator=self, From 9389d17d2bc7b2f4c67eaf50b56197ddaf4b21ff Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 21 Nov 2024 13:44:05 +0200 Subject: [PATCH 49/59] pre-commit --- .../validate/tests/RM_validators_test.py | 299 +++++++++--------- .../RM114_is_image_exists_in_readme.py | 7 +- 2 files changed, 155 insertions(+), 151 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/RM_validators_test.py b/demisto_sdk/commands/validate/tests/RM_validators_test.py index f1b2ab44f67..1f9fe59d4c8 100644 --- a/demisto_sdk/commands/validate/tests/RM_validators_test.py +++ b/demisto_sdk/commands/validate/tests/RM_validators_test.py @@ -68,26 +68,26 @@ "content_items, expected_number_of_failures, expected_msgs", [ ( - [ - create_pack_object(readme_text="This is a valid readme."), - create_pack_object(readme_text=""), - ], - 0, - [], + [ + create_pack_object(readme_text="This is a valid readme."), + create_pack_object(readme_text=""), + ], + 0, + [], ), ( - [create_pack_object(readme_text="Invalid readme\nBSD\nCopyright")], - 1, - [ - "Invalid keywords related to Copyrights (BSD, MIT, Copyright, proprietary) were found in lines: 2, 3. Copyright section cannot be part of pack readme." - ], + [create_pack_object(readme_text="Invalid readme\nBSD\nCopyright")], + 1, + [ + "Invalid keywords related to Copyrights (BSD, MIT, Copyright, proprietary) were found in lines: 2, 3. Copyright section cannot be part of pack readme." + ], ), ], ) def test_IsContainCopyRightSectionValidator_obtain_invalid_content_items( - content_items, - expected_number_of_failures, - expected_msgs, + content_items, + expected_number_of_failures, + expected_msgs, ): """ Given @@ -119,48 +119,48 @@ def test_IsContainCopyRightSectionValidator_obtain_invalid_content_items( "content_items, expected_number_of_failures, expected_msgs", [ ( - [ - create_pack_object( - paths=["support"], - values=["partner"], - readme_text="This is a valid readme.", - ), # valid readme with partner support - create_pack_object( - readme_text="" - ), # empty readme but with no partner support and no playbooks - create_pack_object( - readme_text="This is valid readme", playbooks=1 - ), # should pass as it has a valid readme and playbooks - ], - 0, - [], + [ + create_pack_object( + paths=["support"], + values=["partner"], + readme_text="This is a valid readme.", + ), # valid readme with partner support + create_pack_object( + readme_text="" + ), # empty readme but with no partner support and no playbooks + create_pack_object( + readme_text="This is valid readme", playbooks=1 + ), # should pass as it has a valid readme and playbooks + ], + 0, + [], ), ( - [ - create_pack_object( - paths=["support"], values=["partner"], readme_text="" - ), - ], # empty readme with partner support, not valid - 1, - [ - "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information", - ], + [ + create_pack_object( + paths=["support"], values=["partner"], readme_text="" + ), + ], # empty readme with partner support, not valid + 1, + [ + "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information", + ], ), ( - [ - create_pack_object(readme_text="", playbooks=1) - ], # empty readme with playbooks, not valid - 1, - [ - "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information" - ], + [ + create_pack_object(readme_text="", playbooks=1) + ], # empty readme with playbooks, not valid + 1, + [ + "Pack HelloWorld written by a partner or pack containing playbooks must have a full README.md file with pack information. Please refer to https://xsoar.pan.dev/docs/documentation/pack-docs#pack-readme for more information" + ], ), ], ) def test_empty_readme_validator( - content_items, - expected_number_of_failures, - expected_msgs, + content_items, + expected_number_of_failures, + expected_msgs, ): """ Given: @@ -194,36 +194,36 @@ def test_empty_readme_validator( [ ([create_integration_object()], 0), ( - [ - create_integration_object( - readme_content='Alt text' - ) - ], - 1, + [ + create_integration_object( + readme_content='Alt text' + ) + ], + 1, ), ( - [ - create_script_object( - readme_content='Alt text' - ) - ], - 1, + [ + create_script_object( + readme_content='Alt text' + ) + ], + 1, ), ( - [ - create_pack_object( - readme_text='Alt text' - ) - ], - 1, + [ + create_pack_object( + readme_text='Alt text' + ) + ], + 1, ), ( - [ - create_playbook_object( - readme_content='Alt text' - ) - ], - 1, + [ + create_playbook_object( + readme_content='Alt text' + ) + ], + 1, ), ], ) @@ -254,68 +254,71 @@ def test_is_image_path_validator(content_items, expected_number_of_failures): ] ) + def create_content_items_1(temp_repo): return [ create_playbook_object( readme_content="This is a valid readme without any images.", pack_info={"name": "test1"}, - repo=temp_repo + repo=temp_repo, ), create_playbook_object( readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.png)", pack_info={"name": "test2"}, - repo=temp_repo + repo=temp_repo, ), create_playbook_object(readme_content="", pack_info={"name": "test1"}), create_integration_object( readme_content="This is a valid readme without any images.", pack_info={"name": "test3"}, - repo=temp_repo + repo=temp_repo, ), create_integration_object( readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.png)", pack_info={"name": "test4"}, - repo=temp_repo + repo=temp_repo, ), create_integration_object( readme_content="This is a valid readme if this file exists ![example image](../doc_files/example.jpg)", pack_info={"name": "test5"}, - repo=temp_repo + repo=temp_repo, ), create_integration_object( readme_content="", pack_info={"name": "test6"}, repo=temp_repo - ) + ), ] + def create_content_item_2(temp_repo): return [ create_playbook_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png), ", pack_info={"name": "test1"}, - repo=temp_repo + repo=temp_repo, ), create_integration_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png)", pack_info={"name": "test2"}, - repo=temp_repo + repo=temp_repo, ), create_playbook_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png ), ", pack_info={"name": "test3"}, - repo=temp_repo + repo=temp_repo, ), create_integration_object( readme_content="This is not a valid readme if this file doesn't exists ![example image]( ../doc_files/example.png)", pack_info={"name": "test4"}, - repo=temp_repo + repo=temp_repo, ), create_integration_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.jpg)", pack_info={"name": "test5"}, - repo=temp_repo - ) + repo=temp_repo, + ), ] + @pytest.mark.parametrize( "create_content_items_func, doc_files_name, expected_number_of_failures, expected_msgs", [ @@ -326,23 +329,23 @@ def create_content_item_2(temp_repo): # [], # ), ( - create_content_item_2, - [None, None, "example.png", "example.png", None], - 5, - [ - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test1/doc_files/example.png", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test2/doc_files/example.png", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test3/doc_files/example.png ", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test4/ doc_files/example.png", - ], + create_content_item_2, + [None, None, "example.png", "example.png", None], + 5, + [ + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test1/doc_files/example.png", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test2/doc_files/example.png", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test3/doc_files/example.png ", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/test4/ doc_files/example.png", + ], ), ], ) def test_IsImageExistsInReadmeValidator_obtain_invalid_content_items( - create_content_items_func, - doc_files_name, - expected_number_of_failures, - expected_msgs, + create_content_items_func, + doc_files_name, + expected_number_of_failures, + expected_msgs, ): repo = get_temp_repo() content_items = create_content_items_func(repo) @@ -409,39 +412,39 @@ def test_IsPackReadmeNotEqualPackDescriptionValidator_valid(): "content_items, expected_number_of_failures, expected_msgs", [ ( - [ - create_playbook_object(), - create_playbook_object(), - ], - 1, - [ - "The Playbook 'Detonate File - JoeSecurity V2' doesn't have a README file. Please add a README.md file in the content item's directory." - ], + [ + create_playbook_object(), + create_playbook_object(), + ], + 1, + [ + "The Playbook 'Detonate File - JoeSecurity V2' doesn't have a README file. Please add a README.md file in the content item's directory." + ], ), ( - [ - create_script_object(), - create_script_object(), - ], - 1, - [ - "The Script 'myScript' doesn't have a README file. Please add a README.md file in the content item's directory." - ], + [ + create_script_object(), + create_script_object(), + ], + 1, + [ + "The Script 'myScript' doesn't have a README file. Please add a README.md file in the content item's directory." + ], ), ( - [ - create_integration_object(), - create_integration_object(), - ], - 1, - [ - "The Integration 'TestIntegration' doesn't have a README file. Please add a README.md file in the content item's directory." - ], + [ + create_integration_object(), + create_integration_object(), + ], + 1, + [ + "The Integration 'TestIntegration' doesn't have a README file. Please add a README.md file in the content item's directory." + ], ), ], ) def test_IsReadmeExistsValidator_obtain_invalid_content_items( - content_items, expected_number_of_failures, expected_msgs + content_items, expected_number_of_failures, expected_msgs ): """ Given: @@ -552,7 +555,7 @@ def test_ImagePathIntegrationValidator_obtain_invalid_content_items_invalid_case content_items = [ create_integration_object( readme_content=" Readme contains absolute path:\n 'Here is an image:\n" - " ![Example Image](https://www.example.com/images/example_image.jpg)", + " ![Example Image](https://www.example.com/images/example_image.jpg)", description_content="valid description ![Example Image](../../content/image.jpg)", ), ] @@ -606,8 +609,8 @@ def test_ImagePathOnlyReadMeValidator_obtain_invalid_content_items_invalid_case( content_items = [ create_integration_object( readme_content=" Readme contains absolute path:\n 'Here is an image:\n" - " ![Example Image](https://www.example.com/images/example_image.jpg)" - " ![Example Image](../../content/image.jpg)", + " ![Example Image](https://www.example.com/images/example_image.jpg)" + " ![Example Image](../../content/image.jpg)", ), ] expected = ( @@ -727,8 +730,8 @@ def test_get_command_context_path_from_readme_file_missing_from_yml(): integrations ) assert ( - results[0].message - == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from yml: Test.Path1\n" + results[0].message + == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from yml: Test.Path1\n" ) @@ -775,8 +778,8 @@ def test_get_command_context_path_from_readme_file_missing_from_readme(): [content_item] ) assert ( - results[0].message - == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from readme: Test.Path2\n" + results[0].message + == "Find discrepancy for the following commands:\ntest-command:\nThe following outputs are missing from readme: Test.Path2\n" ) @@ -883,12 +886,12 @@ def test_get_command_context_path_from_readme_file_multiple_commands(): ) assert len(results) == 1 assert ( - "command1:\nThe following outputs are missing from readme: Test.Path2\n" - in results[0].message + "command1:\nThe following outputs are missing from readme: Test.Path2\n" + in results[0].message ) assert ( - "command2:\nThe following outputs are missing from yml: Test.Path3\nThe following outputs are missing from readme: Test.Path4\n" - in results[0].message + "command2:\nThe following outputs are missing from yml: Test.Path3\nThe following outputs are missing from readme: Test.Path4\n" + in results[0].message ) @@ -1075,33 +1078,33 @@ def test_valid_sections(file_input): "file_input, section", [ ( - "##### Required Permissions\n**FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions\n**FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "##### Required Permissions **FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions **FILL IN REQUIRED PERMISSIONS HERE**\n##### Base Command", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", - "FILL IN REQUIRED PERMISSIONS HERE", + "##### Required Permissions FILL IN REQUIRED PERMISSIONS HERE", + "FILL IN REQUIRED PERMISSIONS HERE", ), ( - "This integration was integrated and tested with version xx of integration v2.", - "version xx", + "This integration was integrated and tested with version xx of integration v2.", + "version xx", ), ( - "##Dummy Integration\n this integration is for getting started and learn how to build an " - "integration. some extra text here", - "getting started and learn how to build an integration", + "##Dummy Integration\n this integration is for getting started and learn how to build an " + "integration. some extra text here", + "getting started and learn how to build an integration", ), ( - "In this readme template all required notes should be replaced.\n# %%UPDATE%% ", - "%%UPDATE%%", + "In this readme template all required notes should be replaced.\n# %%UPDATE%% ", + "%%UPDATE%%", ), ], ) diff --git a/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py b/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py index d4224e81d61..27d65ecd577 100644 --- a/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py +++ b/demisto_sdk/commands/validate/validators/RM_validators/RM114_is_image_exists_in_readme.py @@ -27,8 +27,10 @@ class IsImageExistsInReadmeValidator(BaseValidator[ContentTypes]): description = ( "Validate that images placed under doc_files folder and used in README exist." ) - error_message = ("The following images do not exist or have additional characters present in their declaration " - "within the README: {0}") + error_message = ( + "The following images do not exist or have additional characters present in their declaration " + "within the README: {0}" + ) rationale = "Missing images are not shown in rendered markdown" related_field = "" is_auto_fixable = False @@ -37,7 +39,6 @@ class IsImageExistsInReadmeValidator(BaseValidator[ContentTypes]): def obtain_invalid_content_items( self, content_items: Iterable[ContentTypes] ) -> List[ValidationResult]: - return [ ValidationResult( validator=self, From 73df955881fe3868bba9dd154e5a3643006e03dd Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 21 Nov 2024 14:05:37 +0200 Subject: [PATCH 50/59] unittests fix --- demisto_sdk/commands/validate/tests/RM_validators_test.py | 1 - demisto_sdk/commands/validate/tests/test_tools.py | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/RM_validators_test.py b/demisto_sdk/commands/validate/tests/RM_validators_test.py index 1f9fe59d4c8..57fcc05645a 100644 --- a/demisto_sdk/commands/validate/tests/RM_validators_test.py +++ b/demisto_sdk/commands/validate/tests/RM_validators_test.py @@ -359,7 +359,6 @@ def test_IsImageExistsInReadmeValidator_obtain_invalid_content_items( ) assert len(results) == expected_number_of_failures for result, expected_msg in zip(results, expected_msgs): - result_message = result.message assert result.message == expected_msg diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index 5c68ff7bd26..1b02a24ad6f 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -90,10 +90,9 @@ def create_integration_object( yml_content = load_yaml("integration.yml") update_keys(yml_content, paths, values) + pack = repo.create_pack() if pack_info: - pack = repo.create_pack(**pack_info) - else: - pack = repo.create_pack() + pack.set_data(**pack_info) additional_params = {} From c752a5c54e4e2e8669b47e65b4c853b043b983c4 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Thu, 21 Nov 2024 14:41:57 +0200 Subject: [PATCH 51/59] unittests fix --- demisto_sdk/commands/validate/tests/BC_validators_test.py | 1 + demisto_sdk/commands/validate/tests/GR_validators_test.py | 2 +- demisto_sdk/commands/validate/tests/SC_validators_test.py | 6 ++++-- demisto_sdk/commands/validate/tests/test_tools.py | 7 +++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/BC_validators_test.py b/demisto_sdk/commands/validate/tests/BC_validators_test.py index 3345afd5f71..610065305a4 100644 --- a/demisto_sdk/commands/validate/tests/BC_validators_test.py +++ b/demisto_sdk/commands/validate/tests/BC_validators_test.py @@ -395,6 +395,7 @@ def test_WasMarketplaceModifiedValidator__modified_item_has_only_one_marketplace pack_info={"marketplaces": in_pack_marketplaces}, repo=repo ), ] + # old_content_items = [create_integration_object(repo=repo), create_script_object(repo=repo)] old_content_items = [create_integration_object(), create_script_object()] modified_content_items[0].marketplaces = modified_content_items[ diff --git a/demisto_sdk/commands/validate/tests/GR_validators_test.py b/demisto_sdk/commands/validate/tests/GR_validators_test.py index 126bb1d676b..07d3f66bdd8 100644 --- a/demisto_sdk/commands/validate/tests/GR_validators_test.py +++ b/demisto_sdk/commands/validate/tests/GR_validators_test.py @@ -126,7 +126,7 @@ def test_IsPackDisplayNameAlreadyExistsValidatorAllFiles_obtain_invalid_content_ mocker.patch.object( GR104_is_pack_display_name_already_exists.ContentPaths, "CONTENT_PATH", - new=graph_repo.path, + new=Path(graph_repo.path), ) graph_repo.create_pack(name="pack1") diff --git a/demisto_sdk/commands/validate/tests/SC_validators_test.py b/demisto_sdk/commands/validate/tests/SC_validators_test.py index 8598ab979e7..855dc6039b6 100644 --- a/demisto_sdk/commands/validate/tests/SC_validators_test.py +++ b/demisto_sdk/commands/validate/tests/SC_validators_test.py @@ -1,3 +1,5 @@ +from pathlib import Path + from demisto_sdk.commands.common.constants import ( SKIP_PREPARE_SCRIPT_NAME, MarketplaceVersions, @@ -166,7 +168,7 @@ def test_DuplicatedScriptNameValidatorListFiles_obtain_invalid_content_items( mocker.patch.object( SC109_script_name_is_not_unique_validator.ContentPaths, "CONTENT_PATH", - new=graph_repo.path, + new=Path(graph_repo.path), ) pack = graph_repo.create_pack() @@ -214,7 +216,7 @@ def test_DuplicatedScriptNameValidatorAllFiles_obtain_invalid_content_items( mocker.patch.object( SC109_script_name_is_not_unique_validator.ContentPaths, "CONTENT_PATH", - new=graph_repo.path, + new=Path(graph_repo.path), ) pack = graph_repo.create_pack() diff --git a/demisto_sdk/commands/validate/tests/test_tools.py b/demisto_sdk/commands/validate/tests/test_tools.py index 1b02a24ad6f..20684c0a6dd 100644 --- a/demisto_sdk/commands/validate/tests/test_tools.py +++ b/demisto_sdk/commands/validate/tests/test_tools.py @@ -311,7 +311,7 @@ def create_script_object( test_code: Optional[str] = None, repo=get_temp_repo(), ) -> Script: - """Creating an script object with altered fields from a default script yml structure. + """Creating a script object with altered fields from a default script yml structure. Args: paths (Optional[List[str]]): The keys to update. @@ -328,10 +328,9 @@ def create_script_object( yml_content = load_yaml("script.yml") update_keys(yml_content, paths, values) + pack = repo.create_pack() if pack_info: - pack = repo.create_pack(**pack_info) - else: - pack = repo.create_pack() + pack.set_data(**pack_info) if readme_content is not None: additional_params["readme"] = readme_content From c2ac9c2f4b47cffadb2b8e20356b199b87217def Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 10:29:11 +0200 Subject: [PATCH 52/59] unittests fix --- .../validate/tests/IN_validators_test.py | 211 ++++++++++-------- .../validate/tests/RM_validators_test.py | 30 +-- 2 files changed, 127 insertions(+), 114 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/IN_validators_test.py b/demisto_sdk/commands/validate/tests/IN_validators_test.py index 33e51899154..ad01916d7af 100644 --- a/demisto_sdk/commands/validate/tests/IN_validators_test.py +++ b/demisto_sdk/commands/validate/tests/IN_validators_test.py @@ -5280,113 +5280,125 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_i ) -@pytest.mark.parametrize( - "content_items, expected_number_of_failures, expected_msgs", - [ - ( - [ - create_integration_object( - paths=["script.commands"], - values=[[]], - pack_info={"name": "pack_no_1"}, - ), - create_integration_object( - paths=["script.commands"], - values=[ - [ +def create_content_items_1(repo): + return [ + create_integration_object( + paths=["script.commands"], + values=[[]], + pack_info={"name": "pack_no_1"}, + repo=repo, + ), + create_integration_object( + paths=["script.commands"], + values=[ + [ + { + "name": "ip", + "description": "ip command", + "deprecated": False, + "arguments": [ { - "name": "ip", - "description": "ip command", - "deprecated": False, - "arguments": [ - { - "name": "ip_1", - "default": True, - "isArray": True, - "required": True, - "description": "ip_1_description", - }, - { - "name": "ip_2", - "default": True, - "isArray": True, - "required": True, - "description": "ip_2_description", - }, - ], - "outputs": [], + "name": "ip_1", + "default": True, + "isArray": True, + "required": True, + "description": "ip_1_description", }, - ] - ], - pack_info={"name": "pack_no_2"}, - ), - create_integration_object( - paths=["script.commands"], - values=[ - [ { - "name": "incident_command", - "description": "ip command", - "deprecated": False, - "arguments": [ - { - "name": "incident_arg_no_1", - "default": True, - "isArray": True, - "required": True, - "description": "ip_1_description", - }, - { - "name": "ip_2", - "default": True, - "isArray": True, - "required": True, - "description": "ip_2_description", - }, - ], - "outputs": [], + "name": "ip_2", + "default": True, + "isArray": True, + "required": True, + "description": "ip_2_description", }, - ] - ], - pack_info={"name": "pack_no_3"}, - ), + ], + "outputs": [], + }, + ] ], - 0, - [], + pack_info={"name": "pack_no_2"}, + repo=repo, ), - ( - [ - create_integration_object( - paths=["script.commands"], - values=[ - [ + create_integration_object( + paths=["script.commands"], + values=[ + [ + { + "name": "incident_command", + "description": "ip command", + "deprecated": False, + "arguments": [ + { + "name": "incident_arg_no_1", + "default": True, + "isArray": True, + "required": True, + "description": "ip_1_description", + }, { - "name": "incident_command", - "description": "ip command", - "deprecated": False, - "arguments": [ - { - "name": "incident_arg_no_1", - "default": True, - "isArray": True, - "required": True, - "description": "ip_1_description", - }, - { - "name": "ip_2", - "default": True, - "isArray": True, - "required": True, - "description": "ip_2_description", - }, - ], - "outputs": [], + "name": "ip_2", + "default": True, + "isArray": True, + "required": True, + "description": "ip_2_description", }, - ] - ], - pack_info={"name": "pack_no_4"}, - ) + ], + "outputs": [], + }, + ] + ], + pack_info={"name": "pack_no_3"}, + repo=repo, + ), + ] + + +def create_content_items_2(repo): + return [ + create_integration_object( + paths=["script.commands"], + values=[ + [ + { + "name": "incident_command", + "description": "ip command", + "deprecated": False, + "arguments": [ + { + "name": "incident_arg_no_1", + "default": True, + "isArray": True, + "required": True, + "description": "ip_1_description", + }, + { + "name": "ip_2", + "default": True, + "isArray": True, + "required": True, + "description": "ip_2_description", + }, + ], + "outputs": [], + }, + ] ], + pack_info={"name": "pack_no_4"}, + repo=repo, + ) + ] + + +@pytest.mark.parametrize( + "create_content_items_func, expected_number_of_failures, expected_msgs", + [ + ( + create_content_items_1, + 0, + [], + ), + ( + create_content_items_2, 1, [ "The following commands contain the word 'incident' in one or more of their fields, please remove:\nThe command incident_command contains the word 'incident' in its name and in the following arguments: incident_arg_no_1." @@ -5395,7 +5407,7 @@ def test_IsAPITokenInCredentialTypeValidator_obtain_invalid_content_items__all_i ], ) def test_IsNameContainIncidentInCorePackValidator_obtain_invalid_content_items( - mocker, content_items, expected_number_of_failures, expected_msgs + create_content_items_func, mocker, expected_number_of_failures, expected_msgs ): """ Given @@ -5417,6 +5429,7 @@ def test_IsNameContainIncidentInCorePackValidator_obtain_invalid_content_items( return_value=["pack_no_1", "pack_no_2", "pack_no_4"], ) repo = get_temp_repo() + content_items = create_content_items_func(repo) with ChangeCWD(repo.path): results = ( IsNameContainIncidentInCorePackValidator().obtain_invalid_content_items( diff --git a/demisto_sdk/commands/validate/tests/RM_validators_test.py b/demisto_sdk/commands/validate/tests/RM_validators_test.py index 57fcc05645a..ca4a061c828 100644 --- a/demisto_sdk/commands/validate/tests/RM_validators_test.py +++ b/demisto_sdk/commands/validate/tests/RM_validators_test.py @@ -293,27 +293,27 @@ def create_content_item_2(temp_repo): return [ create_playbook_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png), ", - pack_info={"name": "test1"}, + pack_info={"name": "pack_0"}, repo=temp_repo, ), create_integration_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png)", - pack_info={"name": "test2"}, + pack_info={"name": "pack_1"}, repo=temp_repo, ), create_playbook_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.png ), ", - pack_info={"name": "test3"}, + pack_info={"name": "pack_2"}, repo=temp_repo, ), create_integration_object( readme_content="This is not a valid readme if this file doesn't exists ![example image]( ../doc_files/example.png)", - pack_info={"name": "test4"}, + pack_info={"name": "pack_3"}, repo=temp_repo, ), create_integration_object( readme_content="This is not a valid readme if this file doesn't exists ![example image](../doc_files/example.jpg)", - pack_info={"name": "test5"}, + pack_info={"name": "pack_4"}, repo=temp_repo, ), ] @@ -322,21 +322,21 @@ def create_content_item_2(temp_repo): @pytest.mark.parametrize( "create_content_items_func, doc_files_name, expected_number_of_failures, expected_msgs", [ - # ( - # create_content_items_1, - # [None, "example.png", None, None, "example.png", "example.jpg", None], - # 0, - # [], - # ), + ( + create_content_items_1, + [None, "example.png", None, None, "example.png", "example.jpg", None], + 0, + [], + ), ( create_content_item_2, [None, None, "example.png", "example.png", None], 5, [ - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test1/doc_files/example.png", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test2/doc_files/example.png", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test3/doc_files/example.png ", - "The following images do not exist or have additional characters present in their declaration within the README: Packs/test4/ doc_files/example.png", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/pack_0/doc_files/example.png", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/pack_1/doc_files/example.png", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/pack_2/doc_files/example.png ", + "The following images do not exist or have additional characters present in their declaration within the README: Packs/pack_3/ doc_files/example.png", ], ), ], From a3524559652f7ec6f799196062e7c8b5dd40de90 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 10:59:18 +0200 Subject: [PATCH 53/59] unittests fix --- .../commands/validate/tests/RM_validators_test.py | 8 ++++---- .../commands/validate/tests/validators_test.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/RM_validators_test.py b/demisto_sdk/commands/validate/tests/RM_validators_test.py index ca4a061c828..937072a63c0 100644 --- a/demisto_sdk/commands/validate/tests/RM_validators_test.py +++ b/demisto_sdk/commands/validate/tests/RM_validators_test.py @@ -323,10 +323,10 @@ def create_content_item_2(temp_repo): "create_content_items_func, doc_files_name, expected_number_of_failures, expected_msgs", [ ( - create_content_items_1, - [None, "example.png", None, None, "example.png", "example.jpg", None], - 0, - [], + create_content_items_1, + [None, "example.png", None, None, "example.png", "example.jpg", None], + 0, + [], ), ( create_content_item_2, diff --git a/demisto_sdk/commands/validate/tests/validators_test.py b/demisto_sdk/commands/validate/tests/validators_test.py index eddf07189f0..b80267203fb 100644 --- a/demisto_sdk/commands/validate/tests/validators_test.py +++ b/demisto_sdk/commands/validate/tests/validators_test.py @@ -298,7 +298,9 @@ def test_gather_validations_from_conf( { "validations": [ { - "file path": str(INTEGRATION.path), + "file path": str( + INTEGRATION.path.relative_to(ContentPaths.CONTENT_PATH) + ), "error code": "BA101", "message": "", } @@ -336,14 +338,18 @@ def test_gather_validations_from_conf( { "validations": [ { - "file path": str(INTEGRATION.path), + "file path": str( + INTEGRATION.path.relative_to(ContentPaths.CONTENT_PATH) + ), "error code": "BA101", "message": "", } ], "fixed validations": [ { - "file path": str(INTEGRATION.path), + "file path": str( + INTEGRATION.path.relative_to(ContentPaths.CONTENT_PATH) + ), "error code": "BA101", "message": "Fixed this issue", } From ab7f2c2f336b3c1b73d4e5d8fc7e846c6d90c091 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 14:59:50 +0200 Subject: [PATCH 54/59] unittests fix --- .../validate/tests/validators_test.py | 377 ++++++++++-------- 1 file changed, 212 insertions(+), 165 deletions(-) diff --git a/demisto_sdk/commands/validate/tests/validators_test.py b/demisto_sdk/commands/validate/tests/validators_test.py index b80267203fb..b1ba08e0755 100644 --- a/demisto_sdk/commands/validate/tests/validators_test.py +++ b/demisto_sdk/commands/validate/tests/validators_test.py @@ -31,6 +31,7 @@ create_integration_object, create_pack_object, create_script_object, + get_temp_repo, ) from demisto_sdk.commands.validate.validate_manager import ValidateManager from demisto_sdk.commands.validate.validation_results import ResultWriter @@ -283,97 +284,67 @@ def test_gather_validations_from_conf( assert results.support_level_dict == expected_results.support_level_dict -@pytest.mark.parametrize( - "results, fixing_results, expected_results", - [ - ( - [ - ValidationResult( - validator=IDNameValidator(), - message="", - content_object=INTEGRATION, - ) - ], - [], - { - "validations": [ - { - "file path": str( - INTEGRATION.path.relative_to(ContentPaths.CONTENT_PATH) - ), - "error code": "BA101", - "message": "", - } - ], - "fixed validations": [], - "invalid content items": [], - "Validations that caught exceptions": [], - }, - ), - ( - [], - [], - { - "validations": [], - "fixed validations": [], - "invalid content items": [], - "Validations that caught exceptions": [], - }, - ), - ( - [ - ValidationResult( - validator=IDNameValidator(), - message="", - content_object=INTEGRATION, - ) - ], - [ - FixResult( - validator=IDNameValidator(), - message="Fixed this issue", - content_object=INTEGRATION, - ) - ], +@pytest.fixture +def temp_integration(): + """Fixture to create a temporary integration object for testing.""" + temp_repo = get_temp_repo() + return create_integration_object(repo=temp_repo) + + +def test_write_results_case_1(temp_integration): + """ + Test case 1: One validation result, no fixes. + """ + results = [ + ValidationResult( + validator=IDNameValidator(), + message="", + content_object=temp_integration, + ) + ] + fixing_results = [] + expected_results = { + "validations": [ { - "validations": [ - { - "file path": str( - INTEGRATION.path.relative_to(ContentPaths.CONTENT_PATH) - ), - "error code": "BA101", - "message": "", - } - ], - "fixed validations": [ - { - "file path": str( - INTEGRATION.path.relative_to(ContentPaths.CONTENT_PATH) - ), - "error code": "BA101", - "message": "Fixed this issue", - } - ], - "invalid content items": [], - "Validations that caught exceptions": [], - }, - ), - ], -) -def test_write_results_to_json_file(results, fixing_results, expected_results): + "file path": str( + temp_integration.path.relative_to(ContentPaths.CONTENT_PATH) + ), + "error code": "BA101", + "message": "", + } + ], + "fixed validations": [], + "invalid content items": [], + "Validations that caught exceptions": [], + } + + with tempfile.NamedTemporaryFile( + mode="w", delete=False, suffix=".json" + ) as temp_file: + temp_file_path = temp_file.name + validation_results = ResultWriter(json_file_path=temp_file_path) + validation_results.validation_results = results + validation_results.fixing_results = fixing_results + validation_results.write_results_to_json_file() + + with open(temp_file_path, "r") as file: + loaded_data = json.load(file) + assert loaded_data == expected_results + + +def test_write_results_case_2(temp_integration): """ - Given - results and fixing_results lists. - - Case 1: One validation result. - - Case 2: Both lists are empty. - - Case 3: Both lists has one item. - When - - Calling the write_results_to_json_file function. - Then - - Case 1: Make sure the results hold both list where the fixing results is empty. - - Case 2: Make sure the results hold both list where both are empty. - - Case 3: Make sure the results hold both list where both hold 1 result each. + Test case 2: Empty results and fixing results. """ + results = [] + fixing_results = [] + expected_results = { + "validations": [], + "fixed validations": [], + "invalid content items": [], + "Validations that caught exceptions": [], + } + with tempfile.NamedTemporaryFile( mode="w", delete=False, suffix=".json" ) as temp_file: @@ -382,94 +353,167 @@ def test_write_results_to_json_file(results, fixing_results, expected_results): validation_results.validation_results = results validation_results.fixing_results = fixing_results validation_results.write_results_to_json_file() + with open(temp_file_path, "r") as file: loaded_data = json.load(file) assert loaded_data == expected_results -@pytest.mark.parametrize( - "only_throw_warnings, results, expected_exit_code, expected_warnings_call_count, expected_error_call_count, expected_error_code_in_warnings, expected_error_code_in_errors", - [ - ( - ["BA101"], - [ - ValidationResult( - validator=IDNameValidator(), - message="", - content_object=INTEGRATION, - ) - ], - 0, - 1, - 0, - ["BA101"], - [], - ), - ( - [], - [ - ValidationResult( - validator=IDNameValidator(), - message="", - content_object=INTEGRATION, - ) - ], - 1, - 0, - 1, - [], - ["BA101"], - ), - ( - ["BC100"], - [ - ValidationResult( - validator=IDNameValidator(), - message="", - content_object=INTEGRATION, +def test_write_results_case_3(temp_integration): + """ + Test case 3: One validation result and one fix result. + """ + results = [ + ValidationResult( + validator=IDNameValidator(), + message="", + content_object=temp_integration, + ) + ] + fixing_results = [ + FixResult( + validator=IDNameValidator(), + message="Fixed this issue", + content_object=temp_integration, + ) + ] + expected_results = { + "validations": [ + { + "file path": str( + temp_integration.path.relative_to(ContentPaths.CONTENT_PATH) ), - ValidationResult( - validator=BreakingBackwardsSubtypeValidator(), - message="", - content_object=INTEGRATION, + "error code": "BA101", + "message": "", + } + ], + "fixed validations": [ + { + "file path": str( + temp_integration.path.relative_to(ContentPaths.CONTENT_PATH) ), - ], - 1, - 1, - 1, - ["BC100"], - ["BA101"], - ), - ], -) -def test_post_results( - mocker, - only_throw_warnings, - results, - expected_exit_code, - expected_warnings_call_count, - expected_error_call_count, - expected_error_code_in_warnings, - expected_error_code_in_errors, - caplog, -): + "error code": "BA101", + "message": "Fixed this issue", + } + ], + "invalid content items": [], + "Validations that caught exceptions": [], + } + + with tempfile.NamedTemporaryFile( + mode="w", delete=False, suffix=".json" + ) as temp_file: + temp_file_path = temp_file.name + validation_results = ResultWriter(json_file_path=temp_file_path) + validation_results.validation_results = results + validation_results.fixing_results = fixing_results + validation_results.write_results_to_json_file() + + with open(temp_file_path, "r") as file: + loaded_data = json.load(file) + assert loaded_data == expected_results + + +def test_post_results_case_1(temp_integration, caplog): """ - Given - an only_throw_warnings list, and a list of results. - - Case 1: One failed validation with its error_code in the only_throw_warnings list. - - Case 2: One failed validation with its error_code not in the only_throw_warnings list. - - Case 3: One failed validation with its error_code in the only_throw_warnings list and one failed validation with its error_code not in the only_throw_warnings list. - When - - Calling the post_results function. - Then - - Make sure the error and warning loggers was called the correct number of times with the right error codes, and that the exit code was calculated correctly. - - Case 1: Make sure the exit_code is 0 (success), and that the warning logger was called once with 'BA101' and the error logger wasn't called. - - Case 2: Make sure the exit_code is 1 (failure), and that the error logger was called once with 'BA101' and the warning logger wasn't called. - - Case 3: Make sure the exit_code is 1 (failure), and that the error logger was called once with 'BA101' and the warning logger was called once with 'BC100' + Case 1: One failed validation with its error_code in the only_throw_warnings list. """ + only_throw_warnings = ["BA101"] + results = [ + ValidationResult( + validator=IDNameValidator(), + message="", + content_object=temp_integration, + ) + ] + expected_exit_code = 0 + expected_warnings_call_count = 1 + expected_error_call_count = 0 + expected_error_code_in_warnings = ["BA101"] + expected_error_code_in_errors = [] + validation_results = ResultWriter() validation_results.validation_results = results exit_code = validation_results.post_results(only_throw_warning=only_throw_warnings) + + assert exit_code == expected_exit_code + + log_by_level = map_reduce(caplog.records, lambda log: log.levelno) + warnings = log_by_level.get(30, ()) + assert len(warnings) == expected_warnings_call_count + for code in expected_error_code_in_warnings: + assert code in " ".join({log.message for log in warnings}) + + errors = log_by_level.get(40, ()) + assert len(errors) == expected_error_call_count + for code in expected_error_code_in_errors: + assert code in " ".join({log.message for log in errors}) + + +def test_post_results_case_2(temp_integration, caplog): + """ + Case 2: One failed validation with its error_code not in the only_throw_warnings list. + """ + only_throw_warnings = [] + results = [ + ValidationResult( + validator=IDNameValidator(), + message="", + content_object=temp_integration, + ) + ] + expected_exit_code = 1 + expected_warnings_call_count = 0 + expected_error_call_count = 1 + expected_error_code_in_warnings = [] + expected_error_code_in_errors = ["BA101"] + + validation_results = ResultWriter() + validation_results.validation_results = results + exit_code = validation_results.post_results(only_throw_warning=only_throw_warnings) + + assert exit_code == expected_exit_code + + log_by_level = map_reduce(caplog.records, lambda log: log.levelno) + warnings = log_by_level.get(30, ()) + assert len(warnings) == expected_warnings_call_count + for code in expected_error_code_in_warnings: + assert code in " ".join({log.message for log in warnings}) + + errors = log_by_level.get(40, ()) + assert len(errors) == expected_error_call_count + for code in expected_error_code_in_errors: + assert code in " ".join({log.message for log in errors}) + + +def test_post_results_case_3(temp_integration, caplog): + """ + Case 3: One failed validation with its error_code in the only_throw_warnings list + and one failed validation with its error_code not in the only_throw_warnings list. + """ + only_throw_warnings = ["BC100"] + results = [ + ValidationResult( + validator=IDNameValidator(), + message="", + content_object=temp_integration, + ), + ValidationResult( + validator=BreakingBackwardsSubtypeValidator(), + message="", + content_object=temp_integration, + ), + ] + expected_exit_code = 1 + expected_warnings_call_count = 1 + expected_error_call_count = 1 + expected_error_code_in_warnings = ["BC100"] + expected_error_code_in_errors = ["BA101"] + + validation_results = ResultWriter() + validation_results.validation_results = results + exit_code = validation_results.post_results(only_throw_warning=only_throw_warnings) + assert exit_code == expected_exit_code log_by_level = map_reduce(caplog.records, lambda log: log.levelno) @@ -508,7 +552,10 @@ def test_should_run(validator, expected_results): - Case 3: Should return False. """ assert expected_results == validator.should_run( - INTEGRATION, [], {}, running_execution_mode=ExecutionMode.USE_GIT + create_integration_object(), + [], + {}, + running_execution_mode=ExecutionMode.USE_GIT, ) From d51262227b8279fdbb79fc401f9c0b186c4a0fe3 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 16:09:09 +0200 Subject: [PATCH 55/59] setting content path for a test repo instance's lifetime only --- TestSuite/repo.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TestSuite/repo.py b/TestSuite/repo.py index eb28aedbf7f..39651435406 100644 --- a/TestSuite/repo.py +++ b/TestSuite/repo.py @@ -44,6 +44,8 @@ def __init__(self, tmpdir: Path, init_git: bool = False): self._packs_path: Path = tmpdir / "Packs" self._packs_path.mkdir() self.path = str(self._tmpdir) + # Update global content's path for the lifetime of this instance. + self.old_content_path = ContentPaths.CONTENT_PATH ContentPaths.update_content_path(self.path) # Initiate ./Tests/ dir @@ -101,6 +103,9 @@ def __del__(self): if self.graph_interface: self.graph_interface.close() + # Restore original content path. + ContentPaths.update_content_path(self.old_content_path) + def setup_one_pack( self, name: Optional[str] = None, marketplaces: List[str] = DEFAULT_MARKETPLACES ) -> Pack: From 86e294e1c5ab3a9e43fe0eebcd1d5887107094da Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 17:20:34 +0200 Subject: [PATCH 56/59] test fixes --- .../content_graph/tests/create_content_graph_test.py | 8 +++++++- .../content_graph/tests/format_with_graph_test.py | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py index e568cfa3747..551727afc38 100644 --- a/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/create_content_graph_test.py @@ -42,6 +42,9 @@ def repository(mocker, tmp_path: Path): content_temp_dir = tmp_path / "content" content_temp_dir.mkdir() + + # Using this content path for a test's lifetime only and restoring when terminated. + old_content_path = ContentPaths.CONTENT_PATH ContentPaths.update_content_path(content_temp_dir) repository = ContentDTO( @@ -51,7 +54,10 @@ def repository(mocker, tmp_path: Path): "demisto_sdk.commands.content_graph.content_graph_builder.ContentGraphBuilder._create_content_dto", return_value=repository, ) - return repository + yield repository + + # Cleanup and content path restoration. + ContentPaths.update_content_path(old_content_path) def mock_pack( diff --git a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py index dec0e547e2a..2fd02772046 100644 --- a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py @@ -302,7 +302,7 @@ def mock__create_content_dto(packs_to_update: List[str]) -> ContentDTO: return repository -def test_format_mapper_with_graph_remove_unknown_content(mocker, repository, repo): +def test_format_mapper_with_graph_remove_unknown_content(mocker, repository): """ Given - A mapper. @@ -326,7 +326,7 @@ def test_format_mapper_with_graph_remove_unknown_content(mocker, repository, rep "demisto_sdk.commands.format.format_module.update_content_graph", return_value=interface, ) - with ChangeCWD(repo.path): + with ChangeCWD(repository.path): runner = CliRunner() result = runner.invoke( main, @@ -357,7 +357,7 @@ def test_format_mapper_with_graph_remove_unknown_content(mocker, repository, rep ) -def test_format_layout_with_graph_remove_unknown_content(mocker, repository, repo): +def test_format_layout_with_graph_remove_unknown_content(mocker, repository): """ Given - A layout. @@ -381,7 +381,7 @@ def test_format_layout_with_graph_remove_unknown_content(mocker, repository, rep "demisto_sdk.commands.format.format_module.update_content_graph", return_value=interface, ) - with ChangeCWD(repo.path): + with ChangeCWD(repository.path): runner = CliRunner() result = runner.invoke( main, [FORMAT_CMD, "-i", layout_path, "-at", "-y", "-nv"] @@ -418,7 +418,7 @@ def test_format_layout_with_graph_remove_unknown_content(mocker, repository, rep def test_format_incident_field_graph_fix_aliases_marketplace( - mocker, monkeypatch, repository, repo + mocker, monkeypatch, repository ): """ Given @@ -450,7 +450,7 @@ def test_format_incident_field_graph_fix_aliases_marketplace( "demisto_sdk.commands.format.format_module.update_content_graph", return_value=interface, ) - with ChangeCWD(repo.path): + with ChangeCWD(repository.path): runner = CliRunner() result = runner.invoke( main, [FORMAT_CMD, "-i", original_incident_field_path, "-at", "-y", "-nv"] From aa717631c5a7fd3bd241e43b39c79defffda4073 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 17:58:05 +0200 Subject: [PATCH 57/59] setting content path for a test repo instance's lifetime only --- .../tests/format_with_graph_test.py | 12 ++++++-- .../tests/generate_docs_script_test.py | 12 ++++++-- .../tests/graph_validator_test.py | 18 ++++++++++-- .../tests/pack_metadata_graph_test.py | 10 +++++-- .../tests/prepare_content_graph_test.py | 12 ++++++-- .../tests/update_content_graph_test.py | 28 +++++++++++++++---- .../init/tests/contribution_converter_test.py | 20 ++++++++++--- 7 files changed, 92 insertions(+), 20 deletions(-) diff --git a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py index 2fd02772046..2c4999d697f 100644 --- a/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/format_with_graph_test.py @@ -36,10 +36,13 @@ @pytest.fixture(autouse=True) def setup_method(mocker, tmp_path_factory, repo: Repo): """Auto-used fixture for setup before every test run""" - import demisto_sdk.commands.content_graph.objects.base_content as bc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.files.file import File - bc.ContentPaths.update_content_path(Path(repo.path)) + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(Path(repo.path)) + mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) @@ -57,6 +60,11 @@ def setup_method(mocker, tmp_path_factory, repo: Repo): }, ) + yield + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + @pytest.fixture def repository(mocker, repo) -> ContentDTO: diff --git a/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py b/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py index 4fcd277b7eb..b680b43cfe7 100644 --- a/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py +++ b/demisto_sdk/commands/content_graph/tests/generate_docs_script_test.py @@ -35,14 +35,22 @@ @pytest.fixture(autouse=True) def setup_method(mocker, tmp_path_factory, repo: Repo): """Auto-used fixture for setup before every test run""" - import demisto_sdk.commands.content_graph.objects.base_content as bc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths + + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(Path(repo.path)) - bc.ContentPaths.update_content_path(Path(repo.path)) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) mocker.patch.object(ContentGraphInterface, "repo_path", Path(repo.path)) + yield + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + @pytest.fixture def repository(mocker, repo) -> ContentDTO: diff --git a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py index f9196f8ceef..8d48383833c 100644 --- a/demisto_sdk/commands/content_graph/tests/graph_validator_test.py +++ b/demisto_sdk/commands/content_graph/tests/graph_validator_test.py @@ -41,10 +41,12 @@ @pytest.fixture(autouse=True) def setup_method(mocker, tmp_path_factory): """Auto-used fixture for setup before every test run""" - import demisto_sdk.commands.content_graph.objects.base_content as bc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.files.file import File - bc.ContentPaths.update_content_path(GIT_PATH) + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(GIT_PATH) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) @@ -63,6 +65,11 @@ def setup_method(mocker, tmp_path_factory): }, ) + yield + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + def mk_content_dir(repo_path: Path): if repo_path.exists(): @@ -72,6 +79,8 @@ def mk_content_dir(repo_path: Path): @pytest.fixture def repository(mocker) -> ContentDTO: + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH repo_path = ContentPaths.CONTENT_PATH.with_name("content") mk_content_dir(repo_path) ContentPaths.update_content_path(repo_path) @@ -385,7 +394,10 @@ def repository(mocker) -> ContentDTO: "demisto_sdk.commands.content_graph.content_graph_builder.ContentGraphBuilder._create_content_dto", return_value=repository, ) - return repository + yield repository + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) # HELPERS diff --git a/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py b/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py index 75c4647e46f..3d896aa1b28 100644 --- a/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/pack_metadata_graph_test.py @@ -26,14 +26,20 @@ @pytest.fixture(autouse=True) def setup_method(mocker, tmp_path_factory, repo: Repo): """Auto-used fixture for setup before every test run""" - import demisto_sdk.commands.content_graph.objects.base_content as bc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths - bc.ContentPaths.update_content_path(Path(repo.path)) + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(Path(repo.path)) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) mocker.patch.object(ContentGraphInterface, "repo_path", Path(repo.path)) + yield + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + @pytest.fixture def repository(mocker): diff --git a/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py index 38767b57b91..a12d0f04125 100644 --- a/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/prepare_content_graph_test.py @@ -34,10 +34,13 @@ @pytest.fixture(autouse=True) def setup_method(mocker, tmp_path_factory, repo: Repo): """Auto-used fixture for setup before every test run""" - import demisto_sdk.commands.content_graph.objects.base_content as bc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.files.file import File - bc.ContentPaths.update_content_path(Path(repo.path)) + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(Path(repo.path)) + mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) @@ -55,6 +58,11 @@ def setup_method(mocker, tmp_path_factory, repo: Repo): }, ) + yield + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + @pytest.fixture def repository(mocker): diff --git a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py index 34c2fde7e56..0c463a0f6b3 100644 --- a/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py +++ b/demisto_sdk/commands/content_graph/tests/update_content_graph_test.py @@ -44,12 +44,13 @@ @pytest.fixture(autouse=True) def setup_method(mocker, tmp_path_factory): """Auto-used fixture for setup before every test run""" - import demisto_sdk.commands.content_graph.objects.base_content as bc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.files.file import File from_path.cache_clear() - - bc.ContentPaths.update_content_path(GIT_PATH) + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(GIT_PATH) mocker.patch.object( neo4j_service, "NEO4J_DIR", new=tmp_path_factory.mktemp("neo4j") ) @@ -67,6 +68,11 @@ def setup_method(mocker, tmp_path_factory): }, ) + yield + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + def mk_content_dir(repo_path: Path): if repo_path.exists(): @@ -76,9 +82,12 @@ def mk_content_dir(repo_path: Path): @pytest.fixture def repository(mocker) -> ContentDTO: + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH repo_path = ContentPaths.CONTENT_PATH.with_name("content") mk_content_dir(repo_path) ContentPaths.update_content_path(repo_path) + repository = ContentDTO( path=repo_path, packs=[], @@ -213,11 +222,17 @@ def mock__create_content_dto(packs_to_update: List[str]) -> ContentDTO: "demisto_sdk.commands.content_graph.content_graph_builder.ContentGraphBuilder._create_content_dto", side_effect=mock__create_content_dto, ) - return repository + yield repository + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) @pytest.fixture def external_repository(mocker, tmp_path: Path) -> ContentDTO: + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + content_temp_dir = tmp_path / "content" content_temp_dir.mkdir() ContentPaths.update_content_path(content_temp_dir) @@ -252,7 +267,10 @@ def mock__create_content_dto(packs_to_update: List[str]) -> ContentDTO: "demisto_sdk.commands.content_graph.content_graph_builder.ContentGraphBuilder._create_content_dto", side_effect=mock__create_content_dto, ) - return repository + yield repository + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) # HELPERS diff --git a/demisto_sdk/commands/init/tests/contribution_converter_test.py b/demisto_sdk/commands/init/tests/contribution_converter_test.py index 1e4f92f8ca6..88d8e612fda 100644 --- a/demisto_sdk/commands/init/tests/contribution_converter_test.py +++ b/demisto_sdk/commands/init/tests/contribution_converter_test.py @@ -1278,9 +1278,11 @@ def test_process_existing_pack_existing_integration_readme( - The integration README should be updated with the new command. """ - import demisto_sdk.commands.init.contribution_converter as cc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths - cc.ContentPaths.update_content_path(git_repo.path) + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(git_repo.path) # Read integration python, yml code and README to create mock integration py_code_path = Path(CONTRIBUTION_TESTS, "common", "integration.py") @@ -1390,6 +1392,11 @@ def test_process_existing_pack_existing_integration_readme( assert actual_integration_python.read_text() != py_code assert "helloworld-new-cmd" in actual_integration_python.read_text() + yield + + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + def test_process_existing_pack_new_integration_readme( self, tmp_path: Path, git_repo: Repo, mocker: MockerFixture ): @@ -1410,9 +1417,11 @@ def test_process_existing_pack_new_integration_readme( - A new Integration README should be generated. """ - import demisto_sdk.commands.init.contribution_converter as cc + from demisto_sdk.commands.common.content_constant_paths import ContentPaths - cc.ContentPaths.update_content_path(git_repo.path) + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + ContentPaths.update_content_path(git_repo.path) git_repo.create_pack(self.existing_pack_name) @@ -1445,6 +1454,9 @@ def test_process_existing_pack_new_integration_readme( generated_readme = Path(contrib_converter.readme_files[0]) assert not generated_readme.exists() + # Restore the original content path after the test has terminated. + ContentPaths.update_content_path(old_content_path) + def test_process_new_pack( self, tmp_path: Path, git_repo: Repo, mocker: MockerFixture ): From f990a64d0b306ee722872dc812f2721db6cf29c1 Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 18:24:43 +0200 Subject: [PATCH 58/59] fix integration tests --- .../integration_tests/format_integration_test.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/demisto_sdk/tests/integration_tests/format_integration_test.py b/demisto_sdk/tests/integration_tests/format_integration_test.py index 0386d4665cb..ae213de65b9 100644 --- a/demisto_sdk/tests/integration_tests/format_integration_test.py +++ b/demisto_sdk/tests/integration_tests/format_integration_test.py @@ -10,6 +10,7 @@ GENERAL_DEFAULT_FROMVERSION, ) from demisto_sdk.commands.common.content.content import Content +from demisto_sdk.commands.common.content_constant_paths import ContentPaths from demisto_sdk.commands.common.git_util import GitUtil from demisto_sdk.commands.common.handlers import DEFAULT_JSON_HANDLER as json from demisto_sdk.commands.common.handlers import DEFAULT_YAML_HANDLER as yaml @@ -1939,16 +1940,17 @@ def test_verify_deletion_from_conf_pack_format_with_deprecate_flag( Then - Ensure deletion from test.conf """ + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + repo_path = repo.path + ContentPaths.update_content_path(repo_path) - # Prepare mockers - - # Prepare content # Create pack with integration and with test playbook in the yml. pack = repo.create_pack("TestPack") integration = pack.create_integration("TestIntegration") integration.yml.update({"tests": ["test_playbook"]}) pack_path = pack.path - repo_path = repo.path + # We don't need to format empty readme files Path(f"{repo_path}/Packs/TestPack/Integrations/TestIntegration/README.md").unlink( missing_ok=True @@ -1998,6 +2000,9 @@ def test_verify_deletion_from_conf_pack_format_with_deprecate_flag( } ] + # Restore the original content path. + ContentPaths.update_content_path(old_content_path) + def test_verify_deletion_from_conf_script_format_with_deprecate_flag( mocker, monkeypatch, repo From 7a590c51512cad3238e25110338e44a7028e3d9c Mon Sep 17 00:00:00 2001 From: barryyosi-panw Date: Sun, 24 Nov 2024 18:32:51 +0200 Subject: [PATCH 59/59] fix integration tests --- .../tests/integration_tests/format_integration_test.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/demisto_sdk/tests/integration_tests/format_integration_test.py b/demisto_sdk/tests/integration_tests/format_integration_test.py index ae213de65b9..97bf33d6eb9 100644 --- a/demisto_sdk/tests/integration_tests/format_integration_test.py +++ b/demisto_sdk/tests/integration_tests/format_integration_test.py @@ -2018,7 +2018,10 @@ def test_verify_deletion_from_conf_script_format_with_deprecate_flag( - Ensure deletion from test.conf """ - # Prepare mockers + # Save the current content path and update it for the lifetime of the test. + old_content_path = ContentPaths.CONTENT_PATH + repo_path = repo.path + ContentPaths.update_content_path(repo_path) # Prepare content # Create pack with script and with test playbook in the yml. @@ -2026,7 +2029,6 @@ def test_verify_deletion_from_conf_script_format_with_deprecate_flag( script = pack.create_script("TestScript") script.yml.update({"tests": ["test_playbook_for_script"]}) script_path = script.path - repo_path = repo.path # We don't need to format empty readme files Path(f"{repo_path}/Packs/TestPack/Scripts/TestScript/README.md").unlink( @@ -2064,6 +2066,9 @@ def test_verify_deletion_from_conf_script_format_with_deprecate_flag( {"scripts": ["AnotherTestScript"], "playbookID": "test_playbook_for_script"}, ] + # Restore the original content path. + ContentPaths.update_content_path(old_content_path) + def test_format_incident_field_with_no_graph(mocker, monkeypatch, repo): """