Ejemplo n.º 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')
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
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'