コード例 #1
0
ファイル: Product.py プロジェクト: zlychelsea/TestKiss
def lists():
    pd = Product()
    if request.method == "GET":
        r = request.args
        page = r.get('page', 1)
        if page is None:
            page = 1
        size = r.get('size', 10)
        if size is None:
            size = 10
        data = pd.get_list({}, int(page), int(size))
        params = get_query_url(request)
        return render_template('product/lists.html', products=data, url=request.path, params=params)
コード例 #2
0
ファイル: Run.py プロジェクト: zlychelsea/TestKiss
def detail():
    r = request.args
    pd = Product()
    pm = ProductModule()
    pl = Plan()
    rc = Run()
    run_id = r.get('run_id', '')
    if run_id.strip() == "":
        flash("run_id 不能为空!", "err")
        return redirect(request.referrer)
    rc.table.update_one({"_id": int(run_id)},
                        {"$set": {
                            "stat": "执行中",
                            "start_time": time.time()
                        }})
    data = rc.table.find_one({"_id": int(run_id)})
    product_id = data['pd']
    plan_id = data['pl']
    product_ = pd.table.find_one({"_id": int(product_id)})
    plan_ = pl.table.find_one({"_id": int(plan_id)})
    case_ids = data['ids']
    modules = pm.get_run_tree({"pd": str(product_id)}, case_ids)
    return render_template('run/run.detail.html',
                           product=product_,
                           modules=modules,
                           plan=plan_,
                           run=data)
コード例 #3
0
ファイル: Product.py プロジェクト: zlychelsea/TestKiss
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)
コード例 #4
0
def lists():
        r = request.args
        pl = Plan()
        pd = Product()
        page = r.get('page', 1)
        if page is None:
            page = 1
        size = r.get('size', 10)
        if size is None:
            size = 10
        product_id = r.get('product_id', '')
        if product_id == "":
            flash("产品 product_id 不能为空!")
            return redirect(url_for('plan.product'))
        prod = pd.table.find_one({"_id": int(product_id)})
        if prod is None:
            flash("产品不存在,请重新选择!")
            return redirect(url_for('plan.product'))
        search = r.get('search', None)
        if search is None:
            search = {
                "pd": product_id
            }
        else:
            search = {
                "pd": product_id,
                "name": {
                    "$regex": search
                }
            }
        plans = pl.get_list(search, int(page), int(size))
        params = get_query_url(request)
        return render_template('plan/plan.list.html', product=prod, plans=plans, url=request.path, params=params)
コード例 #5
0
def product():
        r = request.args
        pd = Product()
        page = r.get('page', 1)
        size = r.get('size', 16)
        if page is None:
            page = 1
        search = r.get('search', None)
        if search is None:
            search = {}
        else:
            search = {
                "name": {
                    "$regex": search
                }
            }
        products = pd.get_list(search, page, size)
        params = get_query_url(request)
        return render_template('plan/choose_pd.html', products=products, url=request.path, params=params)
コード例 #6
0
ファイル: Product.py プロジェクト: zlychelsea/TestKiss
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="删除失败!")
コード例 #7
0
def detail():
    r = request.args
    plan_id = r.get('plan_id', '')
    product_id = r.get('product_id', '')
    if plan_id.strip() == "":
        flash("plan_id 不能为空!")
        return redirect(request.referrer)
    pd = Product()
    pl = Plan()
    prod = pd.table.find_one({"_id": int(product_id)})
    data = pl.table.find_one({"_id": int(plan_id)})
    return render_template('plan/plan.detail.html', plan=data, product=prod)
コード例 #8
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='更新失败!')
コード例 #9
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='添加失败')
コード例 #10
0
def detail():
    r = request.args
    pd = Product()
    pm = ProductModule()
    pl = Plan()
    rc = Run()
    run_id = r.get('run_id', '')
    if run_id.strip() == "":
        flash("run_id 不能为空!", "err")
        return redirect(request.referrer)
    data = rc.table.find_one({"_id": int(run_id)})
    product_id = data['pd']
    plan_id = data['pl']
    product_ = pd.table.find_one({"_id": int(product_id)})
    plan_ = pl.table.find_one({"_id": int(plan_id)})
    case_ids = data['ids']
    modules = pm.get_run_tree({"pd": str(product_id)}, case_ids)
    progress = []
    p = data['progress']
    progress.append(p['stop']['count'])
    progress.append(p['abort']['count'])
    progress.append(p['fail']['count'])
    progress.append(p['pass']['count'])
    progress.append(p['init']['count'])
    pct = []
    pct.append(
        float("%.2f" % (p['init']['count'] / p['total']['count'])) * 100)
    pct.append(
        float("%.2f" % (p['pass']['count'] / p['total']['count'])) * 100)
    pct.append(
        float("%.2f" % (p['fail']['count'] / p['total']['count'])) * 100)
    pct.append(
        float("%.2f" % (p['abort']['count'] / p['total']['count'])) * 100)
    pct.append(
        float("%.2f" % (p['stop']['count'] / p['total']['count'])) * 100)
    return render_template('report/report.detail.html',
                           product=product_,
                           plan=plan_,
                           modules=modules,
                           run=data,
                           progress=progress,
                           pct=pct)
コード例 #11
0
ファイル: Home.py プロジェクト: zlychelsea/TestKiss
def dashboard():
    user_info = UserInfo()
    user_num = user_info.count_user()
    pd = Product()
    product_num = pd.table.find().count()
    cs = Case()
    case_num = cs.table.find().count()
    rc = Run()
    run_num = rc.table.find().count()
    top = cs.get_top_user()
    case_statistic = cs.get_case_statistic()
    d = {
        "total_user": user_num,
        "total_product": product_num,
        "total_case": case_num,
        "total_run": run_num,
        "top": top,
        "case_statistic": case_statistic
    }
    return render_template('home/dashboard.html', d=d)
コード例 #12
0
ファイル: Run.py プロジェクト: zlychelsea/TestKiss
def lists():
    r = request.args
    pd = Product()
    pl = Plan()
    rc = Run()
    page = r.get('page', 1)
    size = r.get('size', 16)
    if page is None:
        page = 1
    if size is None:
        size = 16
    product_id = r.get('product_id', '')
    plan_id = r.get('plan_id', '')
    if product_id.strip() == "":
        flash("产品 product_id 不能为空!")
        return redirect(url_for('plan.product'))
    if plan_id.strip() == "":
        flash("plan_id 不能为空!")
        return redirect(url_for('plan.lists', product_id=product_id))
    prod = pd.table.find_one({"_id": int(product_id)})
    cur_plan = pl.table.find_one({"_id": int(plan_id)})
    if prod is None:
        flash("产品不存在,请重新选择!")
        return redirect(url_for('plan.product'))
    if cur_plan is None:
        flash("计划不存在,请重新选择计划!")
        return redirect(url_for('plan.lists', product_id=product_id))
    search = r.get('search', None)
    if search is None:
        search = {"pl": plan_id}
    else:
        search = {"pl": plan_id, "name": {"$regex": search}}
    runs = rc.get_list(search, int(page), int(size))
    params = get_query_url(request)
    return render_template('run/run.list.html',
                           product=prod,
                           plan=cur_plan,
                           runs=runs,
                           url=request.path,
                           params=params)
コード例 #13
0
ファイル: Product.py プロジェクト: zlychelsea/TestKiss
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)
コード例 #14
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))