Example #1
0
def test_extract_code():
    from demisto_sdk.commands.split_yml.extractor import Extractor
    configuration = Configuration()
    with patch.object(Extractor, '__init__', lambda a, b, c, d, e, f, g: None):
        extractor = Extractor('', '', False, False, '', configuration)
        extractor.yml_type = ''
        extractor.common_server = True
        extractor.demisto_mock = True
        extractor.yml_path = f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml'
        extractor.extract_code(
            f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt')
        with open(f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt',
                  'rb') as temp_file:
            file_data = temp_file.read().decode('utf-8')
            assert 'import demistomock as demisto\n' in file_data
            assert 'from CommonServerPython import *\n' in file_data
            assert file_data[-1] == '\n'
        os.remove(f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt')
        extractor.common_server = False
        extractor.demisto_mock = False
        extractor.extract_code(
            f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt')
        with open(f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt',
                  'rb') as temp_file:
            file_data = temp_file.read().decode('utf-8')
            assert 'import demistomock as demisto\n' not in file_data
            assert 'from CommonServerPython import *\n' not in file_data
            assert file_data[-1] == '\n'
        os.remove(f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt')
Example #2
0
 def __init__(self,
              input: str,
              output: str,
              file_type: str,
              no_demisto_mock: bool = False,
              no_common_server: bool = False,
              no_auto_create_dir: bool = False,
              configuration: Configuration = None,
              base_name: str = '',
              no_readme: bool = False,
              no_pipenv: bool = False,
              no_changelog: bool = False,
              no_logging: bool = False):
     self.input = input
     self.output = output
     self.demisto_mock = not no_demisto_mock
     self.common_server = not no_common_server
     self.file_type = file_type
     self.base_name = base_name
     self.readme = not no_readme
     self.pipenv = not no_pipenv
     self.changelog = not no_changelog
     self.logging = not no_logging
     if configuration is None:
         self.config = Configuration()
     else:
         self.config = configuration
     self.autocreate_dir = not no_auto_create_dir
     with open(self.input, 'rb') as yml_file:
         self.yml_data = yaml.safe_load(yml_file)
Example #3
0
    def __init__(self,
                 is_backward_check=True,
                 prev_ver=None,
                 use_git=False,
                 is_circle=False,
                 print_ignored_files=False,
                 validate_conf_json=True,
                 validate_id_set=False,
                 file_path=None,
                 validate_all=False,
                 configuration=Configuration()):
        self.validate_all = validate_all
        self.branch_name = ''
        self.use_git = use_git
        if self.use_git:
            print('Using git')
            self.branch_name = self.get_current_working_branch()
            print(f'Running validation on branch {self.branch_name}')

        self.prev_ver = prev_ver
        self._is_valid = True
        self.configuration = configuration
        self.is_backward_check = is_backward_check
        self.is_circle = is_circle
        self.print_ignored_files = print_ignored_files
        self.validate_conf_json = validate_conf_json
        self.validate_id_set = validate_id_set
        self.file_path = file_path

        if self.validate_conf_json:
            self.conf_json_validator = ConfJsonValidator()
        if self.validate_id_set:
            self.id_set_validator = IDSetValidator(
                is_circle=self.is_circle, configuration=self.configuration)
Example #4
0
 def __init__(self,
              is_test_run=False,
              is_circle=False,
              configuration=Configuration(),
              ignored_errors=None,
              print_as_warnings=False,
              suppress_print=False,
              id_set_file=None,
              json_file_path=None):
     super().__init__(ignored_errors=ignored_errors,
                      print_as_warnings=print_as_warnings,
                      suppress_print=suppress_print,
                      json_file_path=json_file_path)
     self.is_circle = is_circle
     self.configuration = configuration
     if not is_test_run and self.is_circle:
         self.id_set_file = id_set_file
         self.script_set = self.id_set_file[self.SCRIPTS_SECTION]
         self.playbook_set = self.id_set_file[self.PLAYBOOK_SECTION]
         self.integration_set = self.id_set_file[self.INTEGRATION_SECTION]
         self.test_playbook_set = self.id_set_file[
             self.TEST_PLAYBOOK_SECTION]
         self.classifiers_set = self.id_set_file[self.CLASSIFIERS_SECTION]
         self.layouts_set = self.id_set_file[self.LAYOUTS_SECTION]
         self.mappers_set = self.id_set_file[self.MAPPERS_SECTION]
         self.incident_types_set = self.id_set_file[
             self.INCIDENT_TYPES_SECTION]
Example #5
0
    def __init__(self,
                 name: str = '',
                 contribution: Union[str] = None,
                 description: str = '',
                 author: str = '',
                 gh_user: str = '',
                 create_new: bool = True,
                 pack_dir_name: Union[str] = None,
                 update_type: str = '',
                 release_notes: str = '',
                 detected_content_items: list = None,
                 base_dir: Union[str] = None,
                 no_pipenv: bool = False):
        """Initializes a ContributionConverter instance

        Note that when recieving a contribution that is an update to an existing pack that the values of 'name',
        'description' and 'author' will be those of the existing pack.

        Args:
            name (str, optional): The name of the pack. Defaults to ''.
            contribution (Union[str], optional): The path to the contribution zipfile. Defaults to None.
            description (str, optional): The description for the contribution. Defaults to ''.
            author (str, optional): The author of the contribution. Defaults to ''.
            gh_user (str, optional): The github username of the person contributing. Defaults to ''.
            create_new (bool, optional): Whether the contribution is intended as a new pack. When the contribution is
                intended as an update to an existing pack, the value passed should be False. Defaults to True.
            pack_dir_name (Union[str], optional): Explicitly pass the name of the pack directory. Only useful when
                updating an existing pack and the pack's directory is not equivalent to the value returned from
                running `self.format_pack_dir_name(name)`
            base_dir (Union[str], optional): Used to explicitly pass the path to the top-level directory of the
                local content repo. If no value is passed, the `get_content_path()` function is used to determine
                the path. Defaults to None.

        """
        self.configuration = Configuration()
        self.contribution = contribution
        self.description = description
        self.author = author
        self.update_type = update_type or 'revision'
        self.release_notes = release_notes
        self.detected_content_items = detected_content_items or []
        self.gh_user = gh_user
        self.contrib_conversion_errs: List[str] = []
        self.create_new = create_new
        self.no_pipenv = no_pipenv
        base_dir = base_dir or get_content_path()
        self.packs_dir_path = os.path.join(base_dir, 'Packs')
        if not os.path.isdir(self.packs_dir_path):
            os.makedirs(self.packs_dir_path)

        self.name = name
        self.dir_name = pack_dir_name or ContributionConverter.format_pack_dir_name(
            name)
        if create_new:
            # make sure that it doesn't conflict with an existing pack directory
            self.dir_name = self.ensure_unique_pack_dir_name(self.dir_name)
        self.pack_dir_path = os.path.join(self.packs_dir_path, self.dir_name)
        if not os.path.isdir(self.pack_dir_path):
            os.makedirs(self.pack_dir_path)
        self.readme_files: List[str] = []
Example #6
0
    def __init__(self, output: str, name: str = '', id: str = '', integration: bool = False, template: str = '',
                 script: bool = False, pack: bool = False, demisto_mock: bool = False, common_server: bool = False):
        self.output = output if output else ''
        self.id = id

        self.is_integration = integration
        self.is_script = script
        self.is_pack = pack
        self.demisto_mock = demisto_mock
        self.common_server = common_server
        self.configuration = Configuration()

        # if no flag given automatically create a pack.
        if not integration and not script and not pack:
            self.is_pack = True

        self.template = self.get_selected_template(template)

        self.full_output_path = ''

        while ' ' in name:
            name = str(input("The directory and file name cannot have spaces in it, Enter a different name: "))

        self.dir_name = name

        self.is_pack_creation = not all([self.is_script, self.is_integration])
Example #7
0
def test_extract_code():
    from demisto_sdk.commands.split_yml.extractor import Extractor
    extractor = Extractor(
        input=f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml',
        output=f'{git_path()}/demisto_sdk/tests/test_files/temp_code.txt',
        file_type='integration',
        no_demisto_mock=False,
        no_common_server=False,
        configuration=Configuration())

    extractor.extract_code(extractor.output)
    with open(extractor.output, 'rb') as temp_code:
        file_data = temp_code.read().decode('utf-8')
        assert 'import demistomock as demisto\n' in file_data
        assert 'from CommonServerPython import *\n' in file_data
        assert file_data[-1] == '\n'
    os.remove(extractor.output)

    extractor.common_server = False
    extractor.demisto_mock = False
    extractor.extract_code(extractor.output)
    with open(extractor.output, 'rb') as temp_code:
        file_data = temp_code.read().decode('utf-8')
        assert 'import demistomock as demisto\n' not in file_data
        assert 'from CommonServerPython import *\n' not in file_data
        assert file_data[-1] == '\n'
    os.remove(extractor.output)
Example #8
0
    def __init__(self, file_path, is_new_file=False, old_file_path=None, predefined_scheme=None, fromversion=False,
                 configuration=Configuration(), ignored_errors=None, print_as_warnings=False, tag='master',
                 suppress_print: bool = False, branch_name='', json_file_path=None, skip_schema_check=False,
                 pykwalify_logs=False, quiet_bc=False):
        super().__init__(ignored_errors=ignored_errors, print_as_warnings=print_as_warnings,
                         suppress_print=suppress_print, json_file_path=json_file_path)
        self.is_valid = True
        self.valid_extensions = ['.yml', '.json', '.md', '.png']
        self.file_path = file_path.replace('\\', '/')
        self.skip_schema_check = skip_schema_check
        self.pykwalify_logs = pykwalify_logs
        self.quiet_bc = quiet_bc

        self.scheme_name = predefined_scheme or self.scheme_of_file_by_path()
        if isinstance(self.scheme_name, str):
            self.scheme_name = FileType(self.scheme_name)

        self.prev_ver = tag
        self.branch_name = branch_name
        self.file_type = self.get_file_type()
        self.current_file = self.load_data_from_file()
        self.fromversion = fromversion
        # If it is a newly added file or if it is a file outside the pack then we will not search for an old file
        if is_new_file or not is_file_path_in_pack(self.file_path):
            self.old_file = {}
        else:
            self.old_file = get_remote_file(old_file_path if old_file_path else file_path, tag=tag,
                                            suppress_print=suppress_print)
        self.configuration = configuration
Example #9
0
    def __init__(self,
                 file_path,
                 is_new_file=False,
                 old_file_path=None,
                 predefined_scheme=None,
                 fromversion=False,
                 configuration=Configuration(),
                 ignored_errors=None,
                 print_as_warnings=False,
                 tag='master',
                 suppress_print: bool = False,
                 branch_name=''):
        super().__init__(ignored_errors=ignored_errors,
                         print_as_warnings=print_as_warnings,
                         suppress_print=suppress_print)
        self.is_valid = True
        self.valid_extensions = ['.yml', '.json', '.md', '.png']
        self.file_path = file_path.replace('\\', '/')

        self.scheme_name = predefined_scheme or self.scheme_of_file_by_path()
        if isinstance(self.scheme_name, str):
            self.scheme_name = FileType(self.scheme_name)

        self.prev_ver = tag
        self.branch_name = branch_name
        self.file_type = self.get_file_type()
        self.current_file = self.load_data_from_file()
        self.fromversion = fromversion
        if is_new_file or predefined_scheme:
            self.old_file = {}
        else:
            self.old_file = get_remote_file(
                old_file_path if old_file_path else file_path, tag=tag)
        self.configuration = configuration
Example #10
0
def main(config, version, env_dir):
    config.configuration = Configuration()
    if version:
        version = get_distribution('demisto-sdk').version
        print(version)

    if env_dir:
        config.configuration.env_dir = env_dir
Example #11
0
 def __init__(self,
              configuration=Configuration(),
              is_circle=False,
              ignore_entropy=False,
              white_list_path=''):
     self.configuration = configuration
     self.is_circle = is_circle
     self.white_list_path = white_list_path
     self.ignore_entropy = ignore_entropy
Example #12
0
def main(config, version):
    config.configuration = Configuration()
    cur_version = get_distribution('demisto-sdk').version
    last_release = get_last_remote_release_version()
    if last_release and cur_version != last_release:
        print_warning(f'You are using demisto-sdk {cur_version}, however version {last_release} is available.\n'
                      f'You should consider upgrading via "pip3 install --upgrade demisto-sdk" command.')
    if version:
        version = get_distribution('demisto-sdk').version
        print(f'demisto-sdk {version}')
Example #13
0
 def __init__(
         self,
         configuration=Configuration(), is_circle=False, ignore_entropy=False, white_list_path='',
         input_path=''
 ):
     self.input_paths = input_path.split(',') if input_path else None
     self.configuration = configuration
     self.is_circle = is_circle
     self.white_list_path = white_list_path
     self.ignore_entropy = ignore_entropy
Example #14
0
    def __init__(self,
                 project_dir_list: str,
                 no_test: bool = False,
                 no_pylint: bool = False,
                 no_flake8: bool = False,
                 no_mypy: bool = False,
                 verbose: bool = False,
                 root: bool = False,
                 keep_container: bool = False,
                 cpu_num: int = 0,
                 parallel: bool = False,
                 max_workers: int = 10,
                 no_bandit: bool = False,
                 no_pslint: bool = False,
                 no_vulture: bool = False,
                 git: bool = False,
                 run_all_tests: bool = False,
                 outfile: str = '',
                 configuration: Configuration = Configuration()):

        if no_test and no_pylint and no_flake8 and no_mypy and no_bandit:
            raise ValueError("Nothing to run as all --no-* options specified.")

        self.parallel = parallel
        set_log_verbose(verbose)
        self.root = root
        self.max_workers = 10 if max_workers is None else int(max_workers)
        self.keep_container = keep_container
        self.cpu_num = cpu_num
        self.common_server_created = False
        self.run_args = {
            'pylint': not no_pylint,
            'flake8': not no_flake8,
            'mypy': not no_mypy,
            'tests': not no_test,
            'bandit': not no_bandit,
            'pslint': not no_pslint,
            'vulture': not no_vulture,
        }

        if run_all_tests or (not project_dir_list and git):
            self.pkgs = self.get_all_directories()

        else:
            self.pkgs = project_dir_list.split(',')

        if git:
            self.pkgs = self._get_packages_to_run()

        self.configuration = configuration
        self.requirements_for_python3 = get_dev_requirements(
            3.7, self.configuration.envs_dirs_base)
        self.requirements_for_python2 = get_dev_requirements(
            2.7, self.configuration.envs_dirs_base)
        self.outfile = outfile
Example #15
0
 def __init__(
         self,
         configuration=Configuration(), is_circle=False, ignore_entropy=False, white_list_path='',
         input_path='', prev_ver=None
 ):
     self.input_paths = input_path.split(',') if input_path else None
     self.configuration = configuration
     self.is_circle = is_circle
     self.white_list_path = white_list_path
     self.ignore_entropy = ignore_entropy
     self.prev_ver = prev_ver if prev_ver is not None else 'origin/master'
Example #16
0
    def __init__(self,
                 project_dir: str,
                 no_test: bool = False,
                 no_pylint: bool = False,
                 no_flake8: bool = False,
                 no_mypy: bool = False,
                 verbose: bool = False,
                 root: bool = False,
                 keep_container: bool = False,
                 cpu_num: int = 0,
                 configuration: Configuration = Configuration(),
                 lock: threading.Lock = threading.Lock(),
                 no_bandit: bool = False,
                 requirements_3: str = '',
                 requirements_2: str = ''):

        if no_test and no_pylint and no_flake8 and no_mypy and no_bandit:
            raise ValueError("Nothing to run as all --no-* options specified.")

        self.configuration = configuration
        dev_scripts_dir = os.path.join(self.configuration.sdk_env_dir,
                                       'common', 'dev_sh_scripts')
        self.run_dev_tasks_script_name = 'run_dev_tasks.sh'
        self.run_mypy_script_name = 'run_mypy.sh'
        self.container_setup_script_name = 'pkg_dev_container_setup.sh'
        self.run_dev_tasks_script = os.path.join(
            dev_scripts_dir, self.run_dev_tasks_script_name)
        self.container_setup_script = os.path.join(
            dev_scripts_dir, self.container_setup_script_name)
        self.run_mypy_script = os.path.join(dev_scripts_dir,
                                            self.run_mypy_script_name)
        self.docker_login_completed = False
        self.project_dir = os.path.abspath(
            os.path.join(self.configuration.env_dir, project_dir))
        if self.project_dir[-1] != os.sep:
            self.project_dir = os.path.join(self.project_dir, '')

        self.log_verbose = verbose
        self.root = root
        self.keep_container = keep_container
        self.cpu_num = cpu_num
        self.common_server_created = False
        self.run_args = {
            'pylint': not no_pylint,
            'flake8': not no_flake8,
            'mypy': not no_mypy,
            'bandit': not no_bandit,
            'tests': not no_test
        }
        self.lock = lock
        self.requirements_3 = requirements_3
        self.requirements_2 = requirements_2
Example #17
0
 def __init__(self, file_path, is_new_file=False, old_file_path=None, predefined_scheme=None,
              configuration=Configuration()):
     # type: (str, Optional[bool], Optional[str], Optional[str], Configuration) -> None
     self.is_valid = True
     self.file_path = file_path
     self.scheme_name = predefined_scheme or self.scheme_of_file_by_path()
     self.file_type = self.get_file_type()
     self.current_file = self.load_data_from_file()
     if is_new_file:
         self.old_file = {}
     else:
         self.old_file = get_remote_file(old_file_path if old_file_path else file_path)
     self.configuration = configuration
Example #18
0
 def __init__(
         self,
         configuration=Configuration(), is_circle=False, ignore_entropy=False, white_list_path='',
         input_path='', prev_ver=None
 ):
     self.input_paths = input_path.split(',') if input_path else None
     self.configuration = configuration
     self.is_circle = is_circle
     self.white_list_path = white_list_path
     self.ignore_entropy = ignore_entropy
     self.prev_ver = prev_ver
     if self.prev_ver and not self.prev_ver.startswith('origin'):
         self.prev_ver = 'origin/' + self.prev_ver
Example #19
0
 def __init__(self,
              is_test_run=False,
              is_circle=False,
              configuration=Configuration()):
     self.is_circle = is_circle
     self.configuration = configuration
     if not is_test_run and self.is_circle:
         self.id_set = self.load_id_set()
         self.id_set_path = os.path.join(self.configuration.env_dir,
                                         'configs', 'id_set.json')
         self.script_set = self.id_set[self.SCRIPTS_SECTION]
         self.playbook_set = self.id_set[self.PLAYBOOK_SECTION]
         self.integration_set = self.id_set[self.INTEGRATION_SECTION]
         self.test_playbook_set = self.id_set[self.TEST_PLAYBOOK_SECTION]
def test_extract_long_description(tmpdir):
    # Test when script
    extractor = YmlSplitter(input=f'{git_path()}/demisto_sdk/tests/test_files/script-test_script.yml',
                            output='', file_type='script', no_demisto_mock=False,
                            no_common_server=False, configuration=Configuration())
    assert extractor.extract_long_description('output_path') == 0

    # Test opening the file and writing to it
    extractor = YmlSplitter(input=f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml',
                            output=str(tmpdir.join('temp_text.txt')), file_type='integration')

    extractor.extract_long_description(extractor.output)
    with open(extractor.output, 'rb') as temp_description:
        assert temp_description.read().decode('utf-8') == 'detaileddescription'
    os.remove(extractor.output)
Example #21
0
def test_get_yml_type(yml_path, expected):
    from demisto_sdk.commands.split_yml.extractor import Extractor
    configuration = Configuration()
    with patch.object(Extractor, '__init__', lambda a, b, c, d, e, f, g: None):
        extractor = Extractor('', '', False, False, '', configuration)
        # Test script/integration case
        extractor.yml_type = ''
        extractor.yml_path = yml_path
        assert extractor.get_yml_type() == expected
        # Test when type is set
        extractor.yml_type = expected
        assert extractor.get_yml_type() == expected
        # Test error
        extractor.yml_type = ''
        extractor.yml_path = 'path'
        with pytest.raises(ValueError):
            extractor.get_yml_type()
Example #22
0
    def __init__(self,
                 output: str,
                 name: str = '',
                 id: str = '',
                 integration: bool = False,
                 script: bool = False,
                 pack: bool = False,
                 demisto_mock: bool = False,
                 common_server: bool = False,
                 contribution: Union[str] = None,
                 description: str = '',
                 author: str = ''):
        self.output = output if output else ''
        self.id = id

        self.is_integration = integration
        self.is_script = script
        self.is_pack = pack
        self.demisto_mock = demisto_mock
        self.common_server = common_server
        self.configuration = Configuration()
        self.contribution = contribution
        self.description = description
        self.author = author
        self.contrib_conversion_errs: List[str] = []

        # if no flag given automatically create a pack.
        if not integration and not script and not pack:
            self.is_pack = True

        self.full_output_path = ''

        self.name = name
        if name and not self.contribution:
            while ' ' in name:
                name = str(
                    input(
                        "The directory and file name cannot have spaces in it, Enter a different name: "
                    ))

        if self.contribution:
            self.dir_name = self.format_pack_dir_name(name)
        else:
            self.dir_name = name
        self.is_pack_creation = not all([self.is_script, self.is_integration])
Example #23
0
def test_extract_long_description():
    from demisto_sdk.commands.split_yml.extractor import Extractor
    configuration = Configuration()
    with patch.object(Extractor, '__init__', lambda a, b, c, d, e, f, g: None):
        # Test yml_type is script
        extractor = Extractor('', '', False, False, '', configuration)
        extractor.yml_type = ''
        extractor.yml_path = 'script'
        assert extractor.extract_long_description('output_path') == 0
        # Test opening the file and writing to it
        extractor.yml_path = f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml'
        extractor.extract_long_description(
            f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt')
        with open(f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt',
                  'rb') as temp_file:
            file_data = temp_file.read().decode('utf-8')
            assert file_data == 'detaileddescription'
        os.remove(f'{git_path()}/demisto_sdk/tests/test_files/temp_file.txt')
Example #24
0
 def __init__(self,
              is_test_run=False,
              is_circle=False,
              configuration=Configuration(),
              ignored_errors=None,
              print_as_warnings=False):
     super().__init__(ignored_errors=ignored_errors,
                      print_as_warnings=print_as_warnings)
     self.is_circle = is_circle
     self.configuration = configuration
     if not is_test_run and self.is_circle:
         self.id_set = self.load_id_set()
         self.id_set_path = os.path.join(self.configuration.env_dir,
                                         'configs', 'id_set.json')
         self.script_set = self.id_set[self.SCRIPTS_SECTION]
         self.playbook_set = self.id_set[self.PLAYBOOK_SECTION]
         self.integration_set = self.id_set[self.INTEGRATION_SECTION]
         self.test_playbook_set = self.id_set[self.TEST_PLAYBOOK_SECTION]
Example #25
0
def test_extract_image():
    from demisto_sdk.commands.split_yml.extractor import Extractor
    configuration = Configuration()
    with patch.object(Extractor, '__init__', lambda a, b, c, d, e, f, g: None):
        # Test yml_type is script
        extractor = Extractor('', '', False, False, '', configuration)
        extractor.yml_type = ''
        extractor.yml_path = 'script'
        assert extractor.extract_image('output_path') == 0
        # Test opening the file and writing to it
        extractor.yml_path = f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml'
        extractor.extract_image(
            f'{git_path()}/demisto_sdk/tests/test_files/temp_image.png')
        with open(f'{git_path()}/demisto_sdk/tests/test_files/temp_image.png',
                  'rb') as temp_image:
            image_data = temp_image.read()
            image = base64.b64encode(image_data).decode('utf-8')
            assert image == DEFAULT_IMAGE_BASE64
        os.remove(f'{git_path()}/demisto_sdk/tests/test_files/temp_image.png')
Example #26
0
def test_extract_long_description():
    from demisto_sdk.commands.split_yml.extractor import Extractor

    # Test when script
    extractor = Extractor(input='script',
                          output='',
                          file_type='script',
                          no_demisto_mock=False,
                          no_common_server=False,
                          configuration=Configuration())
    assert extractor.extract_long_description('output_path') == 0

    # Test opening the file and writing to it
    extractor.input = f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml'
    extractor.file_type = 'integration'
    extractor.output = f'{git_path()}/demisto_sdk/tests/test_files/temp_text.txt'

    extractor.extract_long_description(extractor.output)
    with open(extractor.output, 'rb') as temp_description:
        assert temp_description.read().decode('utf-8') == 'detaileddescription'
    os.remove(extractor.output)
Example #27
0
 def __init__(self, input: str, output: str = '', file_type: str = '', no_demisto_mock: bool = False,
              no_common_server: bool = False, no_auto_create_dir: bool = False, configuration: Configuration = None,
              base_name: str = '', no_readme: bool = False, no_pipenv: bool = False,
              no_logging: bool = False, no_basic_fmt: bool = False, new_module_file: bool = False):
     self.input = Path(input).resolve()
     self.output = (Path(output) if output else Path(self.input.parent)).resolve()
     self.demisto_mock = not no_demisto_mock
     self.common_server = not no_common_server
     self.file_type = file_type
     self.base_name = base_name
     self.readme = not no_readme
     self.pipenv = not no_pipenv
     self.logging = not no_logging
     self.basic_fmt = not no_basic_fmt
     self.lines_inserted_at_code_start = 0
     if configuration is None:
         self.config = Configuration()
     else:
         self.config = configuration
     self.autocreate_dir = not no_auto_create_dir
     with open(self.input, 'rb') as yml_file:
         self.yml_data = yaml.load(yml_file)
Example #28
0
def test_extract_image():
    from demisto_sdk.commands.split_yml.extractor import Extractor

    # Test when script
    extractor = Extractor(input='script',
                          output='',
                          file_type='script',
                          no_demisto_mock=False,
                          no_common_server=False,
                          configuration=Configuration())
    assert extractor.extract_image('output_path') == 0

    # Test opening the file and writing to it
    extractor.input = f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml'
    extractor.file_type = 'integration'
    extractor.output = f'{git_path()}/demisto_sdk/tests/test_files/temp_image.png'

    extractor.extract_image(extractor.output)
    with open(extractor.output, 'rb') as temp_image:
        image_data = temp_image.read()
        image = base64.b64encode(image_data).decode('utf-8')
        assert image == DEFAULT_IMAGE_BASE64
    os.remove(extractor.output)
Example #29
0
 def __init__(self,
              file_path,
              is_new_file=False,
              old_file_path=None,
              predefined_scheme=None,
              fromversion=False,
              configuration=Configuration(),
              ignored_errors=None,
              print_as_warnings=False,
              tag='master'):
     super().__init__(ignored_errors=ignored_errors,
                      print_as_warnings=print_as_warnings)
     self.is_valid = True
     self.file_path = file_path.replace('\\', '/')
     self.scheme_name = predefined_scheme or self.scheme_of_file_by_path()
     self.file_type = self.get_file_type()
     self.current_file = self.load_data_from_file()
     self.fromversion = fromversion
     if is_new_file or predefined_scheme:
         self.old_file = {}
     else:
         self.old_file = get_remote_file(
             old_file_path if old_file_path else file_path, tag=tag)
     self.configuration = configuration
Example #30
0
from demisto_sdk.commands.common.configuration import Configuration
from demisto_sdk.commands.common.hook_validations.id import IDSetValidator

CONFIG = Configuration()


def test_validness_in_set():
    validator = IDSetValidator(is_circle=False,
                               is_test_run=True,
                               configuration=CONFIG)

    obj_data = {"test": {"name": "test"}}
    obj_set = [
        obj_data,
    ]

    assert validator.is_valid_in_id_set(file_path="test", obj_data=obj_data, obj_set=obj_set), \
        "The id validator couldn't find id as valid one"


def test_obj_not_found_in_set():
    validator = IDSetValidator(is_circle=False,
                               is_test_run=True,
                               configuration=CONFIG)

    obj_data = {"test": {"name": "test"}}
    actual_obj_set = {"test": {"name": "test", "fromversion": "1.2.2"}}
    obj_set = [
        actual_obj_set,
    ]