Esempio n. 1
0
def monkey_package_index_handler():
    """
    @api {get} /v1/monkey/package 查询 Monkey package 列表
    @apiName GetMonkeyPackage
    @apiGroup 自动化测试
    @apiDescription 查询 Monkey 测试的上传的包列表
    @apiParam {int} [page_size] 分页-单页大小
    @apiParam {int} [page_index] 分页-页数
    @apiParam {int} [id] Monkey 的 ID
    @apiParam {int} [user_id] 单个设备的测试 ID
    @apiParam {int} test_type 测试类型,默认为 1:monkey,性能测试需要传 2
    @apiParamExample {json} Request-Example:
    {
        "page_size": 10,
        "page_index": 1,
        "monkey_id": 1,
        "test_type": 1
    }
    @apiSuccessExample {json} Success-Response:
     HTTP/1.1 200 OK
     {
        "code": 0,
        "data": [
            {
                "default_activity": "com.mengtuiapp.mall.SplashActivity",
                "id": 3,
                "name": "萌推",
                "oss_url": "http://js.xiazaicc.com/apk3/mengtuiv2.4.7_downcc.com.apk",
                "package_name": "com.mengtuiapp.mall",
                "picture": "iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAABCFBMVEX/AEj/6YT/9fj/7PH/9/n/8/b/6O",
                "size": "",
                "upload_time": "Tue, 09 Jul 2019 17:53:31 GMT",
                "user_id": 1,
                "user_nickname": "王金龙",
                "version": "2.4.7"
            }
        ],
        "message": "ok"
    }
    """
    page_size, page_index = parse_list_args2()
    page_size = page_size or 10
    page_index = page_index or 1

    id = request.args.get('id')
    user_id = request.args.get('user_id')
    test_type = request.args.get('test_type', 1)

    if id:
        data = MonkeyPackageBusiness.query_json_by_id(id)
        return json_detail_render(0, data)
    all, count = MonkeyPackageBusiness.get_monkey_packages_by_user_id(
        user_id, page_size, page_index, test_type)
    response = dict(code=0,
                    data=all,
                    page_size=page_size,
                    page_index=page_index,
                    total=count)
    return response
Esempio n. 2
0
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
Esempio n. 3
0
def monkey_package_delete_handler(id):
    """
    @api {delete} /v1/monkey/package/:id 删除 Monkey 测试包
    @apiName DeleteMonkeyPackage
    @apiGroup 自动化测试
    @apiDescription 删除 Monkey 测试包
    @apiParam {int} id 包的 ID.
    @apiParamExample {json} Request-Example:
    {

    }
    @apiSuccessExample {json} Success-Response:
     HTTP/1.1 200 OK
     {
        "code": 0,
        "data": [],
        "message": "ok"
    }
    """
    ret, msg = MonkeyPackageBusiness.delete(id)
    return dict(code=ret, message=msg)