Beispiel #1
0
def _get_testcases_count():
    """4. 每个模块的用例统计"""
    testcasscount = []
    sql = "select moduleid from t_testcass GROUP BY moduleid"

    # 循环每一个module的id
    for id in dbfucs.query(sql):
        singeitem = {}

        # 统计count和testcases
        sql = "select * from t_testcass where moduleid = %d" % id.get(
            "moduleid")
        res = dbfucs.query(sql)
        if res:
            singeitem["count"] = len(res)  # count
            singeitem["testcases"] = res  # modules
            moduleid = id.get("moduleid")

            # 统计module
            sql = "select * from t_modules where id = %d" % moduleid
            res = dbfucs.query(sql)
            if res:
                singeitem["module"] = res[0]

            testcasscount.append(singeitem)

    return testcasscount
Beispiel #2
0
def _get_last_test_results():
    """1. 上次用例执行结果"""
    """
          "testreports": {
            "failed": {
                "count": 0,
                "data": []
            },
            "success": {
                "count": 2,
                "data": [
                    {
                        "cassid": 2,
                        "createtime": "2018-05-17 00:11:47",
                        "id": 31,
                        "result": "{\n  \"code\": 200, \n  \"data\": \"sjdh34gsalked23nlsakn45dudaj\", \n  \"msg\": \"登陆成功\"\n}\n",
                        "runtime": "0.011257",
                        "status": 0,
                        "validate": "r.status_code==200",
                        "version": 3
                    },
                    {
                        "cassid": 3,
                        "createtime": "2018-05-17 00:15:45",
                        "id": 32,
                        "result": "{\n  \"code\": 200, \n  \"msg\": \"操作成功\"\n}\n",
                        "runtime": "0.012227",
                        "status": 0,
                        "validate": "r.status_code==200",
                        "version": 3
                    }
                ]
            }
        }

    """

    # 获取上次执行的测试用例
    success_sql = "select * from t_reports where version in" \
                  " (select max(version) as version from t_reports) and status='成功'"
    failed_sql = "select * from t_reports where version in" \
                 " (select max(version) as version from t_reports) and status!='成功'"
    success_results = dbfucs.query(success_sql)
    failed_results = dbfucs.query(failed_sql)

    last_testreports = {}
    last_testreports["success"] = {
        "data": success_results,
        "count": len(success_results)
    }
    last_testreports["failed"] = {
        "data": failed_results,
        "count": len(failed_results)
    }

    return last_testreports
Beispiel #3
0
def queryproduct():
    '''
    查询产品列表
    '''
    sql = "SELECT\
                a.id as productid,\
                a.product,\
                a.`explain`,\
                ( SELECT COUNT( * ) FROM t_project WHERE t_project.productid = a.id ) AS jectnum,\
                count(c.id) as modulenum,\
                a.leader,\
                a.remark,\
                a.createtime,\
                a.updatatime\
        FROM\
              t_product AS a\
        LEFT JOIN t_project as b ON a.id = b.productid\
        LEFT JOIN t_modules as c ON c.projectid = b.id\
        GROUP BY\
              a.id	"

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #4
0
def querytcass():
    '''
    获取用例列表
    编号	名称	所属模块	描述	执行状态	责任人	备注	创建时间
    '''
    sql = "SELECT\
        t_testcass.id as testid,\
        (SELECT modules FROM t_modules WHERE id = t_testcass.moduleid) as modulename,\
        t_testcass.testname,\
        t_testcass.`explain`,\
        (select t_reports.`status` from t_reports WHERE id = t_testcass.id order by id DESC limit 1) as `status`,\
        t_testcass.leader,\
        t_testcass.remark,\
        t_testcass.createtime\
    FROM\
        t_testcass\
    LEFT JOIN t_modules ON t_testcass.moduleid = t_modules.id\
    LEFT JOIN t_reports ON t_reports.cassid = t_testcass.id"

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #5
0
def querycurrentreport():
    '''
    获取用例列表
    编号	名称	所属模块	描述	执行状态	责任人	备注	创建时间
    '''
    dictdata = request.get_json()
    cassid = dictdata["cassid"]
    sql = "select  \
           t_reports.cassid,\
           case status when 0 then 'Pass' when 1 then 'Fail' else 'Error' end as status,\
           t_reports.runtime,\
           t_reports.result,\
           t_reports.validate,\
           t_reports.createtime,\
           t_testcass.testname\
           from t_testcass INNER JOIN t_reports\
           on t_testcass.id=t_reports.cassid \
           where t_reports.cassid in (%s) \
           order by createtime desc \
            limit 0, 1" % cassid
    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #6
