Beispiel #1
0
def getTaskHistoryReport(request):
    req = simplejson.loads(request.body)
    hId = None
    if req.has_key("hId"):
        hId = req["hId"]
    if not hId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        history = TaskHistoryModel.objects.get(pk=int(hId))
        suite = TestSuiteModel.objects.get(pk=int(history.suiteId))
        preSql = suite.preSql
        postSql = suite.postSql
    except Exception as e:
        globalVars.getLogger().error(u"查询历史数据失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson(
            "false", u"查询历史数据失败:" + CommonValueHandle.text2unicode(e.message)),
                            content_type="application/json")
    else:
        data = {}
        data["preSql"] = preSql
        data["postSql"] = postSql
        data["preCases"] = history.getPreCaseResult()
        data["Cases"] = history.getCaseResult()
        return HttpResponse(globalVars.responseJson("true", "", data),
                            content_type="application/json")
Beispiel #2
0
def updateApiDelHeader(request):
    req = json.loads(request.body)
    aId = None
    hId = None
    if req.has_key("aId"):
        aId = req["aId"]
    if req.has_key("hId"):
        hId = req["hId"]

    if not aId or not hId:
        globalVars.getLogger().error("aId或者hId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        res = api.delHeader(hId)
        if isinstance(res, unicode) or isinstance(res, str):
            globalVars.getLogger().error(u"删除api Header失败:" +
                                         CommonValueHandle.text2unicode(res))
            return HttpResponse(globalVars.responseJson("false", "删除head失败"),
                                content_type="application/json")
    except Exception as e:
        globalVars.getLogger().error(u"修改api失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改接口失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", ""),
                            content_type="application/json")
Beispiel #3
0
def updateApiChangeResponse(request):
    req = simplejson.loads(request.body)
    aId = None
    rId = None
    direction = None
    if req.has_key("aId"):
        aId = req["aId"]
    if req.has_key("rId"):
        rId = req["rId"]
    if req.has_key("direction"):
        direction = req["direction"]

    if not aId or not rId or not direction:
        globalVars.getLogger().error("aId,pId,direction不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        res = api.changeResponse(direction, rId)
        if isinstance(res, unicode) or isinstance(res, str):
            globalVars.getLogger().error(u"修改api parmas:" +
                                         CommonValueHandle.text2unicode(res))
            return HttpResponse(globalVars.responseJson("false", "修改接口失败"),
                                content_type="application/json")
    except Exception as e:
        globalVars.getLogger().error(u"修改api parmas:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改接口失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", ""),
                            content_type="application/json")
Beispiel #4
0
def getTaskHistory(request):
    req = simplejson.loads(request.body)
    tId = None
    if req.has_key("tId"):
        tId = req["tId"]
    if not tId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        historys = TaskHistoryModel.objects.filter(
            taskId=int(tId)).order_by("-lastResultVersion")
    except Exception as e:
        globalVars.getLogger().error(u"查询历史数据失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson(
            "false", u"查询历史数据失败:" + CommonValueHandle.text2unicode(e.message)),
                            content_type="application/json")
    else:
        data = []
        for t in historys:
            tmp = {}
            tmp["time"] = t.lastRunningTime
            tmp["hId"] = t.id
            tmp["version"] = t.lastResultVersion
            tmp["name"] = t.taskName
            data.append(tmp)
        return HttpResponse(globalVars.responseJson("true", "", data),
                            content_type="application/json")
Beispiel #5
0
def updateApiDelResponse(request):
    req = simplejson.loads(request.body)
    aId = None
    rId = None
    if req.has_key("aId"):
        aId = req["aId"]
    if req.has_key("rId"):
        rId = req["rId"]

    if not aId or not rId:
        globalVars.getLogger().error("aId或者rId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        res = api.delResponse(rId)
        if isinstance(res, unicode) or isinstance(res, str):
            return HttpResponse(globalVars.responseJson(
                "false",
                u"删除api response失败:" + CommonValueHandle.text2unicode(res)),
                                content_type="application/json")
    except Exception as e:
        globalVars.getLogger().error(u"修改api失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改参数失败"),
                            content_type="application/json")
    else:
        data = {}
        data["delId"] = res
        return HttpResponse(globalVars.responseJson("true", "", data),
                            content_type="application/json")
