Пример #1
0
def monkey_index_handler():
    limit, offset = parse_list_args()

    monkey_id = request.args.get('monkey_id')

    if monkey_id:
        data = MonkeyBusiness.query_all_json()
        return json_list_render(0, data, limit, offset)

    data = MonkeyBusiness.query_all_json(limit, offset)
    return {"code": 0, "data": data}
Пример #2
0
def monkey_test_name_get_handler():
    """
    @api {get} /v1/monkey/name 根据 测试类型 获取测试列表
    @apiName GetAutotestListByTestType
    @apiGroup 自动化测试
    @apiDescription 根据 测试类型 获取测试列表
    @apiParam {int} [test_type] 测试类型
    @apiParamExample {json} Request-Example:
    ?test_type=2
    @apiSuccessExample {json} Success-Response:
    HTTP/1.1 200 OK
    {
      "code": 0,
      "data": [
        {
          "id": 163,
          "name": "163-2019-09-19 15:16:54-xxxx-1.5.5.1"
        },
      ],
      "message": "ok"
    }
    """
    test_type = request.args.get('test_type', 1)
    response = {
        "code": 0,
        "data": MonkeyBusiness.get_all_name(test_type)
    }
    return response
Пример #3
0
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
    )
Пример #4
0
def performance_test_get_by_performance_id_handler():
    """
    @api {get} /v1/monkey/test 根据 monkey id 和 测试场景 获取场景的设备测试信息列表
    @apiName GetAutotestListByMonkeyIdAndTestType
    @apiGroup 自动化测试
    @apiDescription 根据 monkey id 和 测试场景 获取场景的设备测试信息列表
    @apiParam {int} monkey_id 测试 id
    @apiParam {string} run_type 测试场景
    @apiParamExample {json} Request-Example:
    ?performance_id=260
    @apiSuccessExample {json} Success-Response:
    HTTP/1.1 200 OK
    {
      "code": 0,
      "data": [
        {
          "ZTEC880U": [
            {
              "cpu_average": 0.0,
              "cpu_top": 0.0,
              "creation_time": "2019-09-19 15:41:46",
              "heap_alloc_average": 0.0,
              "heap_alloc_top": 0.0,
              "heap_size_average": 0.0,
              "heap_size_top": 0.0,
              "id": 12,
              "modified_time": "2019-09-19 15:41:45",
              "performance_id": 260,
              "rss_top": 0.0,
              "run_time": 1,
              "run_type": "qjp"
            }
          ]
        }
      ],
      "message": "ok"
    }
    """
    monkey_id = request.args.get('monkey_id')
    run_type = request.args.get('run_type')
    if not monkey_id:
        raise FieldMissingException('monkey_id is required')

    if not run_type:
        raise FieldMissingException('run_type is required')

    response = {
        "code":
        0,
        "data":
        MonkeyBusiness.get_performance_by_monkey_id_and_type(
            monkey_id, run_type)
    }
    return response
Пример #5
0
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}
Пример #6
0
def monkey_all_handler():
    """
    @api {get} /v1/monkey/all 查询 Monkey 测试列表
    @apiName GetMonkeyAll
    @apiGroup 自动化测试
    @apiDescription 查询 所有的 monkey 测试信息
    @apiParam {int} [page_size] 分页-单页数目
    @apiParam {int} [page_index] 分页-页数
    @apiParam {int} [user_id] 用户 ID,获取当前用户 ID 的 monkey 测试信息
    @apiParam {int} [id] Monkey ID,根据 ID 获取 monkey 信息
    @apiParamExample {json} Request-Example:
    {
       "page_index": 1,
       "page_size": 10,
       "user_id": 1
    }
    @apiSuccessExample {json} Success-Response:
     HTTP/1.1 200 OK
     {
        "code": 0,
        "data": [
            {
                "actual_run_time": "",
                "app_default_activity": "com.mengtuiapp.mall.SplashActivity",
                "app_id": 86,
                "app_install_required": 1,
                "app_name": "萌推",
                "app_oss_url": "http://tcloud-static.ywopt.com/static/00c43b89-f68d-4348-940d-f4dc36979f47.apk",
                "app_package_name": "com.mengtuiapp.mall",
                "app_picture": "iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAABCFBMVEX/AEj/6YT/9fj/7PH/9/n/8/b/6O",
                "app_size": "14.43",
                "app_version": "2.4.7",
                "begin_time": "2019-07-24 11:40:42",
                "cancel_status": 1,
                "creation_time": "2019-07-24 11:40:42",
                "download_app_status": 1,
                "end_time": "Wed, 24 Jul 2019 13:44:15 GMT",
                "id": 111,
                "jenkins_url": "http://ci.automancloud.com/job/monkey_autotest/325/",
                "login_password": "",
                "login_required": 0,
                "login_username": "",
                "mobile_ids": "Y2J5T17410004213",
                "monkey_device_status": [
                    {
                        "activity_all": "[]",
                        "activity_count": 0,
                        "activity_tested": "[]",
                        "activity_tested_count": 0,
                        "anr_count": 3,
                        "begin_time": "2019-07-24 11:40:54",
                        "cancel_status": 1,
                        "crash_count": 0,
                        "current_stage": "通过",
                        "device_connect_status": 1,
                        "end_time": "2019-07-24 13:41:51",
                        "exception_count": 0,
                        "exception_run_time": 0,
                        "id": 178,
                        "login_app_status": 1,
                        "mobile_id": 43,
                        "mobile_model": "HUAWEI VKY-AL00",
                        "mobile_resolution": "2560 x 1440",
                        "mobile_serial": "Y2J5T17410004213",
                        "mobile_use_times": 16,
                        "mobile_version": "7.0",
                        "monkey_id": 111,
                        "process": 100,
                        "run_time": 120,
                        "running_error_reason": "",
                        "running_status": 1,
                        "screen_lock_status": 1,
                        "setup_install_app_status": 1,
                        "setup_uninstall_app_status": 1,
                        "start_app_status": 1,
                        "teardown_uninstall_app_status": 1
                    }
                ],
                "package_name": "com.mengtuiapp.mall",
                "parameters": "{'system_device': 0, 'app': {'user_id': 93, 'app_id': 86}, 'login': {
                                'required': 0, 'username': '', 'password': ''}}",
                "process": 100,
                "report_url": "",
                "run_time": 0,
                "status": 0,
                "system_device": 0,
                "type_id": 1,
                "user_id": 93,
                "user_nickname": "孟伟"
            }
        ],
        "message": "ok",
        "page_index": 1,
        "page_size": 10,
        "total": 66
    }
    """
    page_size, page_index = parse_list_args2()
    page_size = page_size or 10
    page_index = page_index or 1

    user_id = request.args.get('user_id')
    id = request.args.get('id')

    monkeys, count = MonkeyBusiness.get_all_monkeys(id, user_id, page_size,
                                                    page_index)

    return {
        "code": 0,
        "data": monkeys,
        "page_size": page_size,
        "page_index": page_index,
        "total": count
    }
Пример #7
0
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}