예제 #1
0
def module_add():
    r = request.form
    pm = ProductModule()
    pd = r.get('pd', '')
    pid = r.get('pid', '')
    name = r.get('name', '')
    nt = r.get('nt', '')
    if pd == "" or pid == "" or name == "" or nt == "":
        return common_response(data='', err=500, msg="参数错误,请检查!")
    _id = get_mongo_index('product_module_index')
    d = {
        "_id": _id,
        "pd": pd,
        "name": name,
        "pid": pid,
        "nt": nt,
        "st": _id,
        "create_time": time.time(),
        "update_time": time.time()
    }
    try:
        data = pm.table.insert_one(d)
        return common_response(data={"_id": data.inserted_id}, err=0, msg="添加模块成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg=e)
예제 #2
0
def add():
    r = request.form
    pd = Product()
    name = r.get('name', None)
    if name is None:
        return common_response(data={}, err=500, msg='缺少产品名称!')
    check = pd.table.find_one({"name": name})
    if check is not None:
        return common_response(data=check, err=500, msg='产品名称已存在!')
    try:
        d = {
            "_id": get_mongo_index('products'),
            "name": name,
            "category": r.get('category', None),
            "link": r.get('link', None),
            "desc": r.get('desc', None),
            "owner": current_user.username,
            "create_time": time.time(),
            "update_time": time.time()
        }
        _id = pd.table.insert_one(d)
        return common_response(data={"_id": _id.inserted_id, "name": name}, err=0, msg='产品添加成功!')
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data={}, err=500, msg=e)
예제 #3
0
def version():
    r = request
    pv = ProductVersion()
    if r.method == 'POST':
        r = request.form
        product_id = r.get('product_id', '')
        ver = r.get('version', '')
        if product_id.strip() == "":
            return common_response(data='', err=500, msg="产品ID不能为空!")
        if ver.strip() == "":
            return common_response(data='', err=500, msg="产品版本不能为空!")
        product_version = pv.table.find_one({"pd": product_id, "ver": ver})
        if product_version is not None:
            return common_response(data='', err=500, msg="产品版本已存在!")
        d = {
            "_id": get_mongo_index('product_version_index'),
            "pd": product_id,
            "ver": ver
        }
        try:
            data = pv.table.insert_one(d)
            return common_response(data={"_id": data.inserted_id}, err=0, msg="添加产品版本成功!")
        except Exception as e:
            app.logger.error(str(e))
            return common_response(data='', err=500, msg="添加产品版本失败!")
예제 #4
0
def update_module():
    r = request.form
    _id = r.get('_id', "")
    st = r.get('st', "")
    pid = r.get('pid', "")
    nt = r.get('nt', "")
    if _id == "" or st == "" or pid == "":
        return common_response(data='', err=500, msg="参数错误,请检查!")
    pm = ProductModule()
    try:
        _query = {
            "_id": int(_id)
        }
        _update = {
            "$set": {
                "st": int(st),
                "pid": pid
            }
        }
        if nt != "":
            _update['$set']['nt'] = nt
        res = pm.table.update_one(_query, _update)
        print(res.raw_result)
        return common_response(data='', err=0, msg="更新排序成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg=e)
예제 #5
0
파일: Run.py 프로젝트: zlychelsea/TestKiss
def delete(run_id):
    rc = Run()
    try:
        result = rc.table.delete_one({"_id": int(run_id)})
        return common_response(data=result.raw_result, err=0, msg='删除成功!')
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg='删除job失败!')
예제 #6
0
def pd_ver():
    r = request.args
    pv = ProductVersion()
    product_id = r.get('product_id', '')
    try:
        data = pv.table.find({"pd": product_id})
        data = list_mongo_res(data)
        return common_response(data=data, err=0, msg="请求成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg="请求失败!")
예제 #7
0
def delete():
    pd = Product()
    r = request.form
    _id = r.get('_id', "")
    if _id == "":
        return common_response(data='', err=500, msg="id不能为空!")
    try:
        res = pd.table.delete_one({"_id": int(_id)})
        return common_response(data=res.raw_result, err=0, msg="删除成功")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg="删除失败!")
