def monkey_device_release(): """ @api {post} /v1/monkey/device/release 释放 设备 @apiName ReleaseMonkeyDevice @apiGroup 自动化测试 @apiDescription 更新正在使用设备使用状态为空闲 @apiParam {string} [serial] 设备序列号 @apiParamExample {json} Request-Example: { "serial": "7189ac55" } @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "code": 0, "data": [], "message": "ok" } """ serial = parse_json_form('monkey_device_using') if serial: ret, msg = MonkeyDeviceUsingBusiness.release_device(serial) return dict(code=ret, message=msg) else: raise FieldMissingException('serial is required')
def fields_create_handler(): """ @api {post} /v1/datashow/fields 新增 测试数据属性 @apiName SetDataShowFields @apiGroup 自动化测试 @apiDescription 新建 测试数据属性 @apiParam {int} data_type 属性类型 @apiParam {base_string} data_value 属性值 @apiParamExample {json} Request-Example: { "data_type": 1, "data_value": "test" } @apiSuccessExample {json} Success-Response: { "code": 0, "data": [], "message": "ok" } """ data_type, data_value = parse_json_form("data_show_filed_create") code = DataShowFieldsBusiness.create(data_type, data_value) return { "code": code }
def monkey_error_log_create_handler(): """ @api {post} /v1/monkey/errorlog 上传 错误日志 @apiName UpdateErrorLog @apiGroup 自动化测试 @apiDescription 上传 错误日志 @apiParam {int} monkey_id Monkey ID @apiParam {string} error_type 错误类型 @apiParam {string} error_message 错误信息 @apiParam {int} task_id 单个设备的测试 ID @apiParam {int} error_count 错误数量 @apiParamExample {json} Request-Example: { "monkey_id":1, "error_type": "Exception", "error_message": "Java.Lang.Iellagle", "task_id": 1, "error_count": 10 } @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "code": 0, "data": [], "message": "ok" } """ monkey_id, task_id, error_type, error_message, error_count = parse_json_form( 'monkey_error_log_create') ret, msg = MonkeyErrorLogBusiness.create(monkey_id=monkey_id, task_id=task_id, error_type=error_type, error_message=error_message, error_count=error_count) return {"code": ret, "message": msg}
def monkey_report_update_handler(id): """ @api {post} /v1/monkey/report/:id 更新 Monkey 测试报告 @apiName UpdateMonkeyReport @apiGroup 自动化测试 @apiDescription 更新 Monkey 测试报告 @apiParam {int} [monkey_id] 上传用户 ID @apiParam {int} [report_type] 存放 apk 的 oss 路径 @apiParam {int} [task_id] 上传用户 ID @apiParam {string} [report_url] 存放 apk 的 oss 路径 @apiParamExample {json} Request-Example: { "monkey_id": 1, "report_type": 1, "report_url": "http://ctsssource.oss-cn-shanghai.aliyuncs.com/monkey/2019-07-12/None/index.html", "task_id": 1 } @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "code": 0, "data": [], "message": "ok" } """ monkey_id, task_id, report_type, report_url = parse_json_form( 'monkey_report_update') ret, msg = MonkeyReportBusiness.update(id, monkey_id=monkey_id, task_id=task_id, report_type=report_type, report_url=report_url) return dict(code=ret, message=msg)
def monkey_cancel_handler(): """ @api {post} /v1/monkey/cancel 中断 monkey 测试 @apiName CancelMonkey @apiGroup 自动化测试 @apiDescription 中断 monkey @apiParam {int} [monkey_id] Monkey ID @apiParam {int} [task_id] 具体设备测试项目的 ID @apiParamExample {json} Request-Example: { "monkey_id": 1 } @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "code": 0, "data": [], "message": "ok" } """ monkey_id, task_id = parse_json_form('monkey_cancel') ret, msg = MonkeyBusiness.cancel_monkey(monkey_id, task_id) return dict( code=ret, message=msg )
def monkey_device_status_update_handler(id): current_app.logger.info(id) if id is None: return json_detail_render(101, [], "无效的id") (process, activity_count, activity_tested_count, activity_all, activity_tested, anr_count, crash_count, crash_rate, exception_count, exception_run_time, setup_install_app_status, setup_uninstall_app_status, start_app_status, begin_time, login_app_status, running_status, teardown_uninstall_app_status, end_time, run_time, device_connect_status, screen_lock_status, current_stage, running_error_reason, mobile_resolution) = parse_json_form('monkey_device_status_update') ret, msg = MonkeyDeviceStatusBusiness.update(id=id, process=process, activity_count=activity_count, activity_tested_count=activity_tested_count, activity_all=activity_all, activity_tested=activity_tested, anr_count=anr_count, crash_count=crash_count, exception_count=exception_count, exception_run_time=exception_run_time, setup_install_app_status=setup_install_app_status, begin_time=begin_time, start_app_status=start_app_status, setup_uninstall_app_status=setup_uninstall_app_status, login_app_status=login_app_status, end_time=end_time, running_status=running_status, run_time=run_time, teardown_uninstall_app_status=teardown_uninstall_app_status, device_connect_status=device_connect_status, screen_lock_status=screen_lock_status, current_stage=current_stage, running_error_reason=running_error_reason, mobile_resolution=mobile_resolution) response = { "code": ret, "data": [], "message": msg } return response
def performance_test_create_handler(): performance_id, run_type, run_time = parse_json_form( 'performance_test_create') performance_test_id = PerformanceTestBusiness.create( performance_id, run_type, run_time) response = {"code": 0, "data": [{"id": performance_test_id}]} return response
def performance_log_create_handler(id): # current_app.logger.error(id) if id is None: return json_detail_render(101, [], "无效的id") cpu, rss, heap_size, heap_alloc = parse_json_form('performance_log_create') ret, msg = PerformanceTestLogBusiness.create(id, cpu, rss, heap_size, heap_alloc) response = {"code": ret, "message": msg, "data": []} return response
def response_log_update_handler(id): """ @api {post} /v1/datashow/response/log/{id:int} 修改 响应时间_Log @apiName ModifyDataShowResponseLog @apiGroup 自动化测试 @apiDescription 修改 响应时间_Log @apiParam {int} data_source 数据来源 @apiParam {int} phone_model 手机类型 @apiParam {int} apk_version apk 版本 @apiParam {int} kernel_version 内核版本 @apiParam {int} system_version 系统版本 @apiParam {int} thesaurus_version 词库版本 @apiParam {int} corpus_version 语料库版本 @apiParam {string} key_9_kernel_click_time_average 9键点击请求内核响应平均时间 @apiParam {string} key_26_kernel_click_time_average 26 键点击请求内核响应平均时间 @apiParam {string} key_9_kernel_response_time 9 键点击请求内核响应时间 @apiParam {string} key_26_kernel_response_time 26 键点击请求内核响应时间 @apiParam {string} cpu_average cpu 平均值 @apiParam {string} ram_average 内存 平均值 @apiParam {string} battery_use 耗电量 @apiParam {string} comment 备注 @apiParam {int} show_in_chart 是否显示在图表中,0:保存,1:不保存 @apiParamExample {json} Request-Example: { "data_source": 1, "phone_model": 4, "apk_version": 3, "kernel_version": 4, "system_version": 5, "thesaurus_version": 6, "corpus_version": 7, "key_9_kernel_click_time_average": "1231.123123", "key_26_kernel_click_time_average": "12.13", "key_9_kernel_response_time": "12.23", "key_26_kernel_response_time": "1231.123123", "cpu_average": "12.13", "ram_average": "12.23", "battery_use": "12.23", "comment": "testsdfasdfdafdafdasf asdfas f", "show_in_chart": 0 } @apiSuccessExample {json} Success-Response: { "code": 0, "message": "ok" } """ params = parse_json_form('data_show_response_log') data = DataShowResponseLogBusiness.update(id, params) return { "message": "更新成功", "code": data }
def response_kernel_update_handler(id): """ @api {post} /v1/datashow/response/kernel/{id:int} 修改 响应时间_内核录屏 @apiName ModifyDataShowResponseKernel @apiGroup 自动化测试 @apiDescription 修改 响应时间_内核录屏 @apiParam {int} data_source 数据来源 @apiParam {int} phone_model 手机类型 @apiParam {int} apk_version apk 版本 @apiParam {int} kernel_version 内核版本 @apiParam {int} system_version 系统版本 @apiParam {int} thesaurus_version 词库版本 @apiParam {int} corpus_version 语料库版本 @apiParam {string} key_9_and_26 9键26键 @apiParam {string} average 平均值 @apiParam {string} line_90_percent 90% Line @apiParam {string} line_95_percent 95% Line @apiParam {string} comment 备注 @apiParam {int} show_in_chart 是否显示在图表中,0:保存,1:不保存 @apiParamExample {json} Request-Example: { "data_source": 1, "phone_model": 2, "apk_version": 3, "kernel_version": 4, "system_version": 5, "thesaurus_version": 6, "corpus_version": 7, "key_9_and_26": "1231.123123", "average": "12.13", "line_90_percent": "12.23", "line_95_percent": "12.23", "comment": "asdfasdfasdf", "show_in_chart": 0 } @apiSuccessExample {json} Success-Response: { "code": 0, "message": "ok" } """ params = parse_json_form('data_show_response_kernel_record_create') data = DataShowResponseKernelRecordBusiness.update(id, params) return { "message": "更新成功", "code": data }
def monkey_package_create_handler(): """ @api {post} /v1/monkey/package 上传 Monkey Package @apiName UploadMonkeyPackage @apiGroup 自动化测试 @apiDescription 上传 Monkey 测试包 @apiParam {int} user_id 上传用户 ID @apiParam {string} oss_url 存放 apk 的 oss 路径 @apiParam {int} test_type 测试类型,1:monkey,2:performance @apiParamExample {json} Request-Example: { "user_id": 1, "oss_url": "http://js.xiazaicc.com/apk3/mengtuiv2.4.7_downcc.com.apk" } @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "code": 0, "data": [], "message": "ok" } """ (name, package_name, oss_url, picture, version, default_activity, user_id, test_type) = parse_json_form('monkey_package_create') apk_info = tool_trpc.requests('post', '/tool/apk/analysis', body={"apk_download_url": oss_url}) package_name = apk_info.get('package_name') default_activity = apk_info.get('default_activity') version = apk_info.get('version_name') picture = apk_info.get('icon') name = apk_info.get('label') size = apk_info.get('size') or '' ret, msg = MonkeyPackageBusiness.create(name=name, package_name=package_name, oss_url=oss_url, picture=picture, version=version, default_activity=default_activity, user_id=user_id, size=size, test_type=test_type) response = dict(code=ret, message=msg) return response
def response_first_update_handler(id): """ @api {post} /v1/datashow/correction/first/{id:int} 修改 首页响应准确率 @apiName ModifyDataShowFirstPageWord @apiGroup 自动化测试 @apiDescription 修改 首页响应准确率 @apiParam {int} data_source 数据来源 @apiParam {int} phone_model 手机类型 @apiParam {int} apk_version apk 版本 @apiParam {int} kernel_version 内核版本 @apiParam {int} system_version 系统版本 @apiParam {int} thesaurus_version 词库版本 @apiParam {int} corpus_version 语料库版本 @apiParam {string} key_9_and_26 9键26键 @apiParam {string} first_word_correct_rate 首词准确率 @apiParam {string} first_page_correct_rate 首页准确率 @apiParam {string} comment 备注 @apiParam {int} show_in_chart 是否显示在图表中,0:保存,1:不保存 @apiParamExample {json} Request-Example: { "data_source": 1, "phone_model": 4, "apk_version": 3, "kernel_version": 4, "system_version": 5, "thesaurus_version": 6, "corpus_version": 7, "key_9_and_26": "1231.123123", "first_word_correct_rate": "12.13", "first_page_correct_rate": "12.23", "comment": "testsdfasdfdafdafdasf asdfas f", "show_in_chart": 0 } @apiSuccessExample {json} Success-Response: { "code": 0, "message": "ok" } """ params = parse_json_form('data_show_first_page_first_word_correct_rate_create') data = DataShowFirstPageFirstWordCorrectRateBusiness.update(id, params) return { "message": "更新成功", "code": data }
def monkey_update_handler(id): """ @api {post} /v1/monkey/:id 更新 Monkey 状态 @apiName UpdateMonkey @apiGroup 自动化测试 @apiDescription 更新 Monkey 运行状态 @apiParam {string} [end_time] Monkey 结束时间 @apiParam {int} [process Monkey] 运行的进度 1-100 @apiParam {int} [jenkins_url] 当前测试的 Jenkins url @apiParam {int} [status] 测试的状态 @apiParam {int} [app_version] 测试的实际的 app 版本号 @apiParam {int} [begin_time] 测试开始时间 @apiParam {int} [report_url] 测试报告地址 @apiParam {int} [run_time] 测试运行时间 @apiParam {int} [actual_run_time] 测试实际运行时间 @apiParam {int} [download_app_status] 下载 app 的结果,0:未开始,1:成功,2:失败 @apiParamExample {json} Request-Example: { "download_app_status": 1 } @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "code": 0, "data": [], "message": "ok" } """ (end_time, process, jenkins_url, status, app_version, begin_time, report_url, run_time, actual_run_time, download_app_status) = parse_json_form('monkey_update') ret, msg = MonkeyBusiness.update(id=id, end_time=end_time, process=process, jenkins_url=jenkins_url, status=status, app_version=app_version, begin_time=begin_time, report_url=report_url, run_time=run_time, actual_run_time=actual_run_time, download_app_status=download_app_status) return {"code": ret, "message": msg}
def monkey_start_handler(): """ @api {post} /v1/monkey/start 启动 Monkey 测试 @apiName GetMonkeyDeviceAll @apiGroup 自动化测试 @apiDescription 启动 Monkey 测试 @apiParam {int} user_id required 用户 ID,启动用户的 ID @apiParam {list} mobile_infos 测试使用的设备相关的信息 @apiParam {int} type_id Monkey 测试类型,1:mix,2:dfs,3:可配置模式 @apiParam {int} run_time 运行时间,单位 min @apiParam {int} system_device 是否是系统设备,1:是,2:否 @apiParam {int} login_required 是否需要登录,1:是,2:否 @apiParam {string} login_username 登录用户名信息 @apiParam {string} login_password 登录用户名密码 @apiParam {int} app_id 要测试的app id @apiParam {int} app_install_required 是否需要安装 app,1:是,2:否 @apiParamExample {json} Request-Example: { "user_id": 1, "mobile_infos": [ { "mobile_id": "ZTEC880U", "mobile_version": "android 7.0", "mobile_model": "os105", "mobile_resolution": "1080*1080" } ], "system_device": 0, "login_required": 0, "login_username": "", "login_password": "", "type_id": 1, "run_time": 1, "app_id": 1, "app_install_required": 1 } @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "code": 0, "data": [], "message": "ok" } """ (user_id, mobile_infos, type_id, run_time, system_device, login_required, login_username, login_password, app_id, app_install_required) = parse_json_form('monkey_start') parameters = { "system_device": system_device, "app": { "user_id": user_id, "app_id": app_id }, "login": { "required": login_required, "username": login_username, "password": login_password, } } ret, msg = MonkeyBusiness.start_monkey(user_id, mobile_infos, type_id, run_time, system_device, login_required, login_username, login_password, app_id, parameters, app_install_required) return {"code": ret, "message": msg}