<s> """<STR_LIT>""" <EOL> from os import path <EOL> from mock import patch <EOL> from fabric . api import env <EOL> import requests <EOL> from prestoadmin import collect <EOL> from prestoadmin . collect import TMP_PRESTO_DEBUG , PRESTOADMIN_LOG_NAME , PRESTOADMIN_LOG_DIR , OUTPUT_FILENAME_FOR_LOGS , OUTPUT_FILENAME_FOR_SYS_INFO <EOL> import prestoadmin <EOL> from tests . unit . base_unit_case import BaseUnitCase <EOL> class TestCollect ( BaseUnitCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_collect_logs ( self , path_exists_mock , mkdirs_mock , copy_mock , <EOL> tarfile_open_mock , get_files_mock , server_log_mock , <EOL> launcher_log_mock ) : <EOL> downloaded_logs_loc = path . join ( TMP_PRESTO_DEBUG , "<STR_LIT>" ) <EOL> path_exists_mock . return_value = False <EOL> collect . logs ( ) <EOL> mkdirs_mock . assert_called_with ( downloaded_logs_loc ) <EOL> copy_mock . assert_called_with ( path . join ( PRESTOADMIN_LOG_DIR , <EOL> PRESTOADMIN_LOG_NAME ) , <EOL> downloaded_logs_loc ) <EOL> tarfile_open_mock . assert_called_with ( OUTPUT_FILENAME_FOR_LOGS , '<STR_LIT>' ) <EOL> tar = tarfile_open_mock . return_value <EOL> tar . add . assert_called_with ( downloaded_logs_loc , <EOL> arcname = path . basename ( downloaded_logs_loc ) ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_files ( self , get_mock , path_exists_mock ) : <EOL> remote_path = "<STR_LIT>" <EOL> local_path = "<STR_LIT>" <EOL> env . host = "<STR_LIT>" <EOL> path_with_host_name = path . join ( local_path , env . host ) <EOL> path_exists_mock . return_value = True <EOL> collect . get_files ( remote_path , local_path ) <EOL> get_mock . assert_called_with ( remote_path , path_with_host_name , True ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_files_warning ( self , get_mock , warn_mock , path_exists_mock ) : <EOL> remote_path = "<STR_LIT>" <EOL> local_path = "<STR_LIT>" <EOL> env . host = "<STR_LIT>" <EOL> path_exists_mock . return_value = True <EOL> get_mock . side_effect = SystemExit <EOL> collect . get_files ( remote_path , local_path ) <EOL> warn_mock . assert_called_with ( "<STR_LIT>" + remote_path + <EOL> "<STR_LIT>" + env . host ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_query_info_not_run_on_workers ( self , req_get_mock ) : <EOL> env . host = [ "<STR_LIT>" ] <EOL> env . roledefs [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> collect . query_info ( "<STR_LIT>" ) <EOL> assert not req_get_mock . called <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_query_info_fail_invalid_id ( self , req_get_mock , requests_url ) : <EOL> env . host = "<STR_LIT>" <EOL> env . roledefs [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> query_id = "<STR_LIT>" <EOL> req_get_mock . return_value . status_code = requests . codes . ok + <NUM_LIT:10> <EOL> self . assertRaisesRegexp ( SystemExit , "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> collect . query_info , query_id ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_collect_query_info ( self , requests_url_mock , requests_get_mock , <EOL> path_exist_mock , mkdir_mock , open_mock , <EOL> req_json_mock , json_dumps_mock ) : <EOL> query_id = "<STR_LIT>" <EOL> query_info_file_name = path . join ( TMP_PRESTO_DEBUG , <EOL> "<STR_LIT>" + query_id + "<STR_LIT>" ) <EOL> path_exist_mock . return_value = False <EOL> file_obj = open_mock . return_value . __enter__ . return_value <EOL> requests_get_mock . return_value . json . return_value = req_json_mock <EOL> requests_get_mock . return_value . status_code = requests . codes . ok <EOL> env . host = "<STR_LIT>" <EOL> env . roledefs [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> collect . query_info ( query_id ) <EOL> mkdir_mock . assert_called_with ( TMP_PRESTO_DEBUG ) <EOL> open_mock . assert_called_with ( query_info_file_name , "<STR_LIT:w>" ) <EOL> json_dumps_mock . assert_called_with ( req_json_mock , indent = <NUM_LIT:4> ) <EOL> file_obj . write . assert_called_with ( json_dumps_mock . return_value ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_collect_system_info ( self , requests_url_mock , requests_get_mock , <EOL> path_exists_mock , <EOL> mkdir_mock , open_mock , <EOL> execute_mock , req_json_mock , <EOL> json_dumps_mock , conn_info_mock , <EOL> make_tarfile_mock ) : <EOL> downloaded_sys_info_loc = path . join ( TMP_PRESTO_DEBUG , "<STR_LIT>" ) <EOL> node_info_file_name = path . join ( downloaded_sys_info_loc , <EOL> "<STR_LIT>" ) <EOL> conn_info_file_name = path . join ( downloaded_sys_info_loc , <EOL> "<STR_LIT>" ) <EOL> path_exists_mock . return_value = False <EOL> file_obj = open_mock . return_value . __enter__ . return_value <EOL> requests_get_mock . return_value . json . return_value = req_json_mock <EOL> requests_get_mock . return_value . status_code = requests . codes . ok <EOL> connector_info = conn_info_mock . return_value <EOL> env . host = "<STR_LIT>" <EOL> env . roledefs [ "<STR_LIT>" ] = [ "<STR_LIT>" ] <EOL> collect . system_info ( ) <EOL> mkdir_mock . assert_any_call ( TMP_PRESTO_DEBUG ) <EOL> mkdir_mock . assert_called_with ( downloaded_sys_info_loc ) <EOL> open_mock . assert_any_call ( node_info_file_name , "<STR_LIT:w>" ) <EOL> json_dumps_mock . assert_called_with ( req_json_mock , indent = <NUM_LIT:4> ) <EOL> file_obj . write . assert_any_call ( json_dumps_mock . return_value ) <EOL> open_mock . assert_any_call ( conn_info_file_name , "<STR_LIT:w>" ) <EOL> assert conn_info_mock . called <EOL> file_obj . write . assert_any_call ( connector_info + '<STR_LIT:\n>' ) <EOL> execute_mock . assert_called_with ( collect . get_system_info , <EOL> downloaded_sys_info_loc , roles = [ ] ) <EOL> make_tarfile_mock . assert_called_with ( OUTPUT_FILENAME_FOR_SYS_INFO , <EOL> downloaded_sys_info_loc ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_system_info ( self , exists_mock , run_collect_mock , <EOL> plat_info_mock , java_version_mock , <EOL> server_version_mock , <EOL> append_mock , get_files_mock ) : <EOL> downloaded_sys_info_loc = path . join ( TMP_PRESTO_DEBUG , "<STR_LIT>" ) <EOL> version_info_file_name = path . join ( TMP_PRESTO_DEBUG , <EOL> "<STR_LIT>" ) <EOL> platform_info = "<STR_LIT>" <EOL> server_version = "<STR_LIT>" <EOL> java_version = "<STR_LIT>" <EOL> exists_mock . return_value = False <EOL> plat_info_mock . return_value = platform_info <EOL> java_version_mock . return_value = java_version <EOL> server_version_mock . return_value = server_version <EOL> collect . get_system_info ( downloaded_sys_info_loc ) <EOL> exists_mock . assert_any_call ( TMP_PRESTO_DEBUG ) <EOL> run_collect_mock . assert_any_call ( '<STR_LIT>' + TMP_PRESTO_DEBUG ) <EOL> exists_mock . assert_any_call ( version_info_file_name ) <EOL> append_mock . assert_any_call ( version_info_file_name , <EOL> '<STR_LIT>' + <EOL> platform_info + '<STR_LIT:\n>' ) <EOL> append_mock . assert_any_call ( version_info_file_name , <EOL> '<STR_LIT>' + <EOL> java_version + '<STR_LIT:\n>' ) <EOL> append_mock . assert_any_call ( version_info_file_name , <EOL> '<STR_LIT>' + <EOL> prestoadmin . __version__ + '<STR_LIT:\n>' ) <EOL> append_mock . assert_any_call ( version_info_file_name , <EOL> '<STR_LIT>' + <EOL> server_version + '<STR_LIT:\n>' ) <EOL> get_files_mock . assert_called_with ( version_info_file_name , <EOL> downloaded_sys_info_loc ) </s>