0
def querytcass():
    '''
    获取用例列表
    编号	名称	所属模块	描述	执行状态	责任人	备注	创建时间
    '''
    dictdata = request.get_json()
    pageNo = int(dictdata["pageNo"])
    pageSize = int(dictdata["pageSize"])
    start = (pageNo - 1) * pageSize
    sql = "SELECT\
        t_testcass.id as testid,\
        (SELECT modules FROM t_modules WHERE id = t_testcass.moduleid) as modulename,\
        (SELECT COUNT(*) FROM t_testcass ) as casenum,\
        t_testcass.testname,\
        t_testcass.explain,\
        t_testcass.request,\
        t_testcass.validate,\
        t_testcass.extract,\
        t_testcass.createtime,\
        t_testcass.testtype\
    FROM\
        t_testcass\
    LEFT JOIN t_modules ON t_testcass.moduleid = t_modules.id\
    limit %d, %d;" % (start, pageSize)

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #7
0
def runproduct():
    '''
    按产品执行所有用例
    {"idlist":"1,2"}
    '''
    dictdata = request.get_json()
    idlist = dictdata["idlist"]
    sql = "SELECT\
        t_testcass.id\
    FROM\
        t_product\
    LEFT JOIN t_project ON t_product.id = t_project.productid\
    LEFT JOIN t_modules ON t_project.id = t_modules.projectid\
    LEFT JOIN t_testcass ON t_modules.id = t_testcass.moduleid\
    WHERE t_product.id in (%s);" % idlist
    res = dbfucs.query(sql)
    jsoncasss = []
    for test in res:
        jsoncasss.append(test)
    # print(jsoncasss)
    for i in collect.collect_db_cass(jsoncasss):
        Logger.info("*" * 90)
    Logger.info("共计[%d]条测试用例执行完成!" % len(jsoncasss))
    Logger.info("*" * 90)
    response = {}
    response["code"] = 200
    response["msg"] = "成功!!!"
    return jsonify(response)
Beispiel #8
0
def queryproduct():
    '''
    查询产品列表
    '''
    sql = "SELECT\
            t_product.id as productid,\
            t_product.product,\
            t_product.`explain`,\
            (SELECT COUNT(*) FROM t_project WHERE t_project.productid = t_product.id) AS jectnum,\
            (SELECT COUNT(*) FROM t_modules WHERE t_modules.projectid = t_project.id) AS modulenum,\
            t_product.leader,\
            t_product.remark,\
            t_product.createtime,\
            t_product.updatatime\
        FROM\
            t_product\
        LEFT JOIN t_project ON t_product.id = t_project.productid\
        LEFT JOIN t_modules ON t_project.id = t_modules.projectid\
        -- LEFT JOIN t_testcass ON t_modules.id = t_testcass.moduleid\
        group by t_product.id"

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #9
0
def getreport():
    '''
    获取用例列表
    编号	名称	所属模块	描述	执行状态	责任人	备注	创建时间
    '''
    dictdata = request.get_json()
    pageNo = int(dictdata["pageNo"])
    pageSize = int(dictdata["pageSize"])
    start = (pageNo - 1) * pageSize
    sql = "select  \
           t_reports.cassid,\
           case status when 0 then 'Pass' when 1 then 'Fail' else 'Error' end as status,\
           t_reports.runtime,\
           t_reports.result,\
           t_reports.validate,\
           t_reports.createtime,\
           t_testcass.testname,\
           (SELECT COUNT(*) FROM t_reports) as reportnum\
           from t_testcass INNER JOIN t_reports\
           on t_testcass.id=t_reports.cassid \
           order by createtime desc\
            limit %d, %d" % (start, pageSize)
    res = dbfucs.query(sql)
    print(res)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #10