Beispiel #6
0
def updateApiAddResponse(request):
    req = simplejson.loads(request.body)
    aId = None
    if req.has_key("aId"):
        aId = req["aId"]
    if not aId:
        globalVars.getLogger().error("aId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        res = api.addResponse(req)
        #         print(type(res))
        if isinstance(res, unicode) or isinstance(res, str):
            globalVars.getLogger().error(u"添加api response失败:" +
                                         CommonValueHandle.text2unicode(res))
            return HttpResponse(globalVars.responseJson("false", "添加响应失败"),
                                content_type="application/json")
    except Exception as e:
        globalVars.getLogger().error(u"修改api失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改接口失败"),
                            content_type="application/json")
    else:
        data = {}
        data["aId"] = aId
        data["name"] = req["name"]
        data["type"] = req["type"]
        data["dec"] = req["dec"]
        data["rId"] = res.id
        data["default"] = res.default
        data["value"] = res.value
        return HttpResponse(globalVars.responseJson("true", "", data),
                            content_type="application/json")
Beispiel #7
0
def updateApiMethod(request):
    req = simplejson.loads(request.body)
    aId = None
    method = None
    if req.has_key("aId"):
        aId = req["aId"]
    if req.has_key("method"):
        method = req["method"]

    if not aId or not method:
        globalVars.getLogger().error("aId或者url不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        api.method = method
        api.save()
    except Exception as e:
        globalVars.getLogger().error(u"修改api失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改api失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", ""),
                            content_type="application/json")
Beispiel #8
0
def getCasesList(request):
    req = simplejson.loads(request.body)
    tId = None
    if req.has_key("tId"):
        tId = req["tId"]

    if not tId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        task = TaskModel.objects.get(pk=int(tId))
        cases = task.getCases()

    except Exception as e:
        globalVars.getLogger().error(u"修改任务失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改任务失败"),
                            content_type="application/json")
    else:
        re = {}
        re["cases"] = cases
        re["lastRunningSuccessCount"] = task.lastRunningSuccessCount
        re["lastRunningfailedCount"] = task.lastRunningfailedCount
        re["lastRunningTime"] = task.lastRunningTime
        re["lastRunningUser"] = task.lastRunningUser
        re["lastRunningResult"] = task.lastRunningResult
        re["preSql"] = task.getPreSql()
        re["postSql"] = task.getPostSql()
        re["preRequirement"] = task.getPreRequirement()
        return HttpResponse(globalVars.responseJson("true", "", re),
                            content_type="application/json")
