def add_item(request): #添加项目的视图 forms = Cms_projectInfo(request.POST) if forms.is_valid(): project_name = forms.cleaned_data.get("project_name") responsible_name = forms.cleaned_data.get("responsible_name") test_user = forms.cleaned_data.get("test_user") dev_user = forms.cleaned_data.get("dev_user") publish_app = forms.cleaned_data.get("publish_app") simple_desc = forms.cleaned_data.get("simple_desc") other_desc = forms.cleaned_data.get("other_desc") id = request.session.get("_auth_user_id") a = request.session.keys() print(id) print(a) user_id = User.objects.filter(pk=id).exists() if user_id: confirm = ProjectInfo.objects.filter( project_name=project_name).exists() if confirm: return restful.result(message="此项目名称已存在!") else: iteme = ProjectInfo(project_name=project_name, responsible_name=responsible_name, test_user=test_user, dev_user=dev_user, publish_app=publish_app, simple_desc=simple_desc, other_desc=other_desc) iteme.user_id = id iteme.save() return restful.result(message="添加项目成功!") else: errors = forms.get_errors() return restful.params_error(message=errors)
def edit_url(request): id=request.POST.get("id") if id: form = Cms_url(request.POST) if form.is_valid(): print("我已经执行6") host_name = form.cleaned_data.get("host_name") host_url = form.cleaned_data.get("host_url") describe = form.cleaned_data.get("describe") url_id = Urlconfiguratin.objects.filter(pk=id) if url_id: confirm = Urlconfiguratin.objects.filter(host_name=host_name).exclude(id=id).exists() print("===我已执行==") if confirm: return restful.unauth(message="您输入的环境名称已存在!") else: print("===执行不存在的项目=") url_id1= url_id.update(id=id,host_name=host_name, host_url=host_url,describe=describe) return restful.result(message="编辑环境配置成功!") else: return restful.unauth(message="您输入id不存在!") else: print("我已经执行8") errors = form.get_errors() return restful.params_error(message=errors) else: return restful.unauth(message="id号不能为空")
def time_box(request): total_result=operation_information.objects.values('function_time').distinct() data=[] for i in total_result: data.append(i) print(data) return restful.result(data=list(reversed(data)),message="成功")
def all_calculation(request): box_time=request.GET.get("box_time") print(box_time) if box_time: total_result = operation_information.objects.filter(function_time=box_time) if total_result: all_use_case = total_result.count() pass_use_case = total_result.filter(result="pass").count() fail_use_case = total_result.filter(result="fail").count() suspend_use_case = total_result.filter(~Q(result="fail") & ~Q(result="pass")).count() pass_percentage = "{}%".format((pass_use_case / all_use_case) * 100) fail_percentage = "{}%".format((fail_use_case / all_use_case) * 100) suspend_percentage = "{}%".format((suspend_use_case / all_use_case) * 100) context = { "all_use_case": all_use_case, "pass_use_case": pass_use_case, "fail_use_case": fail_use_case, "suspend_use_case": suspend_use_case, "pass_percentage": pass_percentage, "fail_percentage": fail_percentage, "suspend_percentage": suspend_percentage, } return restful.result(data=[context], message="成功") else: return restful.unauth(message="查询信息已不存在!") else: return restful.unauth(message="提交数据不能空!")
def user_list(request): id = request.session.get("_auth_user_id") if id: user = User.objects.filter(pk=id) serializers = UserSerializer(user, many=True) data = serializers.data return restful.result(data=data, message="成功") else: return restful.unauth(message="无sessionid,请重新登录")
def delete_module(request): #删除模块视图 id = request.POST.get("id") if id: url_id = ModuleInfo.objects.get(pk=id) url_id1 = url_id.usecase_set.all() if url_id1: return restful.params_error(message="此模块已被其他用例关联,不能删除!") else: if url_id: url_id.delete() return restful.result(message="删除模块成功!") else: return restful.unauth(message="该id不存在!") else: return restful.unauth(message="请输入项目id!")
def delete_item(request): #删除项目视图 id = request.POST.get("id") if id: item_id = ProjectInfo.objects.filter( id=id).prefetch_related("moduleInfo") for url_id in item_id: if url_id: return restful.params_error(message="此项目已被其他模块关联,不能删除!") else: if item_id: item_id.delete() return restful.result(message="删除项目成功!") else: return restful.unauth(message="该id不存在!") else: return restful.unauth(message="请输入项目id!")
def edit_function(request): #运行多条用例的视图 userid = request.session.get("_auth_user_id") id = request.POST.get("id") if id: all_edit = ProjectInfo.objects.get(pk=id) if all_edit: data_times = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) run_multiple_use_cases.delay(id=id, userid=userid, data_times=data_times) return restful.result(message="已运行成功!") else: return restful.unauth(message="此项目id不存在!") else: return restful.params_error(message="请输入正确的用例id!")
def delete_url(request): id=request.POST.get("id") if id: url_id=Urlconfiguratin.objects.get(pk=id) url_id1=url_id.usecase_set.all() if url_id1: return restful.params_error(message="此环境已被其他用例关联,不能删除!") else: print("我已执行") if url_id: url_id.delete() print("====已执行====") return restful.result(message="删除环境成功!") else: return restful.unauth(message="该id不存在!") else: return restful.unauth(message="请输入环境id!")
def all_calculation1(request): total_result = operation_information.objects.order_by("-data_time") total_result1 = total_result[0] all_result = operation_information.objects.filter(function_time=total_result1.function_time) all_use_case = all_result.count() pass_use_case = all_result.filter(result="pass").count() fail_use_case = all_result.filter(result="fail").count() suspend_use_case = all_result.filter(~Q(result="fail") & ~Q(result="pass")).count() pass_percentage = "{}%".format((pass_use_case / all_use_case) * 100) fail_percentage = "{}%".format((fail_use_case / all_use_case) * 100) suspend_percentage = "{}%".format((suspend_use_case / all_use_case) * 100) context = { "all_use_case": all_use_case, "pass_use_case": pass_use_case, "fail_use_case": fail_use_case, "suspend_use_case": suspend_use_case, "pass_percentage": pass_percentage, "fail_percentage": fail_percentage, "suspend_percentage": suspend_percentage, } return restful.result(data=[context], message="成功")
def edit_module(request): #编辑项目视图 id = request.POST.get("id") if id: forms = Cms_Moudle(request.POST) if forms.is_valid(): module_name = forms.cleaned_data.get("module_name") test_user = forms.cleaned_data.get("test_user") belong_project = request.POST.get("belong_project") simple_desc = forms.cleaned_data.get("simple_desc") other_desc = forms.cleaned_data.get("other_desc") module_order = forms.cleaned_data.get("module_order") module_id = ModuleInfo.objects.filter(pk=id) if module_id: confirm = ModuleInfo.objects.filter( module_name=module_name).exclude(id=id).exists() if confirm: return restful.unauth(message="您输入的项目名称已存在!") else: all_true = ModuleInfo.objects.filter( belong_project_id=belong_project).exclude( id=id).filter(module_order=module_order).exists() if all_true: return restful.unauth(message="模块运行顺序已存在!") else: module_id1 = module_id.update( id=id, module_name=module_name, test_user=test_user, belong_project_id=belong_project, simple_desc=simple_desc, other_desc=other_desc, module_order=module_order) return restful.result(message="编辑项目成功!") else: return restful.unauth(message="您输入id不存在!") else: errors = forms.get_errors() return restful.params_error(message=errors) else: return restful.unauth(message="id号不能为空")
def add_url(request):#添加环境视图 form= Cms_url(request.POST) if form.is_valid(): host_name=form.cleaned_data.get("host_name") host_url=form.cleaned_data.get("host_url") describe=form.cleaned_data.get("describe") id = request.session.get("_auth_user_id") a = request.session.keys() user_id = User.objects.filter(pk=id).exists() if user_id: confirm = Urlconfiguratin.objects.filter(host_name=host_name).exists() if confirm: return restful.unauth(message="此环境名称已存在!") else: url= Urlconfiguratin(host_name=host_name, host_url=host_url, describe=describe) url.user_id = id url.save() return restful.result(message="添加环境成功!") else: errors = form.get_errors() return restful.params_error(message=errors)
def edit_item(request): #编辑项目视图 id = request.POST.get("id") if id: forms = Cms_projectInfo(request.POST) if forms.is_valid(): project_name = forms.cleaned_data.get("project_name") responsible_name = forms.cleaned_data.get("responsible_name") test_user = forms.cleaned_data.get("test_user") dev_user = forms.cleaned_data.get("dev_user") publish_app = forms.cleaned_data.get("publish_app") simple_desc = forms.cleaned_data.get("simple_desc") other_desc = forms.cleaned_data.get("other_desc") item_id = ProjectInfo.objects.filter(pk=id) for i in item_id: print(i.project_name) print(other_desc) if item_id: confirm = ProjectInfo.objects.filter( project_name=project_name).exclude(id=id).exists() if confirm: return restful.unauth(message="您输入的项目名称已存在!") else: item_id1 = item_id.update( id=id, project_name=project_name, responsible_name=responsible_name, test_user=test_user, dev_user=dev_user, publish_app=publish_app, simple_desc=simple_desc, other_desc=other_desc) return restful.result(message="编辑项目成功!") else: return restful.unauth(message="您输入id不存在!") else: errors = forms.get_errors() return restful.params_error(message=errors) else: return restful.unauth(message="id号不能为空")
def post_password(request): password = request.POST.get("password") password1 = request.POST.get("password1") password2 = request.POST.get("password2") if not password: return restful.unauth(message="开始密码不能为空!") if not password1 or not password2: return restful.unauth(message="新密码或确认密码不能为空!") if password and password1 and password2: id = request.session.get("_auth_user_id") user = User.objects.get(pk=id) print(user.telephone) user1 = user.check_password(password) if user1: if password1 == password2: user.set_password(password1) user.save() logout(request) return restful.result(message="修改密码成功!") else: return restful.unauth(message="新密码和确认密码不一致!") else: return restful.unauth(message="始初密码输入不正确!")
def add_module(request): #添加模块视图 forms = Cms_Moudle(request.POST) if forms.is_valid(): module_name = forms.cleaned_data.get("module_name") test_user = forms.cleaned_data.get("test_user") belong_project = request.POST.get("belong_project") simple_desc = forms.cleaned_data.get("simple_desc") other_desc = forms.cleaned_data.get("other_desc") module_order = forms.cleaned_data.get("module_order") id = request.session.get("_auth_user_id") a = request.session.keys() is_module = ProjectInfo.objects.filter(pk=int(belong_project)) is_case_url = is_module.filter( moduleInfo__module_order=module_order).exists() if is_case_url: # 如果存在执行下面代码 return restful.unauth(message="此用例运行顺序已存在!") else: user_id = User.objects.filter(pk=id).exists() if user_id: confirm = ModuleInfo.objects.filter( module_name=module_name).exists() if confirm: return restful.unauth(message="此模块名称已存在!") else: iteme = ModuleInfo(module_name=module_name, test_user=test_user, simple_desc=simple_desc, other_desc=other_desc, module_order=module_order) iteme.user_id = id iteme.belong_project_id = int(belong_project) iteme.save() return restful.result(message="添加模块成功!") else: errors = forms.get_errors() return restful.params_error(message=errors)
def post(self,request,*args,**kwargs): form = LoginForm(request.POST) if form.is_valid(): telephone = form.cleaned_data.get("telephone") password = form.cleaned_data.get("password") pwd=base64.b64decode(password).decode("utf-8") remember = form.cleaned_data.get("remember") user = authenticate(request, username=telephone, password=pwd) if user: if user.is_active: login(request, user) if remember: request.session.set_expiry(None) else: request.session.set_expiry(0) return restful.result(message="登录成功") else: # 用户不使用执行下面代码 return restful.unauth(message="您的账号已被冻结") else: return restful.params_error(message={"password": ["您输入的账号或密码错误"]}) else: errors = form.get_errors() return restful.params_error(message=errors)
def post(self,request,*args,**kwargs): logout(request) return restful.result(message="退出成功")
def edit_details(request): userid = request.session.get("_auth_user_id") id = request.POST.get("id") if id: all_edit = ProjectInfo.objects.get(pk=id) if all_edit: module_prefetch = Prefetch( "moduleInfo", queryset=ModuleInfo.objects.order_by("module_order")) use_prefetch = Prefetch( "usecase_set", queryset=Usecase.objects.order_by("case_order")) operation = Prefetch( "operation_information_set", queryset=operation_information.objects.filter( use_case_mode="many").order_by("-data_time")) module_data = ProjectInfo.objects.filter( id=id).prefetch_related(module_prefetch) use_data = ModuleInfo.objects.prefetch_related(use_prefetch) use_case = Usecase.objects.prefetch_related(operation) a = operation_information.objects.filter( use_case_mode="many").order_by("-data_time") print(a.exists()) all_result = [] for i in module_data: print(i.project_name) module_all = i.moduleInfo.all() if module_all: for sub_data in module_all: for use_data_all in use_data: if sub_data.module_name == use_data_all.module_name: print(use_data_all.module_name) usecase_data_all = use_data_all.usecase_set.all( ) if usecase_data_all: usecase2 = use_data_all.usecase_set.count() print("======") print(usecase2) else: usecase2 = 0 if usecase_data_all: for usecase in usecase_data_all: for use_ca in use_case: if usecase.case_name == use_ca.case_name: result = [] operation_all = use_ca.operation_information_set.all( ) print("333333") print(len(operation_all)) if operation_all: if len(operation_all) == 1: serializer = operation_informationSerializer( operation_all, many=True) data = serializer.data[ -1] all_result.append(data) print("hahah") else: serializer = operation_informationSerializer( operation_all, many=True) data = list( reversed( serializer.data ))[-1] all_result.append(data) else: pass else: #不存在关联用例执行下面 pass else: #不存在关联模块执行下面 pass return restful.result(data=all_result, message="请求成功!") else: return restful.unauth(message="此项目id不存在!") else: return restful.params_error(message="请输入正确的用例id!")