예제 #8
0
def query():
    r = request.args
    pl = Plan()
    pd = r.get('pd', '').strip()
    ver = r.get('pd_ver', '').strip()
    try:
        data = pl.table.find({"pd": pd, "pd_ver": ver})
        data = list_mongo_res(data)
        return common_response(data=data, err=0, msg="请求成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg="请求失败!")
예제 #9
0
def update():
    pl = Plan()
    pv = ProductVersion()
    if request.method == "GET":
        r = request.args
        pd = Product()
        product_id = r.get('product_id', '')
        plan_id = r.get('plan_id', '')
        pd_ver = pv.table.find({"pd": product_id}, {"ver": 1}).sort([("_id", -1)]).limit(20)
        data = pl.table.find_one({"_id": int(plan_id)})
        prod = pd.table.find_one({"_id": int(product_id)})
        return render_template('plan/plan.edit.html', product=prod, versions=pd_ver, plan=data)

    if request.method == "PUT":
        r = request.form
        plan_id = r.get('plan_id', '')
        name = r.get('plan_name', '')
        product_id = r.get('product_id', '')
        pd_ver = r.get('pd_ver', '')
        plan_type = r.get('plan_type', '')
        plan_detail = r.get('plan_detail', '')
        err = {}
        if plan_id.strip() == "":
            err['plan_id'] = "plan_id 不能为空!"
        if name.strip() == "":
            err['name'] = "计划名称不能为空!"
        if product_id.strip() == "":
            err['product_id'] = "产品ID不能为空!"
        if pd_ver.strip() == "":
            err['pd_ver'] = "产品版本不能为空!"
        if plan_type.strip() == "":
            err['plan_type'] = "计划类型不能为空!"
        if plan_detail.strip() == "":
            err['plan_detail'] = "计划详情不能为空!"
        if len(err) > 0:
            return common_response(data=err, err=500, msg="参数错误,请查看接口返回!")
        try:
            q = {"_id": int(plan_id)}
            d = {
                "$set": {
                    "name": name,
                    "pd_ver": pd_ver,
                    "type": plan_type,
                    "detail": plan_detail,
                    "update_time": time.time()
                }
            }
            data = pl.table.update_one(q, d)
            return common_response(data={"result": data.raw_result}, err=0, msg="更新成功!!")
        except Exception as e:
            app.logger.error(str(e))
            return common_response(data='', err=500, msg='更新失败!')
예제 #10
0
def delete_module():
    r = request.form
    _id = r.get('_id', "")
    if _id == "":
        return common_response(data='', err=500, msg="参数错误,请检查!")
    pm = ProductModule()
    try:
        _query = {
            "_id": int(_id)
        }
        pm.table.delete_one(_query)
        return common_response(data='', err=0, msg="删除成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg=e)
예제 #11
0
def add():
    pl = Plan()
    pv = ProductVersion()
    if request.method == "GET":
        r = request.args
        pd = Product()
        product_id = r.get('product_id', '')
        pd_ver = pv.table.find({"pd": product_id}, {"ver": 1}).sort([("_id", -1)]).limit(20)
        prod = pd.table.find_one({"_id": int(product_id)})
        return render_template('plan/plan.add.html', product=prod, versions=pd_ver)

    if request.method == "POST":
        r = request.form
        name = r.get('plan_name', '')
        product_id = r.get('product_id', '')
        pd_ver = r.get('pd_ver', '')
        plan_type = r.get('plan_type', '')
        plan_detail = r.get('plan_detail', '')
        err = {}
        if name.strip() == "":
            err['name'] = "计划名称不能为空!"
        if product_id.strip() == "":
            err['product_id'] = "产品ID不能为空!"
        if pd_ver.strip() == "":
            err['pd_ver'] = "产品版本不能为空!"
        if plan_type.strip() == "":
            err['plan_type'] = "计划类型不能为空!"
        if plan_detail.strip() == "":
            err['plan_detail'] = "计划详情不能为空!"
        if len(err) > 0:
            return common_response(data=err, err=500, msg="参数错误,请查看接口返回!")
        try:
            d = {
                "_id": get_mongo_index('plans'),
                "name": name,
                "pd": product_id,
                "pd_ver": pd_ver,
                "type": plan_type,
                "detail": plan_detail,
                "author": current_user.username,
                "create_time": time.time(),
                "update_time": time.time()
            }
            data = pl.table.insert_one(d)
            return common_response(data={"_id": data.inserted_id}, err=0, msg="添加成功!")
        except Exception as e:
            app.logger.error(str(e))
            return common_response(data='', err=500, msg='添加失败')
예제 #12
0
def delete():
    r = request.form
    pl = Plan()
    rc = Run()
    _id = r.get("_id", '')
    if _id.strip() == "":
        return common_response(data='', err=500, msg='_id 参数不能为空!')
    check = rc.table.find_one({"pl": _id})
    if check is not None:
        return common_response(data='', err=500, msg="计划下有执行,请先删除执行!")
    try:
        data = pl.table.delete_one({"_id": int(_id)})
        return common_response(data=data.raw_result, err=0, msg='删除成功!')
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg="删除失败!")
예제 #13
0
파일: Run.py 프로젝트: zlychelsea/TestKiss
def update_run_stat():
    r = request.form
    rc = Run()
    run_id = r.get('run_id', '').strip()
    stat = r.get('stat', '').strip()
    if run_id == "":
        return common_response(data='', err=500, msg='run_id 不能为空!')
    if stat not in ['未开始', '执行中', '已完成']:
        return common_response(data='', err=500, msg='状态不合法!')
    try:
        data = rc.table.update_one(
            {"_id": int(run_id)},
            {"$set": {
                "stat": stat,
                "end_time": time.time()
            }})
        return common_response(data=data.raw_result, err=0, msg="更新状态成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg="更新状态失败!")
예제 #14
0
파일: Run.py 프로젝트: zlychelsea/TestKiss
def update_run_case():
    r = request.form
    rc = Run()
    run_id = r.get('run_id', '')
    case_id = r.get('case_id', '')
    old_stat = r.get('old_stat', '').strip()
    new_stat = r.get('new_stat', '').strip()
    if run_id.strip() == "":
        return common_response(data='', err=500, msg="run_id 不能为空!")
    if case_id.strip() == "":
        return common_response(data='', err=500, msg="case_id 不能为空!")
    if old_stat == "":
        return common_response(data='', err=500, msg="old_stat 不能为空!")
    if new_stat == "":
        return common_response(data='', err=500, msg="new_stat 不能为空!")
    try:
        q = {"_id": int(run_id)}
        u = {
            "$inc": {
                "progress." + old_stat + ".count": -1,
                "progress." + new_stat + ".count": 1
            },
            "$set": {
                "detail." + case_id + ".stat": new_stat
            }
        }
        res = rc.table.update_one(q, u)
        return common_response(data=res.raw_result, err=0, msg="更新case状态成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg="更新case状态失败")
예제 #15
0
def update():
    pd = Product()
    r = request.form
    _id = r.get('_id', "")
    name = r.get("name", "")
    if _id == "" or name == "":
        return common_response(data='', err=500, msg="id不能为空!")
    query = {
        "_id": int(_id)
    }
    upd = {
        "$set": {
            "name": name,
            "link": r.get("link"),
            "desc": r.get("desc")
        }
    }
    try:
        pd.table.update_one(query, upd)
        return common_response(data='', err=0, msg="更新成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg=e)
예제 #16
0
파일: Run.py 프로젝트: zlychelsea/TestKiss
def update_run_case_info():
    r = request.form
    rc = Run()
    run_id = r.get('run_id', '').strip()
    case_id = r.get('case_id', '').strip()
    bug = r.get('bug', '')
    comment = r.get('comment', '')
    if run_id.strip() == "":
        return common_response(data='', err=500, msg="run_id 不能为空!")
    if case_id == "":
        return common_response(data='', err=500, msg="case_id 不能为空!")
    try:
        q = {"_id": int(run_id)}
        d = {
            "$set": {
                "detail." + case_id + ".bugs": bug,
                "detail." + case_id + ".comment": comment
            }
        }
        res = rc.table.update_one(q, d)
        return common_response(data=res.raw_result, err=0, msg="更新成功!")
    except Exception as e:
        app.logger.error(str(e))
        return common_response(data='', err=500, msg="更新失败,请重试!")
예제 #17
0
파일: Run.py 프로젝트: zlychelsea/TestKiss
def add():
    if request.method == "GET":
        r = request.args
        product_id = r.get('product_id', '')
        plan_id = r.get('plan_id', '')
        if product_id.strip() == '':
            flash("产品ID不存在!")
            return redirect(url_for('plan.product'))
        if plan_id.strip() == "":
            flash("计划不存在,请重新选择!")
            return redirect(request.referrer)
        pd = Product()
        pl = Plan()
        product = pd.table.find_one({"_id": int(product_id)})
        plan_ = pl.table.find_one({"_id": int(plan_id)})
        if product is None:
            return redirect(url_for('case.dashboard'))
        pm = ProductModule()
        modules = pm.get_module_tree({"pd": str(product_id)}, 'all')
        return render_template('run/run.add.html',
                               product=product,
                               modules=modules,
                               plan=plan_)

    if request.method == "POST":
        r = request.form
        rc = Run()
        product_id = r.get("product_id", "")
        plan_id = r.get("plan_id", "")
        run_name = r.get('run_name', '')
        assign_to = r.get('assign_to', '')
        cid = r.get('cid', '')
        err = {}
        if product_id.strip() == "":
            err['product_id'] = "产品ID 不能为空!"
        if plan_id.strip() == "":
            err['plan_id'] = "计划ID 不能为空!"
        if run_name.strip() == "":
            err["run_name"] = "执行名称不能为空!"
        if assign_to.strip() == "":
            err['assign_to'] = "用例执行者不能为空!"
        if cid.strip() == "":
            err['cit'] = "选择用例为空,请先选择用例!"
        if len(err) > 0:
            return common_response(data=err, err=500, msg="参数错误,请查看接口返回!")
        cases = cid.split(',')
        ids = list(map(int, cases))
        detail = {}
        for case in cases:
            detail[case] = {
                "stat": "init",
                "comment": "",
                "bugs": "",
                "update_time": ""
            }
        case_count = len(cases)
        progress = {
            "init": {
                "name": "待执行",
                "count": case_count
            },
            "stop": {
                "name": "暂停",
                "count": 0
            },
            "abort": {
                "name": "废弃",
                "count": 0
            },
            "fail": {
                "name": "失败",
                "count": 0
            },
            "pass": {
                "name": "通过",
                "count": 0
            },
            "total": {
                "name": "总数",
                "count": case_count
            },
            "percent": {
                "name": "百分比",
                "count": "0%"
            }
        }
        d = {
            "_id": get_mongo_index('run_index'),
            "pd": product_id,
            "pl": plan_id,
            "name": run_name,
            "assign": assign_to,
            "stat": "未开始",
            "progress": progress,
            "start_time": "",
            "end_time": "",
            "ids": ids,
            "detail": detail
        }
        try:
            data = rc.table.insert_one(d)
            return common_response(data={"_id": data.inserted_id},
                                   err=0,
                                   msg="添加执行成功!")
        except Exception as e:
            app.logger.error(str(e))
            return common_response(data='', err=500, msg=str(e))
예제 #18
0
def categories():
    pc = ProductCategory()
    if request.method == "GET":
        r = request.args
        page = r.get('page', 1)
        if page is None:
            page = 1
        data = pc.get_list({}, int(page))
        params = get_query_url(request)
        return render_template('product/categories.html', categories=data, url=request.path, params=params)

    if request.method == "POST":
        r = request.form
        try:
            check = pc.table.find_one({"name": r.get('name')})
            if check is not None:
                return common_response(data='', err=500, msg="产品分类已经存在!")
            if r.get('name') is None:
                return common_response(data='', err=500, msg="产品分类不能为空!")
            d = {
                "_id": get_mongo_index('product_category_index'),
                "name": r.get('name'),
                "desc": r.get('desc'),
                "create_time": time.time(),
                "update_time": time.time()
            }
            pc.table.insert(d)
            return common_response(data={}, err=0, msg="添加成功!")
        except Exception as e:
            app.logger.error(str(e))
            return common_response(data='', err=500, msg=e)

    if request.method == "PUT":
        r = request.form
        _id = r.get('_id', None)
        if _id is None:
            return common_response(data='', err=500, msg="_id不能为空!")

        query = {"_id": int(_id)}
        _update = {"$set": {
            "name": r.get('name'),
            "desc": r.get('desc'),
            "update_time": time.time()
            }
        }
        try:
            pc.table.update_one(query, _update)
            return common_response(data={}, err=0, msg="更新成功")
        except Exception as e:
            app.logger.error(str(e))
            return common_response(data='', err=500, msg=e)

    if request.method == "DELETE":
        r = request.form
        _id = r.get('_id')
        if _id is None:
            return common_response(data='', err=500, msg="id不能为空!")
        try:
            pc.table.delete_one({"_id": int(_id)})
            return common_response(data='', err=0, msg="删除成功")
        except Exception as e:
            app.logger.err(e)
            return common_response(data='', err=500, msg="删除失败!")
예제 #19
0
def categories_all():
    pc = ProductCategory()
    res = pc.table.find({}, {"_id": 1, "name": 1})
    data = list_mongo_res(res)
    return common_response(data=data, err=0, msg="Success")