Beispiel #9
0
def deleteApi(request):
    req = simplejson.loads(request.body)
    aId = None
    print("~~~~~~~~")
    print(req)
    print("6666666")

    if req.has_key("aId"):
        aId = req["aId"]
    if not aId:
        globalVars.getLogger().error("aId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        TestCaseModel.objects.filter(api=api).delete()
        api.delete()
    except Exception as e:
        globalVars.getLogger().error(u"删除api失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "删除接口失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", ""),
                            content_type="application/json")
Beispiel #10
0
def deleteApiModule(request):
    req = simplejson.loads(request.body)
    mId = None
    if req.has_key("mId"):
        mId = req["mId"]

    if not mId:
        globalVars.getLogger().error("mId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        module = ApiModules.objects.get(pk=mId)
    except Project.DoesNotExist:
        globalVars.getLogger().error("mId错误")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    else:
        try:
            module.delete()
        except Exception as e:
            globalVars.getLogger().error(
                u"删除模块失败:" + CommonValueHandle.text2unicode(e.message))
            return HttpResponse(globalVars.responseJson("false", "删除模块失败"),
                                content_type="application/json")
        else:
            return HttpResponse(globalVars.responseJson("true", "", {}),
                                content_type="application/json")
Beispiel #11
0
def copyApi(request):
    req = simplejson.loads(request.body)
    aId = None
    if req.has_key("aId"):
        aId = req["aId"]
    if not aId:
        globalVars.getLogger().error("aId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        newApi = api.cloneApi()
        newApi.save()
    except Exception as e:
        globalVars.getLogger().error(u"复制api失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "复制失败"),
                            content_type="application/json")
    else:
        tmp = {}
        tmp["name"] = newApi.name
        tmp["aId"] = newApi.id
        tmp["mId"] = newApi.module.id
        tmp["method"] = newApi.method
        tmp["pId"] = newApi.project.id
        tmp["parentId"] = newApi.module.id
        tmp["type"] = "api"
        tmp["cId"] = -1
        return HttpResponse(globalVars.responseJson("true", "", tmp),
                            content_type="application/json")
Beispiel #12
0
def requirementAddPicker(request):
    req = simplejson.loads(request.body)
    rId = None
    name = None
    value = None
    expression = None
    if req.has_key("rId"):
        rId=req["rId"]
    if req.has_key("name"):
        name=req["name"]
    if req.has_key("value"):
        value=req["value"]
    if req.has_key("expression"):
        expression=req["expression"]
    if not rId or not value or not expression:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"), content_type="application/json")
    try:
        picker = PickerValuesModel.objects.create(name=name,value=value,expression=expression)
        require = RequirementModel.objects.get(pk=int(rId))
        require.addPickerValue(picker.id);
    except Exception as e:
        globalVars.getLogger().error(u"新建变量提取失败:"+CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "新建变量提取失败"), content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true","",picker.getDict()), content_type="application/json")
Beispiel #13
0
def updateTask(request):
    req = simplejson.loads(request.body)
    tId = None
    name = None
    suId = None
    eId = None
    taskType = None
    repeatDateTime = None
    repeatType = None
    if req.has_key("tId"):
        tId = req["tId"]
    if req.has_key("name"):
        name = req["name"]
    if req.has_key("suId"):
        suId = req["suId"]
    if req.has_key("eId"):
        eId = req["eId"]
    if req.has_key("taskType"):
        taskType = req["taskType"]
    if req.has_key("repeatDateTime"):
        repeatDateTime = req["repeatDateTime"]
    if req.has_key("repeatType"):
        repeatType = req["repeatType"]

    if not tId or not name or not suId or not eId or not taskType or not repeatDateTime or not repeatType:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        task = TaskModel.objects.get(pk=int(tId))
        task.name = name
        task.env = EnvModel.objects.get(pk=int(eId))
        task.suite = TestSuiteModel.objects.get(pk=int(suId))
        task.taskType = taskType
        task.repeatDateTime = repeatDateTime
        task.repeatType = int(repeatType)
        task.successRate = 0
        task.lastRunningTime = u""
        task.lastRunningUser = u""
        task.lastRunningSuccessCount = 0
        task.lastRunningfailedCount = 0
        task.lastResultVersion = -1
        task.lastRunningResult = u"未执行,无结果"
        task.save()
    except Exception as e:
        globalVars.getLogger().error(u"修改任务失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改任务失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", "",
                                                    task.getDict()),
                            content_type="application/json")
Beispiel #14
0
def updateAPiSetResponse(request):
    req = simplejson.loads(request.body)
    aId = None
    if len(req) == 0:
        return HttpResponse(globalVars.responseJson("false", "数据为空"),
                            content_type="application/json")
    if req[0].has_key("aId"):
        aId = req[0]["aId"]
    if not aId:
        globalVars.getLogger().error("aId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        res = api.setResponse(req)
        #         print(type(res))
        if isinstance(res, unicode) or isinstance(res, str):
            globalVars.getLogger().error(u"添加api parmas失败:" +
                                         CommonValueHandle.text2unicode(res))
            return HttpResponse(globalVars.responseJson("false", "添加参数失败"),
                                content_type="application/json")
    except Exception as e:
        return HttpResponse(globalVars.responseJson(
            "false", u"修改api失败:" + CommonValueHandle.text2unicode(e.message)),
                            content_type="application/json")
    else:
        resList = []
        for i in res:
            data = {}
            data["aId"] = api.id
            data["name"] = i.name
            data["type"] = i.type
            data["dec"] = i.dec
            data["rId"] = i.id
            data["default"] = i.default
            data["value"] = i.value
            resList.append(data)
        return HttpResponse(globalVars.responseJson("true", "", resList),
                            content_type="application/json")
Beispiel #15
0
def runTask(request):
    req = simplejson.loads(request.body)
    tId = None
    uId = None
    if req.has_key("tId"):
        tId = req["tId"]
    if req.has_key("uId"):
        uId = req["uId"]
    if not tId or not uId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        task = TaskModel.objects.get(pk=int(tId))
        excute = TestTaskExcute(task.id, uId)
        ret = excute.excute()
        if True != ret:
            globalVars.getLogger().error(u"执行任务失败:" +
                                         CommonValueHandle.text2unicode(ret))
            return HttpResponse(globalVars.responseJson(
                "false", u"执行任务失败:" + CommonValueHandle.text2unicode(ret)),
                                content_type="application/json")
    except Exception as e:
        print(e)
        print(1)
        traceback
        globalVars.getLogger().error(u"执行任务失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson(
            "false", u"执行任务失败:" + CommonValueHandle.text2unicode(e.message)),
                            content_type="application/json")
    else:

        new_task = TaskModel.objects.get(pk=int(tId))
        return HttpResponse(globalVars.responseJson("true", "",
                                                    new_task.getDict()),
                            content_type="application/json")
Beispiel #16
0
def requirementGetPicker(request):
    req = simplejson.loads(request.body)
    rId = None
    if req.has_key("rId"):
        rId=req["rId"]

    if not rId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"), content_type="application/json")
    try:
        require = RequirementModel.objects.get(pk=int(rId))
    except Exception as e:
        globalVars.getLogger().error(u"新建变量提取失败:"+CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "新建变量提取失败"), content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true","",require.getPickerValue()), content_type="application/json")
Beispiel #17
0
def addTask(request):
    req = simplejson.loads(request.body)
    pId = None
    name = None
    suId = None
    eId = None
    taskType = None
    repeatDateTime = None
    repeatType = None
    if req.has_key("name"):
        name = req["name"]
    if req.has_key("pId"):
        pId = req["pId"]
    if req.has_key("suId"):
        suId = req["suId"]
    if req.has_key("eId"):
        eId = req["eId"]
    if req.has_key("taskType"):
        taskType = req["taskType"]
    if req.has_key("repeatDateTime"):
        repeatDateTime = req["repeatDateTime"]
    if req.has_key("repeatType"):
        repeatType = req["repeatType"]

    if not name or not pId or not suId or not eId or not taskType or not repeatDateTime or not repeatType:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        task = TaskModel.objects.create(name=name,
                                        project_id=pId,
                                        suite_id=suId,
                                        env_id=eId,
                                        taskType=taskType,
                                        repeatDateTime=repeatDateTime,
                                        repeatType=repeatType)
    except Exception as e:
        globalVars.getLogger().error(u"新建任务失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "新建任务失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", "",
                                                    task.getDict()),
                            content_type="application/json")
Beispiel #18
0
def updateApiModule(request):
    req = simplejson.loads(request.body)
    name = None
    parentId = None
    mId = None
    parentId_status = None
    if req.has_key("name"):
        name = req["name"]
    if req.has_key("parentId"):
        parentId = req["parentId"]
        if parentId != None and parentId != "":
            parentId_status = True
    if req.has_key("mId"):
        mId = req["mId"]

    if not mId:
        globalVars.getLogger().error("mId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        module = ApiModules.objects.get(pk=mId)
    except ApiModules.DoesNotExist:
        globalVars.getLogger().error("mId错误")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    else:
        try:
            if name:
                module.name = name
            if parentId_status:
                module.parentId = parentId
            module.save()
        except Exception as e:
            globalVars.getLogger().error(
                u"修改模块失败:" + CommonValueHandle.text2unicode(e.message))
            return HttpResponse(globalVars.responseJson("false", "修改模块失败"),
                                content_type="application/json")
        else:
            content = {}
            content["name"] = name
            content["mId"] = mId
            content["parentId"] = parentId
            content["type"] = "module"
            return HttpResponse(globalVars.responseJson("true", "", content),
                                content_type="application/json")
Beispiel #19
0
def addApiModule(request):
    req = simplejson.loads(request.body)
    name = None
    pId = None
    parentId = None
    parentId_status = None
    if req.has_key("name"):
        name = req["name"]
    if req.has_key("pId"):
        pId = req["pId"]
    if req.has_key("parentId"):
        parentId = req["parentId"]
        if parentId != None and parentId != "":
            parentId_status = True

    if not name or not pId or not parentId_status:
        globalVars.getLogger().error("名称和pId,parentId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        pro = Project.objects.get(pk=int(pId))
    except Project.DoesNotExist:
        globalVars.getLogger().error("pId不存在")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    else:
        try:
            mo = ApiModules.objects.create(name=name,
                                           project=pro,
                                           parentId=parentId)
        except Exception as e:
            globalVars.getLogger().error(
                u"新建模块失败:" + CommonValueHandle.text2unicode(e.message))
            return HttpResponse(globalVars.responseJson("false", "新建模块失败"),
                                content_type="application/json")
        else:
            content = {}
            content["name"] = name
            content["pId"] = pId
            content["parentId"] = parentId
            content["mId"] = mo.id
            content["type"] = "module"
            return HttpResponse(globalVars.responseJson("true", "", content),
                                content_type="application/json")
Beispiel #20
0
def deleteTask(request):
    req = simplejson.loads(request.body)
    tId = None
    if req.has_key("tId"):
        tId = req["tId"]
    if not tId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        task = TaskModel.objects.get(pk=int(tId))
        task.delete()
    except Exception as e:
        globalVars.getLogger().error(u"删除任务失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "删除任务失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", ""),
                            content_type="application/json")
Beispiel #21
0
def addRequirement(request):
    req = simplejson.loads(request.body)
    cases = None
    if req.has_key("cases"):
        cases=req["cases"]
    if not cases:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"), content_type="application/json")
    try:
        res = []
        for i in cases:
            require = RequirementModel.objects.create(case_id=i["cId"],type=i["type"])
            res.append(require.getDict())
    except Exception as e:
        globalVars.getLogger().error(u"新建前置条件失败:"+CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "新建前置条件失败"), content_type="application/json")
    else:
        content={}
        content["requirements"]=res
        return HttpResponse(globalVars.responseJson("true","",content), content_type="application/json")
Beispiel #22
0
def getTestCaseResult(request):
    req = json.loads(request.body)
    reId = None

    if req.has_key("rId"):
        reId = req["rId"]

    if not reId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数不正确,请检查请求参数"),
                            content_type="application/json")
    try:
        result = TestCaseResultModel.objects.get(pk=int(reId))
    except Exception as e:
        globalVars.getLogger().error(u"获取结果失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "获取结果失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", "",
                                                    result.getDict()),
                            content_type="application/json")
