예제 #1
0
def test_return_raw_outputs_from_log_with_raw_response_flag(
    mocker,
    set_environment_variables,
):
    """
    Validates that the raw outputs of a log file is extracted correctly while using the raw_output parameter,
     even if the file has a context part

    """
    file_path = f'{git_path()}/demisto_sdk/commands/run_cmd/tests/test_data/kl-get-component.txt'
    expected_output = [{
        'ID': 10082,
        'Name': 'Projects',
        'ShortName': 'Projects',
        'SystemName': 'Projects'
    }, {
        'ID': 10077,
        'Name': 'Universe',
        'ShortName': 'Universe',
        'SystemName': 'Universe'
    }]
    mocker.patch.object(DefaultApi, 'download_file', return_value=file_path)
    runner = Runner('Query', json_to_outputs=True, raw_response=True)
    temp = runner._return_context_dict_from_log(['123'])
    assert temp == expected_output
예제 #2
0
def test_return_raw_outputs_from_log(mocker, set_environment_variables,
                                     file_path, expected_output):
    """
    Validates that the context of a log file is extracted correctly.

    """
    mocker.patch.object(DefaultApi, 'download_file', return_value=file_path)
    runner = Runner('Query', json_to_outputs=True)
    temp = runner._return_context_dict_from_log(['123'])
    assert temp == expected_output
예제 #3
0
def test_return_raw_outputs_from_log_also_write_log(mocker,
                                                    set_environment_variables,
                                                    file_path,
                                                    expected_output):
    """
    Validates that the context of a log file is extracted correctly and that the log file is saved correctly in
    the expected output path.

    """
    mocker.patch.object(DefaultApi, 'download_file', return_value=file_path)
    temp_file = tempfile.NamedTemporaryFile()
    runner = Runner('Query', debug_path=temp_file.name, json_to_outputs=True)
    temp = runner._return_context_dict_from_log(['123'])
    assert temp == expected_output
    assert filecmp.cmp(file_path, temp_file.name)
    temp_file.close()