from demisto_sdk.commands.common.constants import PACKS_DIR, PLAYBOOKS_DIR from demisto_sdk.commands.common.content.objects.pack_objects import Playbook from demisto_sdk.commands.common.content.objects_factory import \ path_to_pack_object from demisto_sdk.commands.common.tools import src_root TEST_DATA = src_root() / 'tests' / 'test_files' TEST_CONTENT_REPO = TEST_DATA / 'content_slim' PLAYBOOK = TEST_CONTENT_REPO / PACKS_DIR / 'Sample01' / PLAYBOOKS_DIR / 'playbook-sample_new.yml' def test_objects_factory(): obj = path_to_pack_object(PLAYBOOK) assert isinstance(obj, Playbook) def test_prefix(): obj = Playbook(PLAYBOOK) assert obj.normalize_file_name() == PLAYBOOK.name
from pathlib import Path from shutil import rmtree import click import pytest from demisto_sdk.__main__ import xsoar_config_file_update from demisto_sdk.commands.common.handlers import JSON_Handler from demisto_sdk.commands.common.tools import src_root from demisto_sdk.commands.update_xsoar_config_file.update_xsoar_config_file import \ XSOARConfigFileUpdater json = JSON_Handler() UNIT_TEST_DATA = (src_root() / 'commands' / 'update_xsoar_config_file' / 'tests' / 'data') @contextmanager def temp_dir(): """Create Temp directory for test. Open: - Create temp directory. Close: - Delete temp directory. """ temp = UNIT_TEST_DATA / 'temp' try: temp.mkdir(parents=True, exist_ok=True)
from contextlib import contextmanager from filecmp import cmp, dircmp from pathlib import Path from shutil import copyfile, copytree, rmtree import pytest from demisto_sdk.commands.common.constants import PACKS_DIR, TEST_PLAYBOOKS_DIR from demisto_sdk.commands.common.logger import logging_setup from demisto_sdk.commands.common.tools import src_root from TestSuite.test_tools import ChangeCWD TEST_DATA = src_root() / 'tests' / 'test_files' TEST_CONTENT_REPO = TEST_DATA / 'content_slim' TEST_PRIVATE_CONTENT_REPO = TEST_DATA / 'private_content_slim' UNIT_TEST_DATA = (src_root() / 'commands' / 'create_artifacts' / 'tests' / 'data') COMMON_SERVER = UNIT_TEST_DATA / 'common_server' ARTIFACTS_EXPECTED_RESULTS = TEST_DATA / 'artifacts' def same_folders(src1, src2): """Assert if folder contains different files""" dcmp = dircmp(src1, src2) if dcmp.left_only or dcmp.right_only: return False for sub_dcmp in dcmp.subdirs.values(): same_folders(sub_dcmp.left, sub_dcmp.right) return True
expected_failed_uploaded_files_title = '\nNOT UPLOADED DUE TO VERSION MISMATCH:' expected_failed_uploaded_files = """╒════════════════╤════════╤═════════════════╤═════════════════════╤═══════════════════╕ │ NAME │ TYPE │ XSOAR Version │ FILE_FROM_VERSION │ FILE_TO_VERSION │ ╞════════════════╪════════╪═════════════════╪═════════════════════╪═══════════════════╡ │ SomeScriptName │ Script │ 6.0.0 │ 0.0.0 │ 5.0.0 │ ╘════════════════╧════════╧═════════════════╧═════════════════════╧═══════════════════╛ """ # verify exactly 3 calls to print_color assert secho.call_count == 3 assert secho.call_args_list[0][0][0] == expected_upload_summary_title assert secho.call_args_list[1][0][ 0] == expected_failed_uploaded_files_title assert secho.call_args_list[2][0][0] == expected_failed_uploaded_files TEST_DATA = src_root() / 'commands' / 'upload' / 'tests' / 'data' CONTENT_PACKS_ZIP = str(TEST_DATA / 'content_packs.zip') TEST_PACK_ZIP = str(TEST_DATA / 'TestPack.zip') TEST_PACK = 'Packs/TestPack' INVALID_ZIP = 'invalid_zip' INVALID_ZIP_ERROR = 'Error: Given input path: {path} does not exist' API_CLIENT = DefaultApi() def mock_api_client(mocker): mocker.patch.object(demisto_client, 'configure', return_value=API_CLIENT) mocker.patch.object(uploader, 'get_demisto_version', return_value=parse('6.0.0'))
from pathlib import Path from shutil import rmtree, unpack_archive import click import demisto_client import pytest from demisto_client.demisto_api import DefaultApi from packaging.version import parse from demisto_sdk.__main__ import zip_packs from demisto_sdk.commands.common.tools import src_root from demisto_sdk.commands.upload import uploader from demisto_sdk.commands.upload.uploader import Uploader from demisto_sdk.tests.constants_test import PACK_TARGET UNIT_TEST_DATA = (src_root() / 'commands' / 'zip_packs' / 'tests' / 'data') TEST_PACK_PATH = Path(PACK_TARGET) @contextmanager def temp_dir(): """Create Temp directory for test. Open: - Create temp directory. Close: - Delete temp directory. """ temp = UNIT_TEST_DATA / 'temp' try: