コード例 #1
0
ファイル: http_utils.py プロジェクト: Vieira-zj/zj_new_py_app
def http_test():
    LogManager.build_logger(Constants.LOG_FILE_PATH)

    # get request
    headers = {'X-Test-Method': 'X-Test-Get'}
    http_utils = HttpUtils.get_instance().set_default_headers(headers)

    mock_url = 'http://127.0.0.1:17891/index'
    headers['Content-Type'] = 'text/plain; charset=utf-8'
    query = 'k1=v1&k2=v2'
    resp = http_utils.send_http_request(HttpUtils.HTTP_METHOD_GET,
                                        mock_url,
                                        query,
                                        headers=headers,
                                        timeout=0.5)
    assert (resp is not None and resp.status_code == 200)

    # post request
    headers = {'X-Test-Method': 'X-Test-Post'}
    http_utils.set_default_headers(headers)

    headers['Content-Type'] = 'text/json; charset=utf-8'
    data_dict = {'email': '*****@*****.**', 'password': '******'}
    # resp = http_utils.send_http_request(
    #     HttpUtils.HTTP_METHOD_POST_DATA, mock_url, json.dumps(data_dict), headers=headers)
    resp = http_utils.send_http_request(HttpUtils.HTTP_METHOD_POST_JSON,
                                        mock_url,
                                        data_dict,
                                        headers=headers)
    assert (resp is not None and resp.status_code == 200)

    LogManager.clear_log_handles()
コード例 #2
0
ファイル: conftest.py プロジェクト: Vieira-zj/zj_new_py_app
def init_logger():
    logdir_path = LoadConfigs.get_testenv_configs().get('logdir_path')
    logdir_path = logdir_path.replace('{project}', project_path)
    logfile_path = os.path.join(
        logdir_path,
        'pytest_log_%s.txt' % SysUtils.get_current_date_and_time())
    LogManager.build_logger(logfile_path)
コード例 #3
0
def py_base_ex03():
    sys.path.append(os.getenv('PYPATH'))
    from utils import Constants
    from utils import LogManager
    from utils import SysUtils

    try:
        logger = LogManager.build_logger(Constants.LOG_FILE_PATH)
        logger.info('import external modules test.')
        utils = SysUtils().get_instance()
        utils.run_sys_cmd('python --version')
    finally:
        LogManager.clear_log_handles()
コード例 #4
0
def py_parallel_demo24(is_thread=False):
    import logging
    from concurrent.futures import ThreadPoolExecutor
    from concurrent.futures import ProcessPoolExecutor
    from concurrent.futures import wait

    sys.path.append(os.getenv('PYPATH'))
    from utils import Constants, LogManager

    LogManager.build_logger(Constants.LOG_FILE_PATH,
                            stream_log_level=logging.DEBUG)
    logger = LogManager.get_logger()

    base_path = os.path.join(os.getenv('HOME'), 'Downloads/tmp_files')
    file_paths = [os.path.join(base_path, 'test_data.csv')]
    file_paths.append(os.path.join(base_path, 'test_log.txt'))
    file_paths.append(os.path.join(base_path, 'not_exist.txt'))

    workers_num = 3
    executor = ThreadPoolExecutor(max_workers=workers_num) \
        if is_thread else ProcessPoolExecutor(max_workers=workers_num)
    f_submit = [
        executor.submit(checkfile_process, logger, path) for path in file_paths
    ]
    f_done = wait(f_submit, return_when='ALL_COMPLETED')

    for future in f_done.done:
        if future.exception() is None:
            if future.result() is not None:
                # if error, result() will directly raise Exception
                logger.debug('result: ' + future.result())
        else:
            logger.error('exception ===> ' + str(future.exception()))

    logger.debug('[%d] main process done.' % os.getpid())
    LogManager.clear_log_handles()
コード例 #5
0
    def __init__(self, test_pkg_name, run_mins):
        '''
        Constructor
        '''
        self.__test_pkg_name = test_pkg_name
        self.__run_mins = int(run_mins)

        cur_time = SysUtils.get_current_date_and_time()
        self.__log_root_path = os.path.join(os.getcwd(), 'monkeyreports')
        self.__log_dir_path_for_win = os.path.join(self.__log_root_path,
                                                   cur_time)
        self.__log_dir_path_for_shell = '/data/local/tmp/monkey_test_logs'

        self.__exec_log_path = os.path.join(self.__log_dir_path_for_win,
                                            'run_log.log')
        self.__device_props_file_path = os.path.join(
            self.__log_dir_path_for_win, 'device_props.log')
        self.__app_dump_file_path = os.path.join(self.__log_dir_path_for_win,
                                                 'app_info.log')
        self.__monkey_log_path_for_shell = '%s/%s' % (
            self.__log_dir_path_for_shell, 'monkey_log.log')
        self.__logcat_log_path_for_shell = '%s/%s' % (
            self.__log_dir_path_for_shell, 'logcat_full_log.log')

        self.__logcat_exception_file_name = 'logcat_exception.log'
        self.__logcat_exception_path_for_shell = '%s/%s' % (
            self.__log_dir_path_for_shell, self.__logcat_exception_file_name)
        self.__logcat_anr_file_name = 'logcat_anr.log'
        self.__logcat_anr_path_for_shell = '%s/%s' % (
            self.__log_dir_path_for_shell, self.__logcat_anr_file_name)

        SysUtils.create_dir(self.__log_dir_path_for_win)
        self.__logger = LogManager.build_logger(self.__exec_log_path)
        self.__sysutils = SysUtils()
        self.__adbutils = AdbUtils()
        self.__monitor = MonkeyMonitor()

        self.__profile_monitor = ProfileMonitor(
            Constants.ITEST_COLLECT_INTERVAL)
        self.__chart_parser = ChartParser(self.__log_dir_path_for_win)
        self.__report = MonkeyReport(self.__log_dir_path_for_win,
                                     self.__logcat_exception_file_name,
                                     self.__logcat_anr_file_name)
コード例 #6
0
        if not os.path.exists(output_dir_path):
            self.__logger.error('test output dir is not exist: ' +
                                output_dir_path)
            return ''
        if not os.path.isdir(output_dir_path):
            self.__logger.error('invalid test out dir: ' + output_dir_path)
            return ''
        return output_dir_path


if __name__ == '__main__':

    isTest = True

    if isTest:
        print('Done')
    else:
        # init logger and configs
        LogManager.build_logger(Constants.LOG_FILE_PATH)
        cfg_file_path = os.path.join(os.getenv('PYPATH'), 'apitest',
                                     'configs.ini')
        LoadConfigs.load_configs(cfg_file_path)

        mail_content = 'API test done.\nPlease read details of results in attachment.'
        mail = EmailHelper.get_intance()
        mail.set_content_text(mail_content).send_email()

        LogManager.clear_log_handles()
        print('email helper test DONE.')
コード例 #7
0
            ret_ok = resp.json()['results']
            expected_ok = json.loads(case[self.CASE_SCHEMA_EXP_MSG])['results']
            assert (ret_ok == expected_ok)

    @pytest.allure.severity(pytest.allure.severity_level.CRITICAL)
    def test_index_post_01(self):
        case = LoadCases.get_instance().get_tc_data_dict(self.__cur_case)
        headers = LoadCases.format_headers_to_dict(
            case[self.CASE_SCHEMA_HEADER])
        resp = self.__http_utils.send_http_request(
            case[self.CASE_SCHEMA_METHOD],
            case[self.CASE_SCHEMA_URL],
            case[self.CASE_SCHEMA_BODY],
            headers=headers)
        # assert(resp is not None and resp.status_code == int(case['RetCode']))
        self.base_http_assert(resp)


if __name__ == '__main__':

    LogManager.build_logger(Constants.LOG_FILE_PATH,
                            stream_log_level=logging.DEBUG)
    file_path = os.path.join(os.path.dirname(os.getcwd()), 'TestCases.xlsx')
    LoadCases.get_instance().pre_load_sheet(
        file_path, 'Module01').load_all_cases_by_sheet()

    pytest.main(['-v', '-s', 'test_module_01.py'])

    LogManager.clear_log_handles()
    print('test module 01 DONE.')