Beispiel #23
0
def getApiList(request):
    req = simplejson.loads(request.body)
    mId = None
    if req.has_key("mId"):
        mId = req["mId"]
    if not mId:
        globalVars.getLogger().error("mId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        module = ApiModules.objects.get(pk=int(mId))
    except ApiModules.DoesNotExist:
        globalVars.getLogger().error("模块mId不存在")
        return HttpResponse(globalVars.responseJson("false", "模块不存在"),
                            content_type="application/json")
    else:
        try:
            apilist = ApiDefine.objects.filter(module=module)
        except Exception as e:
            globalVars.getLogger().error(
                u"数据库查询失败:" + CommonValueHandle.text2unicode(e.message))
            return HttpResponse(globalVars.responseJson("false", "参数错误"),
                                content_type="application/json")
        else:
            context = {}
            data = []
            for i in apilist:
                tmp = {}
                tmp["aId"] = i.id
                tmp["name"] = i.name
                tmp["method"] = i.method
                tmp["type"] = "api"
                data.append(tmp)
            context["length"] = apilist.count()
            context["data"] = data
            return HttpResponse(globalVars.responseJson("true", "", context),
                                content_type="application/json")
Beispiel #24
0
def addCase(request):  
    req = simplejson.loads(request.body)
    name = None
    dec = None
    pId = None
    aId = None
    uId = None
    label = None
    if req.has_key("name"):
        name=req["name"]
    if req.has_key("pId"):
        pId=req["pId"]
    if req.has_key("dec"):
        dec = req["dec"]
    if req.has_key("aId"):
        aId = req["aId"]
    if req.has_key("uId"):
        uId = req["uId"]
    if req.has_key("label"):
        label = req["label"]
    
    if not name or not pId or not dec or not aId or not uId:
        globalVars.getLogger().error("参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数错误"), content_type="application/json")
    try:
        pro = Project.objects.get(pk=int(pId))
        u = Users.objects.get(pk=int(uId))
        a = ApiDefine.objects.get(pk=int(aId))
    except Project.DoesNotExist or Users.DoesNotExist or ApiDefine.DoesNotExist:
        globalVars.getLogger().error("pId,aId,uId 不存在")
        return HttpResponse(globalVars.responseJson("false", "参数错误"), content_type="application/json")   
    else:    
        try:
            case = TestCaseModel.objects.create(name=name,project=pro,dec=dec,user=u,api=a,caseLabels=label)
        except Exception as e:
            globalVars.getLogger().error(u"新建模块失败:"+CommonValueHandle.text2unicode(e.message))
            return HttpResponse(globalVars.responseJson("false", "新建模块失败"), content_type="application/json")
