def case_run(request): if request.method == 'POST': case_id = request.POST['case_id'] env_id = request.POST['env_id'] execute = Execute(case_id, env_id) case_result = execute.run_case() return JsonResponse(case_result)
def plan_run(request): if request.method == 'POST': plan_id = request.POST['plan_id'] plan = Plan.objects.get(plan_id=plan_id) env_id = plan.environment.env_id case_id_list = eval(plan.content) case_num = len(case_id_list) content = [] pass_num = 0 fail_num = 0 error_num = 0 for case_id in case_id_list: execute = Execute(case_id, env_id) case_result = execute.run_case() content.append(case_result) if case_result["result"] == "pass": pass_num += 1 if case_result["result"] == "fail": fail_num += 1 if case_result["result"] == "error": error_num += 1 report_name = plan.plan_name + "-" + time.strftime("%Y%m%d%H%M%S") if Report.objects.filter(plan=plan): Report.objects.filter(plan=plan).update(report_name=report_name, content=content, case_num=case_num, pass_num=pass_num, fail_num=fail_num, error_num=error_num) else: report = Report(plan=plan, report_name=report_name, content=content, case_num=case_num, pass_num=pass_num, fail_num=fail_num, error_num=error_num) report.save() return HttpResponse(plan.plan_name + " 执行成功!")
def post(self, requests): #运行用例调试类视图 case_id = requests.POST.get("case_id") #用例ID env_id = requests.POST.get("env_id") #环境 execute = Execute(case_id, env_id) #实例化执行类得到execute()对象 execute_result = execute.run_case() #执行后的结果 #调试结果返回至前端回调函数 return JsonResponse(execute_result)
def post(self, requests): plan_id = requests.POST.get("plan_id") plan = Plan.objects.get(plant_id=plan_id) env = plan.env.env_id #计划对象对应的环境 content = eval(plan.content) #计划对应的content case_num = len(content) #测试用例数 pass_num = 0 #用例通过数 fail_num = 0 # 用例失败数 error_num = 0 # 用例错误数 case_list = [] #测试计划中测试用例集 for case_obj in content: execute_obj = Execute(case_obj, env) run_result = execute_obj.run_case() case_list.append(run_result) if run_result["result"] == "pass": pass_num += 1 elif run_result["result"] == "fail": fail_num += 1 else: error_num += 1 report_name = plan.plant_name + "-" + time.strftime("%Y%m%d%H%M%S") if Report.objects.filter(plant=plan): Report.objects.filter(plant=plan).update(report_name=report_name, plant=plan, content=case_list, case_num=case_num, pass_num=pass_num, fail_num=fail_num, error_num=error_num, task=None) else: Report(report_name=report_name, plant=plan, content=case_list, case_num=case_num, pass_num=pass_num, fail_num=fail_num, error_num=error_num, task=None).save() return HttpResponse(plan.plant_name + "执行成功!")