0
def runmodule():
    '''
    按模块执行所有用例
    {"idlist":"1,2"}
    '''
    dictdata = request.get_json()
    idlist = dictdata["idlist"]
    ids = ''
    for i in idlist:
        ids += str(i) + ","
    sql = "SELECT * FROM t_testcass WHERE moduleid in (%s)" % ids[:-1]
    res = dbfucs.query(sql)
    if len(res) == 0:
        response = {}
        response["code"] = 200
        response["msg"] = "没有可用用例执行"
        return jsonify(response)
    jsoncasss = []
    for test in res:
        jsoncasss.append(test)
    # print(jsoncasss)
    for i in collect.collect_db_cass(jsoncasss):
        Logger.info("*" * 90)
    Logger.info("共计[%d]条测试用例执行完成!" % len(jsoncasss))
    Logger.info("*" * 90)
    response = {}
    response["code"] = 200
    response["msg"] = "成功!!!"
    return jsonify(response)
Beispiel #11
0
def deleteproject():
    '''
    删除项目,项目下面的所有关联的内容都会被删除
    {"pid":1}
    '''
    dictdata = request.get_json()
    # 查询产品id
    pid = dictdata["pid"]

    # 查询项目id询 模块id 用例id
    sql = "SELECT\
                a.id AS moduleid,\
                b.id AS testcaseid \
            FROM\
                t_modules AS a\
                LEFT JOIN t_testcass AS b ON b.moduleid = a.id \
            WHERE\
                a.projectid = %s" % pid

    # 级联删除 case -> module -> project
    for ids in dbfucs.query(sql):
        delete_modelus_sql = "delete from t_modules where id = %d" % ids.get("moduleid")
        delete_testcase_sql = "delete from t_testcass where id = %d" % ids.get("testcaseid")
        dbfucs.excute(delete_testcase_sql)
        dbfucs.excute(delete_modelus_sql)

    sql = "DELETE FROM `t_project` WHERE (`id`='%s')" % pid
    res = dbfucs.excute(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "删除成功!!!"
    return jsonify(response)
Beispiel #12
0
def runproduct():
    '''
    按产品执行所有用例
    {"idlist":"1,2"}
    '''
    dictdata = request.get_json()
    idlist = dictdata["idlist"]
    ids = ''
    for i in idlist:
        ids += str(i) + ","
    sql = "SELECT\
        t_testcass.id\
    FROM\
        t_product\
    LEFT JOIN t_project ON t_product.id = t_project.productid\
    LEFT JOIN t_modules ON t_project.id = t_modules.projectid\
    LEFT JOIN t_testcass ON t_modules.id = t_testcass.moduleid\
    WHERE t_product.id in (%s);" % ids[:-1]
    # print(sql)
    res = dbfucs.query(sql)
    # print(res)
    if len(res) == 0:
        response = {}
        response["code"] = 200
        response["msg"] = "没有可用用例执行"
        return jsonify(response)
    idlist = []
    for i in res:
        idlist.append(i['id'])
    ids = ''
    for i in idlist:
        ids += str(i) + ","
    sql = "select id,testname,testtype,request,validate,extract from t_testcass where id in(%s);" % ids[:
                                                                                                        -1]
    res = dbfucs.query(sql)
    jsoncasss = []
    for test in res:
        jsoncasss.append(test)
    # print(jsoncasss)
    for i in collect.collect_db_cass(jsoncasss):
        Logger.info("*" * 90)
    Logger.info("共计[%d]条测试用例执行完成!" % len(jsoncasss))
    Logger.info("*" * 90)
    response = {}
    response["code"] = 200
    response["msg"] = "共计[%d]条测试用例执行完成!" % len(jsoncasss)
    return jsonify(response)
Beispiel #13
0
def getproject():
    '''
    读取项目列表,这个接口是给新增模块等东西的时候,选择所属项目用的
    '''
    sql = "SELECT t_product.id as productid, t_product.product FROM t_product"
    res = dbfucs.query(sql)
    projelist = []
    for prod in res:
        sql = "SELECT t_project.id as projectid, t_project.project FROM t_project where productid = %s" % prod[
            "productid"]
        res = dbfucs.query(sql)
        prod["jectinfo"] = res
        projelist.append(prod)
    response = {}
    response["code"] = 200
    response["data"] = projelist
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #14
0
def getproduct():
    '''
    读取产品列表,这个接口是给新增项目等东西的时候,选择所属产品用的
    '''
    sql = "SELECT id,product FROM t_product"
    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #15
0
def _get_test_results(**kwargs):
    """
    抽象查询结果的公共方法
    :params kwargs: 参数可以传任意值
        {} / {"version": 14} / {"version": 14, "productid": 1}
        {"version": 14, "productid": 1, "projectid": 1} / {"version": 14, "productid": 1, "projectid": 1, "moduleid": 6}
    :return:
    """
    version = kwargs.get("version")
    productid = kwargs.get("productid")
    projectid = kwargs.get("projectid")
    moduleid = kwargs.get("moduleid")
    # 构造sql
    product_sql, project_sql, module_sql = ["", ""], ["", ""], ["", ""]
    if productid is not None and productid != "":
        product_sql.clear()
        product_sql.append(" ,t_product AS b")
        product_sql.append(" AND b.id=%d" % productid)
    if projectid is not None and projectid != "":
        project_sql.clear()
        project_sql.append(" ,t_project AS c")
        project_sql.append(" AND c.id=%d" % projectid)
    if moduleid is not None and moduleid != "":
        module_sql.clear()
        module_sql.append(" ,t_modules AS d")
        module_sql.append(" AND d.id=%d  AND e.moduleid = d.id" % moduleid)
    if version is not None and version != "":
        version_sql = "a.version = %d" % version
    else:
        version_sql = " version in (select max(version) as version from t_reports)"

    success_sql = "SELECT a.* FROM t_reports AS a %s %s  %s ,t_testcass as e WHERE %s AND a.`status`='成功' %s %s %s" \
                  " AND a.cassid = e.id" % (product_sql[0], project_sql[0], module_sql[0], version_sql, product_sql[1], project_sql[1], module_sql[1])

    failed_sql = "SELECT a.* FROM t_reports AS a %s %s  %s ,t_testcass as e WHERE %s AND a.`status`!='成功' %s %s %s" \
                  " AND a.cassid = e.id" % (product_sql[0], project_sql[0], module_sql[0], version_sql, product_sql[1], project_sql[1], module_sql[1])

    all_sql = "SELECT a.* FROM t_reports AS a %s %s  %s ,t_testcass as e WHERE %s %s %s %s" \
                  " AND a.cassid = e.id" % (product_sql[0], project_sql[0], module_sql[0], version_sql, product_sql[1], project_sql[1], module_sql[1])

    return dbfucs.query(success_sql), dbfucs.query(failed_sql), dbfucs.query(all_sql)
Beispiel #16
0
def get_reports_max_version():
    """
    获取测试报告的最后一个版本
    :return:
    """
    from app.utils.dbfucs import query
    sql = "select max(version) as version from t_reports"
    r = query(sql)[0]
    if r.get("version"):
        return r.get("version") + 1
    else:
        return 1
Beispiel #17
0
def querytcasscount():
    '''
    获取用例列表
    编号	名称	所属模块	描述	执行状态	责任人	备注	创建时间
    '''
    sql = "SELECT COUNT(*)casenum FROM t_testcass"
    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #18
0
def getcassres():
    '''
    获取用例执行结果
    {"pid":1}
    '''
    dictdata = request.get_json()
    pid = dictdata["pid"]
    sql = "select result from t_reports WHERE cassid = %s order by id DESC limit 1" % pid
    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #19
0
def getmodules():
    '''
    读取模块列表,这个接口是给新增用例等东西的时候,选择所属模块用的
    '''
    sql = "SELECT t_product.id as productid, t_product.product FROM t_product"
    res = dbfucs.query(sql)
    projelist = []
    for prod in res:
        sql = "SELECT t_project.id as projectid, t_project.project FROM t_project where productid = %s" % prod[
            "productid"]
        res = dbfucs.query(sql)
        prod["jectinfo"] = res
        for proj in res:
            sql = "SELECT t_modules.id as moduleid, t_modules.modules FROM t_modules where projectid = %s" % proj[
                "projectid"]
            res = dbfucs.query(sql)
            proj["moduleinfo"] = res
        projelist.append(prod)
    response = {}
    response["code"] = 200
    response["data"] = projelist
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #20
0
def getversions():
    """
    获取所有用例执行版本
    :return:
    """
    sql = "select version from t_reports group by version"
    versions = []
    for res in dbfucs.query(sql):
        versions.append(res.get("version"))
    response = {}
    response["code"] = 200
    response["data"] = {"versions":versions}
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #21
0
def queryresultCount():
    '''
    获取用例列表
    编号	名称	所属模块	描述	执行状态	责任人	备注	创建时间
    '''
    sql = "select \
         case status when 0 then 'Pass' when 1 then 'Fail' else 'Error' end as status,\
         count(status) as nums \
         from t_reports \
         GROUP BY status"

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #22
0
def runtests():
    '''{"idlist":"1,2"}'''
    dictdata = request.get_json()
    idlist = dictdata["idlist"]
    sql = "select id,testname,testtype,request,validate,extract from t_testcass where id in(%s);" % idlist
    res = dbfucs.query(sql)
    jsoncasss = []
    for test in res:
        jsoncasss.append(test)
    for i in collect.collect_db_cass(jsoncasss):
        Logger.info("*" * 90)
    Logger.info("共计[%d]条测试用例执行完成!" % len(jsoncasss))
    Logger.info("*" * 90)
    response = {}
    response["code"] = 200
    response["msg"] = "用例执行完成!"
    return jsonify(response)
Beispiel #23
0
def getproject():
    '''
    读取项目列表,这个接口是给新增模块等东西的时候,选择所属项目用的
    '''
    sql = "SELECT\
        t_product.id as productid,\
        t_product.product,\
        t_project.id as projectid,\
        t_project.project\
    FROM\
        t_product\
    LEFT JOIN t_project ON t_product.id = t_project.productid\
    LEFT JOIN t_modules ON t_project.id = t_modules.projectid"

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #24
0
def readproduct():
    '''
    读取产品信息
    {"pid":1}
    '''
    dictdata = request.get_json()
    pid = dictdata["pid"]
    sql = "SELECT\
        t_product.product,\
        t_product.`explain`,\
        t_product.leader,\
        t_product.remark\
        FROM\
        t_product\
        WHERE\
        t_product.id = %s" % pid
    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #25
0
def readmodule():
    '''
    读取项目信息
    {"pid":1}
    '''
    dictdata = request.get_json()
    pid = dictdata["pid"]
    sql = "SELECT\
        t_modules.id,\
        t_modules.modules,\
        t_modules.`explain`,\
        t_modules.leader,\
        t_modules.remark\
        FROM\
        t_modules\
        WHERE\
        t_modules.id = %s" % pid
    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #26
0
def readcass():
    '''
    读取用例信息
    {"pid":1}
    '''
    dictdata = request.get_json()
    pid = dictdata["pid"]
    sql = "SELECT\
        moduleid,\
        testname,\
        testtype,\
        `explain`,\
        request,\
        validate,\
        extract,\
        leader,\
        remark\
    FROM t_testcass WHERE id = %s;" % pid
    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #27
0
def querytcass():
    '''
    获取用例列表
    编号	名称	所属模块	描述	执行状态	责任人	备注	创建时间
    '''
    sql = "SELECT\
                t_testcass.id AS testid,\
                ( SELECT modules FROM t_modules WHERE id = t_testcass.moduleid ) AS modulename,\
                t_testcass.testname,\
                t_testcass.`explain`,\
                ( SELECT t_reports.`status` FROM t_reports WHERE t_reports.cassid = t_testcass.id ORDER BY t_reports.version DESC LIMIT 1 ) AS `status`,\
                t_testcass.leader,\
                t_testcass.remark,\
                t_testcass.createtime \
          FROM\
	            t_testcass \
	      LEFT JOIN t_modules ON t_testcass.moduleid = t_modules.id "

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #28
0
def querymodule():
    '''
    查询模块列表
    '''
    sql = "SELECT\
        t_modules.id as moduleid,\
        t_modules.modules,\
        t_modules.`explain`,\
        (SELECT COUNT(*) FROM t_testcass WHERE t_testcass.moduleid = t_modules.id) AS cassnum,\
        t_modules.leader,\
        t_modules.remark,\
        t_modules.createtime,\
        t_modules.updatatime\
    FROM\
        t_modules\
    LEFT JOIN t_testcass ON t_modules.id = t_testcass.moduleid\
    group by t_modules.id;"

    res = dbfucs.query(sql)
    response = {}
    response["code"] = 200
    response["data"] = res
    response["msg"] = "查询成功!!!"
    return jsonify(response)
Beispiel #29
0
def _get_modules_count():
    """  3. 每个项目的模块统计 """
    """
        "modulescount": [
            {
                "count": 2,
                "modules": [
                    {
                        "createtime": "2018-05-17 21:47:48",
                        "explain": "WEB端测试模块1",
                        "id": 1,
                        "leader": "浪晋",
                        "modules": "WEB模块1",
                        "projectid": 1,
                        "remark": "备注",
                        "updatatime": "2018-05-17 21:47:48"
                    },
                    {
                        "createtime": "2018-05-17 21:47:52",
                        "explain": "WEB端测试模块2",
                        "id": 6,
                        "leader": "snake",
                        "modules": "WEB模块2",
                        "projectid": 1,
                        "remark": "备注",
                        "updatatime": "2018-05-17 21:47:52"
                    }
                ],
                "project": {
                    "createtime": "2018-05-17 21:48:25",
                    "explain": "WEB端",
                    "id": 1,
                    "leader": "浪晋",
                    "productid": 1,
                    "project": "WEB项目",
                    "remark": "备注",
                    "updatatime": "2018-05-17 21:48:25"
                }
            },
            {
                "count": 2,
                "modules": [
                    {
                        "createtime": "2018-05-17 21:47:52",
                        "explain": "APP端测试模块1",
                        "id": 7,
                        "leader": "snake",
                        "modules": "APP模块1",
                        "projectid": 6,
                        "remark": "备注",
                        "updatatime": "2018-05-17 21:47:52"
                    },
                    {
                        "createtime": "2018-05-17 21:47:52",
                        "explain": "APP端测试模块2",
                        "id": 8,
                        "leader": "snake",
                        "modules": "APP模块2",
                        "projectid": 6,
                        "remark": "备注",
                        "updatatime": "2018-05-17 21:47:52"
                    }
                ],
                "project": {
                    "createtime": "2018-05-17 21:48:21",
                    "explain": "APP端",
                    "id": 6,
                    "leader": "snake",
                    "productid": 1,
                    "project": "APP项目",
                    "remark": "备注",
                    "updatatime": "2018-05-17 21:48:21"
                }
            }
        ]
    """
    modulescount = []
    sql = "select projectid from t_modules GROUP BY projectid"
    for results in dbfucs.query(sql):
        singeitem = {}

        # 统计count和modules
        sql = "select * from t_modules where projectid = %d" % results.get(
            "projectid")
        res = dbfucs.query(sql)
        if res:
            singeitem["count"] = len(res)  # count
            singeitem["modules"] = res  # modules
            projectid = results.get("projectid")

            # 统计project
            sql = "select * from t_project where id = %d" % projectid
            res = dbfucs.query(sql)
            if res:
                singeitem["project"] = res[0]

            modulescount.append(singeitem)

    return modulescount
Beispiel #30
0
def _get_last_test_result_runtime():
    """2. 上次用例执行时间分段统计图"""
    """
        时间分段统计:
        极快: t<1s
        快速: 1s< t <3s
        慢: 3s < t < 5s
        超级慢: t>5s

        "runtimecount": {
            "fast": {
                "count": 0,
                "times": []
            },
            "faster": {
                "count": 2,
                "times": [
                    0.011257,
                    0.012227
                ]
            },
            "slow": {
                "count": 0,
                "times": []
            },
            "slowly": {
                "count": 0,
                "times": []
            }
        },
    """
    faster, fast, slow, slowly = {}, {}, {}, {}
    faster["count"], fast["count"], slow["count"], slowly["count"] = 0, 0, 0, 0
    faster["times"], fast["times"], slow["times"], slowly[
        "times"], = [], [], [], []
    success_sql = "select * from t_reports where version in" \
                  " (select max(version) as version from t_reports) and status='成功'"
    failed_sql = "select * from t_reports where version in" \
                 " (select max(version) as version from t_reports) and status!='成功'"
    success_results = dbfucs.query(success_sql)
    failed_results = dbfucs.query(failed_sql)
    for result in (success_results, failed_results):
        for r in result:
            try:
                runtime = float(r.get("runtime"))
            except:
                runtime = 100.0
            if runtime < 1.0:
                faster["count"] += 1
                faster["times"].append(runtime)
            if runtime > 1.0 and runtime < 3.0:
                fast["count"] += 1
                fast["times"].append(runtime)
            if runtime > 3.0 and runtime < 5.0:
                slow["count"] += 1
                slow["times"].append(runtime)
            if runtime > 5.0:
                slowly["count"] += 1
                slowly["times"].append(runtime)

    return {"faster": faster, "fast": fast, "slow": slow, "slowly": slowly}