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')
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)
def test_extract_code_pwsh(tmpdir): extractor = Extractor(input=f'{git_path()}/demisto_sdk/tests/test_files/integration-powershell_ssh_remote.yml', output=str(tmpdir.join('temp_code')), file_type='integration') extractor.extract_code(extractor.output) # notice that we passed without an extension. Extractor should be adding .ps1 with open(extractor.output + '.ps1', 'r', encoding='utf-8') as temp_code: file_data = temp_code.read() assert '. $PSScriptRoot\\CommonServerPowerShell.ps1\n' in file_data assert file_data[-1] == '\n'
def extract_code(config, **kwargs): file_type = find_type(kwargs.get('input')) if file_type not in ["integration", "script"]: print_error('File is not an Integration or Script.') return 1 extractor = Extractor(configuration=config.configuration, file_type=file_type, **kwargs) return extractor.extract_code(kwargs['outfile'])
def extract_code(config, **kwargs): file_type = find_type(kwargs.get('input'), ignore_sub_categories=True) if file_type not in [FileType.INTEGRATION, FileType.SCRIPT]: print_error('File is not an Integration or Script.') return 1 extractor = Extractor(configuration=config.configuration, file_type=file_type.value, **kwargs) return extractor.extract_code(kwargs['outfile'])
def test_extract_code(tmpdir): extractor = Extractor(input=f'{git_path()}/demisto_sdk/tests/test_files/integration-Zoom.yml', output=str(tmpdir.join('temp_code.py')), file_type='integration') 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 #' in file_data assert 'from CommonServerPython import * #' 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 #' not in file_data assert 'from CommonServerPython import * #' not in file_data assert file_data[-1] == '\n'
def extract_code(config, **kwargs): extractor = Extractor(configuration=config.configuration, **kwargs) return extractor.extract_code(kwargs['outfile'])