Beispiel #25
0
def updateApiParmasType(request):
    req = json.loads(request.body)
    aId = None
    parmasType = None
    if req.has_key("aId"):
        aId = req["aId"]
    if req.has_key("parmasType"):
        parmasType = req["parmasType"]
    if not aId or not parmasType:
        globalVars.getLogger().error("aId或者parmasType不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        api = ApiDefine.objects.get(pk=int(aId))
        api.parmasType = parmasType
        api.save()
    except Exception as e:
        globalVars.getLogger().error(u"修改api失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改接口失败"),
                            content_type="application/json")
    else:
        return HttpResponse(globalVars.responseJson("true", ""),
                            content_type="application/json")
Beispiel #26
0
def getApiModules(request):

    req = simplejson.loads(request.body)
    pId = None

    if req["pId"]:
        pId = req["pId"]

    if not pId:
        globalVars.getLogger().error("pId不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        pro = Project.objects.get(pk=int(pId))
    except Project.DoesNotExist:
        globalVars.getLogger().error("pId不存在")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    else:
        try:
            moduleList = ApiModules.objects.filter(project=pro)
            apilist = ApiDefine.objects.filter(project=pro)
            caselist = TestCaseModel.objects.filter(project=pro)
        except Exception as e:
            globalVars.getLogger().error(
                u"查询模块数据失败:" + CommonValueHandle.text2unicode(e.message))
            return HttpResponse(globalVars.responseJson("false", "查询失败"),
                                content_type="application/json")
        else:
            content = {}
            content["len"] = moduleList.count() + apilist.count()
            datalist = []
            for p in moduleList:
                tmp = {}
                tmp["name"] = p.name
                tmp["mId"] = p.id
                tmp["parentId"] = p.parentId
                tmp["pId"] = p.project.id
                tmp["type"] = "module"
                tmp["aId"] = -1
                tmp["cId"] = -1
                tmp["method"] = "none"
                datalist.append(tmp)

            for i in apilist:
                tmp = {}
                tmp["name"] = i.name
                tmp["aId"] = i.id
                tmp["mId"] = i.module.id
                tmp["method"] = i.method
                tmp["pId"] = i.project.id
                tmp["parentId"] = i.module.id
                tmp["type"] = "api"
                tmp["cId"] = -1
                datalist.append(tmp)

            for i in caselist:
                tmp = {}
                tmp["name"] = i.name
                tmp["aId"] = i.api.id
                tmp["mId"] = -1
                tmp["method"] = "none"
                tmp["pId"] = i.project.id
                tmp["parentId"] = i.api.id
                tmp["type"] = "case"
                tmp["cId"] = i.id
                datalist.append(tmp)

            content["data"] = datalist
            return HttpResponse(globalVars.responseJson("true", "", content),
                                content_type="application/json")
Beispiel #27
0
def addApi(request):
    req = simplejson.loads(request.body)
    pId = None
    mId = None
    uId = None
    name = None
    dec = None
    method = None
    url = None
    if req.has_key("pId"):
        pId = req["pId"]
    if req.has_key("mId"):
        mId = req["mId"]
    if req.has_key("uId"):
        uId = req["uId"]
    if req.has_key("name"):
        name = req["name"]
    if req.has_key("dec"):
        dec = req["dec"]
    if req.has_key("method"):
        method = req["method"]
    if req.has_key("url"):
        url = req["url"]
    if not pId or not mId or not uId or not name or not dec or not method or not url:
        globalVars.getLogger().error("pId,mId,uId,name,dec,method,url不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        pro = Project.objects.get(pk=int(pId))
        user = Users.objects.get(pk=int(uId))
        module = ApiModules.objects.get(pk=int(mId))
    except (Project.DoesNotExist, Users.DoesNotExist,
            ApiModules.DoesNotExist) as e:
        globalVars.getLogger().error(u"参数有误:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    else:
        try:
            api = ApiDefine.objects.create(name=name,
                                           project=pro,
                                           user=user,
                                           module=module,
                                           dec=dec,
                                           method=method,
                                           url=url,
                                           parmasType="json",
                                           responseType="json")
        except Exception as e:
            globalVars.getLogger().error(
                u"创建api失败:" + CommonValueHandle.text2unicode(e.message))
            return HttpResponse(globalVars.responseJson("false", "创建接口失败"),
                                content_type="application/json")
        else:
            data = {}
            data["aId"] = api.id
            data["pId"] = pId
            data["uId"] = uId
            data["mId"] = mId
            data["name"] = name
            data["dec"] = dec
            data["url"] = url
            data["type"] = "api"
            data["method"] = method
            return HttpResponse(globalVars.responseJson("true", "", data),
                                content_type="application/json")
Beispiel #28
0
    if req.has_key("label"):
        label=req["label"]
    if not cId:
        globalVars.getLogger().error("cId参数不正确,请检查请求参数")
        return HttpResponse(globalVars.responseJson("false", "参数错误"), content_type="application/json")
    try:
        case = TestCaseModel.objects.get(pk=int(cId))
        if None!=name:
            case.name=name
        if None!=dec:
            case.dec = dec
        if None!=label:
            case.caseLabels = label
        case.save();
    except Exception as e:
        globalVars.getLogger().error(u"修改case失败:"+CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "修改案例失败"), content_type="application/json")   
    else:    
        content={}
        content["cId"] = case.id
        content["name"]= name
        content["dec"] = dec
        content["label"] = label
        content["type"] = "case"
        return HttpResponse(globalVars.responseJson("true","",content), content_type="application/json")
    
def updateCaseHeader(request):
    req = simplejson.loads(request.body)
    cId = None
    headerData=None
Beispiel #29
0
def apiDebug(request):
    req = simplejson.loads(request.body)
    r = ""
    method = ""
    header = {}
    parmasType = ""
    form = []
    json = {}

    try:
        r = req["url"]
    except KeyError:
        r = ""

    try:
        method = req["method"]
    except KeyError:
        method = ""

    try:
        header = req["header"]
    except KeyError:
        header = {}

    try:
        parmasType = req["parmasType"]
    except KeyError:
        parmasType = ""

    try:
        form = req["form"]
    except KeyError:
        form = {}

    try:
        json = req["json"]
    except KeyError:
        json = {}

    if not r or not method:
        globalVars.getLogger().error("url或者method不能为空")
        return HttpResponse(globalVars.responseJson("false", "参数错误"),
                            content_type="application/json")
    try:
        #api = ApiDefine.objects.get(pk=int(aId))
        debug = RequestDebug(r, method, header, parmasType, form, json)
        debug.send()


#         res = apiDebug.sendRequest(req)
    except Exception as e:
        globalVars.getLogger().error(u"debug请求失败:" +
                                     CommonValueHandle.text2unicode(e.message))
        return HttpResponse(globalVars.responseJson("false", "请求失败"),
                            content_type="application/json")
    else:
        data = {}
        print(debug.getResponseBody())
        print(debug.getResponseHeader())
        print(debug.getRequest())
        data["body"] = debug.getResponseBody()
        data["head"] = debug.getResponseHeader()
        data["request"] = debug.getRequest()
        data["status"] = debug.getResponseStatus()
        return HttpResponse(globalVars.responseJson("true", "", data),
                            content_type="application/json")