def post(self, request): """ post方法,设置登录密码 :return: """ logger.info('设置登录密码接口') data = request.data logger.info("开始修改密码") password1 = data.get('password_1') password2 = data.get('password_2') logger.info("修改的用户ID为: {}".format(data['user_id'])) if password1 != password2: logger.error('密码不一致,请重新输入') return ReturnJson.faile(UserEnumeration.PASSWORD_INPUT_ERROR.value) else: user_info = OpsUser.objects.get(id=int(data['user_id'])) logger.info("获取到的用户信息为: {}".format(user_info)) try: user_info.set_password(password2) logger.info("修改密码中") user_info.save() logger.info("修改密码成功") return ReturnJson.success("重置密码成功") except Exception as e: logger.error('修改密码失败:{}'.format(e)) return ReturnJson.faile(UserEnumeration.SET_PASSWORD_ERROR.value)
def put(self, requests): """ 修改迭代信息 :param requests: :return: """ logger.info('开始执行更新迭代信息接口') data = requests.data # username = requests.user.username user_id = requests.user.id logger.info(str(data)) try: data_obj = IterationForJobCenter.objects.get(id=int(data['data_id'])) if data.__contains__('name'): data_obj.name = data['name'] if data.__contains__('state'): data_obj.state = data['state'] if data.__contains__('description'): data_obj.description = data['description'] if data.__contains__('pro_id'): data_obj.pro_id = int(data['pro_id']) if data.__contains__('version_id'): data_obj.version_id = int(data['version_id']) if data.__contains__('abandon_flag'): data_obj.abandon_flag = int(data['abandon_flag']) data_obj.updated_by_id = user_id data_obj.save() return ReturnJson.success(int(data_obj.id)) except Exception as ex: logger.error(ex) return ReturnJson.faile(JobCenterEnumeration.UPDATE_IT_STATE_ERROR.value)
def post(self, request): """ post方法 新增菜单 :param request: :return: """ logger.info('开始执行新增菜单接口') data = request.data logger.info('开始进行参数校验') logger.info(str(data)) params_list = ['title', 'order', 'url'] for params in params_list: if not data.__contains__(params) or data[params] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) logger.info('参数校验通过') sid = transaction.savepoint() try: add_menu = MenuSerializer(data=data) add_menu.is_valid(raise_exception=True) new_menu = add_menu.save() if data.__contains__('parent_id'): info = Menu.objects.get(id=new_menu.id) info.parent_id = data['parent_id'] info.save() transaction.savepoint_commit(sid) except Exception as ex: logger.error(ex) transaction.savepoint_rollback(sid) return ReturnJson.faile(UserEnumeration.CREATE_MENU_ERROR.value) else: logger.info('新增菜单成功') return ReturnJson.success('新增成功')
def post(self, requests): """ post,创建迭代接口 :param requests: :return: """ logger.info('开始执行创建迭代接口') data = requests.data # username = requests.user.username user_id = requests.user.id logger.info(str(data)) try: info = { 'name': data['name'], 'state': 10, 'description': data['description'], } context = { 'created_by_id': user_id, 'updated_by_id': user_id, 'pro_id': int(data['pro_id']), 'version_id': int(data['version_id']) } m_data = IterationSerializer(data=info, context=context) m_data.is_valid(raise_exception=True) data_obj = m_data.save() jobs = [int(r) for r in data['jobs']] data_obj.job.add(*jobs) return ReturnJson.success(int(data_obj.id)) except Exception as ex: logger.error(ex) return ReturnJson.faile(JobCenterEnumeration.GET_JOB_INFO_ERROR.value)
def post(self, request): """ 新增项目的版本号配置 :param request: :return: """ logger.info('开始执行新增项目的版本号配置接口') data = request.data user_id = request.user.id logger.info("新增数据:{}".format(data)) try: # data = eval(data) context = { 'created_by_id': user_id, 'updated_by_id': user_id, 'pro_id': int(data['pro_id']), } if VersionForProject.objects.filter(type=data['type'], pro_id=int(data['pro_id'])): logger.error("新增项目版本号配置失败: {}".format( BaseEnumeration.CREATE_SYS_VERSION_REPEAT_ERROR.value)) return ReturnJson.faile( BaseEnumeration.CREATE_SYS_VERSION_REPEAT_ERROR.value) new_ver = VersionForProjectSerializer(data=data, context=context) new_ver.is_valid(raise_exception=True) new_ver.save() except Exception as ex: logger.error(ex) return ReturnJson.faile( BaseEnumeration.CREATE_SYS_VERSION_ERROR.value) else: logger.info('新增项目的版本号配置成功') return ReturnJson.success('新增成功')
def post(self, request): """ post方法,添加配置 :return: """ logger.info('开始执行资源库添加配置接口') data = request.data user_id = request.user.id logger.info(str(data)) try: context = { "pro_id": data["pro_id"], 'created_by_id': user_id, 'updated_by_id': user_id, } if ConfigForResources.objects.filter(key=data['key'], value=data['value'], pro_id=int(data["pro_id"])): logger.error("新增资源库添加配置失败: {}".format( ResourceEnumeration.CONFIG_REPEAT_ERROE.value)) return ReturnJson.faile( ResourceEnumeration.CONFIG_REPEAT_ERROE.value) # 使用序列化创建数据 new_config = ConfigForResourcesSerializer(data=data, context=context) new_config.is_valid(raise_exception=True) new_config.save() logger.info('资源库新增配置成功') return ReturnJson.success('资源库新增配置成功') except Exception as ex: logger.error("新增资源库添加配置失败: {}".format(ex)) return ReturnJson.faile( ResourceEnumeration.CREATE_CONFIG_ERROE.value)
def post(self, requests): """ 根据子任务ID,获取测试用例执行数据 :param requests: :return: """ data = requests.data logger.info("根据子任务ID,获取测试用例执行数据。{}".format(data)) # user = requests.user.username user_id = requests.user.id logger.info("查询人为: {}".format(user_id)) try: logger.info("开始查询用例执行信息") obj_data = SubJobDataForJobCenter.objects.filter(job_id=int(data['data_id'])) result_data = [] for i in obj_data: data = {} data.update(model_to_dict(i)) data['case_name'] = i.case.case_name data['case_type'] = i.case.case_type.param_name result_data.append(data) return ReturnJson.success(result_data) except Exception as e: logger.error("查询用例执行信息失败: {}".format(e)) return ReturnJson.faile(JobCenterEnumeration.GET_REPORT_CASE_INTO_ERROR.value)
def post(self, request): """ post方法,为接口数据创建测试用例 :param request: :return: """ logger.info('开始执行接口数据创建测试用例接口') data = request.data user_id = request.user.id logger.info(str(data)) sid = transaction.savepoint() try: logger.info('获取接口数据') re_info = RequestsForResources.objects.get( id=int(data['re_id'])).__dict__ # logger.info(str(re_info)) info = CreateTestCase(re_info, data, user_id) result = info.CreateTestCaseData() if result['status'] == 110: logger.error(result['errorMsg']) transaction.rollback(sid) return ReturnJson.faile( ResourceEnumeration.CREATE_CASE_ERROR.value) except Exception as ex: logger.error(ex) transaction.rollback(sid) return ReturnJson.faile( ResourceEnumeration.CREATE_CASE_ERROR.value) else: logger.info("接口执行正常,提交事务") transaction.savepoint_commit(sid) re_data = RequestsForResources.objects.get(id=int(data['re_id'])) re_data.if_have_case = 0 re_data.save() return ReturnJson.success('新增成功')
def post(self, request): """ post方法 新增角色 :param request: :return: """ logger.info('开始执行新增角色接口') data = request.data logger.info('开始进行参数校验') logger.info(str(data)) if not data.__contains__('title') or data['title'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) logger.info('参数校验通过') try: new_role = Role() new_role.title = data['title'] new_role.save() for i in data['role_list']: new_role.permissions.add(i) except Exception as ex: logger.error(ex) return ReturnJson.faile(UserEnumeration.CREATE_MENU_ERROR.value) else: logger.info('新增角色成功') return ReturnJson.success('新增成功')
def post(self, request): """ post方法,添加系统参数配置 :return: """ logger.info('开始执行添加系统参数配置接口') data = request.data logger.info(str(data)) user_id = request.user.id logger.info("新增数据:{}".format(data)) try: context = { 'created_by_id': user_id, 'updated_by_id': user_id, } if BaseSysParam.objects.filter(param_key=data['param_key'], param_value=data['param_value']): logger.error("新增系统参数配置失败: {}".format( BaseEnumeration.CREATE_SYS_PARAM_REPEAT_ERROR.value)) return ReturnJson.faile( BaseEnumeration.CREATE_SYS_PARAM_REPEAT_ERROR.value) new_sys = BaseSysParamSerializer(data=data, context=context) new_sys.is_valid(raise_exception=True) new_sys.save() except Exception as ex: logger.error("新增系统参数配置失败: {}".format(ex)) return ReturnJson.faile( BaseEnumeration.CREATE_SYS_PARAM_ERROR.value) else: logger.info('新增系统参数配置成功') return ReturnJson.success('新增成功')
def post(self, requests): """ post方法,执行任务 :param requests: :return: """ logger.info('开始执行 执行任务接口') data = requests.data # username = requests.user.username user_id = requests.user.id logger.info(str(data)) job_id = data["job_id"] try: exe_obj = ExeSubJob() exe_result = exe_obj.exeSubJob(job_id, user_id) if exe_result['state'] == 110: return ReturnJson.faile(JobCenterEnumeration.EXE_SUB_JOB_ERROR.value) return ReturnJson.success("任务执行完毕,请在报告管理中,查看任务状态。") except Exception as ex: logger.error(ex) return ReturnJson.faile(JobCenterEnumeration.EXE_SUB_JOB_ERROR.value)
def put(self, request): """ put方法,更新菜单信息 :param request: :return: """ logger.info('开始执行更新菜单信息接口') data = request.data logger.info('开始更新数据') logger.info(str(data)) try: if not data.__contains__('menu_id') or data['menu_id'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) menu_info = Menu.objects.filter(id=int(data['menu_id'])).first() if data.__contains__('title'): menu_info.title = data['title'] if data.__contains__('icon'): menu_info.icon = data['icon'] if data.__contains__('abandon_flag'): menu_info.abandon_flag = data['abandon_flag'] menu_info.save() except Exception as ex: logger.error(ex) return ReturnJson.faile(UserEnumeration.CREATE_MENU_ERROR.value) else: logger.info('更新菜单信息成功') return ReturnJson.success('更新成功')
def put(self, request): """ put方法,更新角色信息 :param request: :return: """ logger.info('开始执行更新权限菜单信息') data = request.data logger.info('开始更新数据') logger.info(str(data)) try: if not data.__contains__('role_id') or data['role_id'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) role_info = Role.objects.get(id=int(data['role_id'])) if data.__contains__('title'): role_info.title = data['title'] if data.__contains__('abandon_flag'): role_info.abandon_flag = data['abandon_flag'] if data.__contains__('per_list'): g_per_list = data['per_list'] role_info.permissions.clear() [role_info.permissions.add(menu) for menu in g_per_list] role_info.save() except Exception as ex: logger.error(ex) return ReturnJson.faile(UserEnumeration.CREATE_MENU_ERROR.value) else: logger.info('更新菜单信息成功') return ReturnJson.success('更新成功')
def put(self, requests): """ 更新测试用例数据状态 :param requests: :return: """ data = requests.data logger.info("更新的测试用例信息为: {}".format(data)) user_id = requests.user.id logger.info("更新人为: {}".format(user_id)) try: if not data.__contains__('data_id') or data['data_id'] == '': return ReturnJson.faile(CaseEnumeration.GET_INFO_ERROR.value) logger.info("查找测试用例数据并更新") data_obj = CaseInfoForCaseCenter.objects.get( id=int(data['data_id'])) sid = transaction.savepoint() if data_obj: if data.__contains__('case_name'): data_obj.case_name = data['case_name'] if data.__contains__('if_update'): data_obj.if_update = data['if_update'] if data.__contains__('description'): data_obj.description = data['description'] if data.__contains__('pro_id'): data_obj.pro_id = int(data['pro_id']) if data.__contains__('abandon_flag'): data_obj.abandon_flag = int(data['abandon_flag']) if data.__contains__('case_type_id'): data_obj.case_type_id = int(data['case_type_id']) if data.__contains__('case_suite_id'): data_obj.case_suite_id = int(data['case_suite_id']) data_obj.updated_by_id = user_id data_obj.save() if data.__contains__('abandon_flag'): logger.error("更新内容有数据状态,开始更新测试步骤状态") try: CaseStepForCaseCenter.objects.filter( case=int(data['data_id'])).update( abandon_flag=data['abandon_flag'], updated_at=time.strftime('%Y-%m-%d %H:%M:%S'), updated_by_id=user_id) except Exception as e: logger.error("更新测试步骤状态失败: {}".format(e)) return ReturnJson.faile( CaseEnumeration.UPDATE_CASE_STEP_ERROR.value) logger.info("状态更新成功") transaction.savepoint_commit(sid) return ReturnJson.success("状态更新成功") else: transaction.savepoint_rollback(sid) logger.error("更新测试用例状态失败,用例不存在") return ReturnJson.faile( CaseEnumeration.UPDATE_CASE_ERROR.value) except Exception as e: logger.error("更新测试用例状态失败: {}".format(e)) return ReturnJson.faile(CaseEnumeration.UPDATE_CASE_ERROR.value)
def put(self, request): """ post方法,更新用户信息 :param request: :return: """ logger.info('开始执行更新用户信息接口') data = request.data logger.info('开始进行参数校验:{}'.format(data)) if not data.__contains__('user_id') or data['user_id'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) # 开始检测用户是否已注册 # 条件1:用户名不可重复 # a = OpsUser.objects.filter(username=data['username']).exclude(id=data['user_id']) logger.info('参数校验通过') sid = transaction.savepoint() try: logger.info('开始更新用户信息') user = OpsUser.objects.get(id=data['user_id']) if data.__contains__('username'): if OpsUser.objects.filter(username=data['username']).exclude(id=data['user_id']): return ReturnJson.faile(UserEnumeration.REGISTER_USERNAME_FORGET_ERROR.value) else: user.username = data['username'] if data.__contains__('last_name'): user.last_name = data['last_name'] if data.__contains__('first_name'): user.first_name = data['first_name'] if data.__contains__('department'): user.department = data['department'] if data.__contains__('mobile_no'): user.mobile_no = data['mobile_no'] if data.__contains__('email'): user.email = data['email'] if data.__contains__('abandon_flag'): user.is_active = int(data['abandon_flag']) # 更改角色和项目 if data.__contains__('roles'): roles = [int(r) for r in data['roles']] user.role.clear() user.role.add(*roles) if data.__contains__('pros'): pros = [int(r) for r in data['pros']] user.pro.clear() user.pro.add(*pros) user.save() logger.info('更新用户信息成功') transaction.savepoint_commit(sid) return ReturnJson.success("更新用户信息成功") except Exception as e: logger.error('更新用户信息失败:{}'.format(e)) transaction.rollback(sid) return ReturnJson.faile(UserEnumeration.UPDATE_USER_INFO_ERROR.value)
def put(self, request): """ put方法,更新配置 :return: """ logger.info('开始执行更新配置接口') data = request.data user_id = request.user.id logger.info(str(data)) try: if not data.__contains__('config_id') or data['config_id'] == '': return ReturnJson.faile( ResourceEnumeration.CONFIG_ID_ERROR.value) config_info = ConfigForResources.objects.filter( id=int(data['config_id'])).first() if data.__contains__('key'): if ConfigForResources.objects.filter( key=data['key'], value=data['value'], pro_id=int(data["pro_id"])).exclude( id=int(data['config_id'])): logger.error("更新资源库添加配置失败: {}".format( ResourceEnumeration.CONFIG_REPEAT_ERROE.value)) return ReturnJson.faile( ResourceEnumeration.CONFIG_REPEAT_ERROE.value) config_info.key = data['key'] if data.__contains__('value'): if ConfigForResources.objects.filter( key=data['key'], value=data['value'], pro_id=int(data["pro_id"])).exclude( id=int(data['config_id'])): logger.error("更新资源库添加配置失败: {}".format( ResourceEnumeration.CONFIG_REPEAT_ERROE.value)) return ReturnJson.faile( ResourceEnumeration.CONFIG_REPEAT_ERROE.value) config_info.value = data['value'] if data.__contains__('name'): config_info.name = data['name'] if data.__contains__('description'): config_info.description = data['description'] if data.__contains__('pro_id'): config_info.pro_id = int(data['pro_id']) if data.__contains__('abandon_flag'): config_info.abandon_flag = int(data['abandon_flag']) config_info.updated_by_id = user_id config_info.save() except Exception as ex: logger.error("更新资源库添加配置失败: {}".format(ex)) return ReturnJson.faile( ResourceEnumeration.UPDATE_CONFIG_ERROE.value) else: logger.info('更新配置成功') return ReturnJson.success('更新成功')
def post(self, request): """ 登录接口 :param request: :return: """ logger.info('进入登录接口 --- 开始校验请求参数') data = request.POST.dict() logger.info(str(data)) if not data.__contains__('info') or not data.__contains__('pwd'): # return JsonResponse({'status': 201, 'msg': '用户名/密码为空,请重新输入'}) error_msg = "用户名/密码为空,请重新输入" logger.error('用户名/密码为空,请重新输入') return ReturnJson.faile(error_msg) # return render(request, 'login.html', locals()) logger.info('判断用户是否存在') try: info = OpsUser.objects.values('id', 'username').filter( Q(mobile_no=data['info']) | Q(email=data['info']) | Q(username=data['info'])) if bool(info): logger.info('用户存在开始登录') username = info[0]['username'] user = auth.authenticate(username=username, password=data['pwd']) if user: if user.is_active: logger.info('开始登录') auth.login(request, user) logger.info('登录成功,开始添加权限') logger.info(info[0]) request.session['user_id'] = info[0]['id'] # 用户id注入session # 将权限列表和权限菜单列表注入session initial_session(info[0]['id'], request) # initial_session(user, request) logger.info('添加页面权限菜单') return ReturnJson.success('登录成功') # return HttpResponseRedirect('/BaseCenter/WorkbenchIndex/') else: error_msg = "该用户已被禁,请联系管理员" logger.error('该用户已被禁,请联系管理员') return ReturnJson.faile(error_msg) # return render(request, 'login.html', locals()) else: error_msg = "用户名密码错误,请重新输入" logger.error('用户名密码错误,请重新输入') # error_msg = "请重新核对您的用户名和密码" # logger.error('user为空') return ReturnJson.faile(error_msg) # return render(request, 'login.html', locals()) except Exception as ex: error_msg = "系统异常,请稍后再试" logger.error(ex) return ReturnJson.faile(error_msg)
def put(self, request): """ put方法,更新系统参数配置 :return: """ logger.info('开始执行更新系统参数配置接口') data = request.data user_id = request.user.id logger.info(str(data)) try: if not data.__contains__('sys_id') or data['sys_id'] == '': return ReturnJson.faile( BaseEnumeration.SYS_PARAM_ID_ERROR.value) sys_info = BaseSysParam.objects.get(id=int(data['sys_id'])) if data.__contains__('param_key'): if BaseSysParam.objects.filter( param_key=data['param_key'], param_name=data['param_value']).exclude( id=int(data['sys_id'])): logger.error("更新系统参数配置失败: {}".format( BaseEnumeration.CREATE_SYS_PARAM_REPEAT_ERROR.value)) return ReturnJson.faile( BaseEnumeration.CREATE_SYS_PARAM_REPEAT_ERROR.value) sys_info.param_key = data['param_key'] if data.__contains__('param_value'): if BaseSysParam.objects.filter( param_key=data['param_key'], param_name=data['param_value']).exclude( id=int(data['sys_id'])): logger.error("更新系统参数配置失败: {}".format( BaseEnumeration.CREATE_SYS_PARAM_REPEAT_ERROR.value)) return ReturnJson.faile( BaseEnumeration.CREATE_SYS_PARAM_REPEAT_ERROR.value) sys_info.param_value = data['param_value'] if data.__contains__('param_name'): sys_info.param_name = data['param_name'] if data.__contains__('description'): sys_info.description = data['description'] if data.__contains__('abandon_flag'): sys_info.abandon_flag = int(data['abandon_flag']) sys_info.updated_by_id = user_id sys_info.save() except Exception as ex: logger.error("更新系统参数配置失败: {}".format(ex)) return ReturnJson.faile( BaseEnumeration.UPDATE_SYS_PARAM_ERROR.value) else: logger.info('更新系统参数配置成功') return ReturnJson.success('更新成功')
def put(self, requests): """ 更新测试集合数据状态 :param requests: :return: """ data = requests.data logger.info("更新的测试集合信息为: {}".format(data)) user = requests.user.username logger.info("更新人为: {}".format(user)) try: logger.info("查找测试集合数据并更新") suite_obj = CaseSuiteForCaseCenter.objects.get( id=int(data['data_id'])) sid = transaction.savepoint() if suite_obj: suite_obj.abandon_flag = data['abandon_flag'] suite_obj.save() case_list = suite_obj.case_id.all() case_id_list = [int(info.id) for info in case_list] try: CaseInfoForCaseCenter.objects.filter(id__in=case_id_list)\ .update(abandon_flag=data['abandon_flag'], updated_at=time.strftime('%Y-%m-%d %H:%M:%S'), updated_by=user) try: CaseStepForCaseCenter.objects.filter(case__in=case_id_list)\ .update(abandon_flag=data['abandon_flag'], updated_at=time.strftime('%Y-%m-%d %H:%M:%S'), updated_by=user) except Exception as e: logger.error("更新测试步骤状态失败: {}".format(e)) transaction.savepoint_rollback(sid) return ReturnJson.faile( CaseEnumeration.UPDATE_CASE_STEP_ERROR.value) except Exception as e: transaction.savepoint_rollback(sid) logger.error("更新测试用例状态失败: {}".format(e)) return ReturnJson.faile( CaseEnumeration.UPDATE_CASE_ERROR.value) logger.info("状态更新成功") transaction.savepoint_commit(sid) return ReturnJson.success("状态更新成功") else: transaction.savepoint_rollback(sid) logger.error("更新测试集合状态失败,集合不存在") return ReturnJson.faile( CaseEnumeration.UPDATE_SUITE_ERROR.value) except Exception as e: logger.error("更新测试集合状态失败: {}".format(e)) return ReturnJson.faile(CaseEnumeration.UPDATE_SUITE_ERROR.value)
def get(self, request): """ 获取接口列表 :param request: :return: """ # 搜索数据 # data = request.data # logger.info("搜索数据:{}".format(data)) data = request.GET.get('search_data') logger.info("获取接口列表,搜索数据:{}".format(data)) try: if data: search_data = {} data = eval(data) if data.__contains__('project__parent__id__in'): data['project__parent__id__in'] = eval( data['project__parent__id__in']) for key, value in data.items(): if bool(key) and bool(value): search_data[key] = data[key] roles = RequestsForResources.objects.filter( **search_data).order_by('-abandon_flag', '-id') # 自定义分页实例化 page = GoodsPagination() # 根据分页查询数据 page_roles = page.paginate_queryset(queryset=roles, request=request, view=self) # 对查询数据进行序列化 roles_ser = RequestsListSerializer(instance=page_roles, many=True) # 返回数据,以及前后页的url result_info = page.get_paginated_response(roles_ser.data) # return Response(roles_ser.data) # 只返回数据 return result_info else: # 没有搜索条件和搜索类型,那么默认为显示全部信息 # 根据id排序,搜索数据 # roles = RequestsForResources.objects.get_queryset().order_by('-id').filter(abandon_flag=1) roles = RequestsForResources.objects.order_by('-id').filter( abandon_flag=1) # 自定义分页实例化 page = GoodsPagination() # 根据分页处理数据 page_roles = page.paginate_queryset(queryset=roles, request=request, view=self) # 查询数据序列化处理 roles_ser = RequestsListSerializer(instance=page_roles, many=True) # 返回数据,以及前后页的url result_info = page.get_paginated_response(roles_ser.data) # return Response(roles_ser.data) # 只返回数据 return result_info except Exception as e: logger.error(e) return ReturnJson.faile(ResourceEnumeration.SYS_ERROE.value)
def post(self, request): """ post 退出登录接口 :param request: :return: """ user_id = request.user.id logger.info("用户" + str(user_id) + "退出登录") try: auth.logout(request) request.session.clear() # return HttpResponseRedirect('/login/', locals()) return ReturnJson.success('退出成功') except Exception as ex: logger.error(ex) return ReturnJson.faile(UserEnumeration.SIGNOUT_ERROR.value)
def put(self, request): """ post方法,更新项目配置 :return: """ logger.info('开始执行更新项目配置接口') data = request.data logger.info(str(data)) user_id = request.user.id try: if not data.__contains__('project_id') or data['project_id'] == '': return ReturnJson.faile(BaseEnumeration.PROJECT_ID_ERROR.value) pro_info = ProjectForBase.objects.get(id=int(data['project_id'])) if data.__contains__('project_name'): if ProjectForBase.objects.filter( project_name=data['project_name'], parent_id=int(data['parent_id'])).exclude( id=int(data['project_id'])): logger.error("新增项目配置失败: {}".format( BaseEnumeration.CREATE_PROJECT_DATA_ERROR.value)) return ReturnJson.faile( BaseEnumeration.CREATE_PROJECT_DATA_ERROR.value) pro_info.project_name = data['project_name'] if data.__contains__('project_type'): pro_info.project_type = data['project_type'] if data.__contains__('project_code'): pro_info.project_code = data['project_code'] if data.__contains__('description'): pro_info.description = data['description'] if data.__contains__('parent_id'): pro_info.parent_id = int(data['parent_id']) if data.__contains__('abandon_flag'): pro_info.abandon_flag = int(data['abandon_flag']) pro_info.updated_by_id = user_id pro_info.save() except Exception as ex: logger.error(ex) return ReturnJson.faile(BaseEnumeration.UPDATE_PROJECT_ERROR.value) else: logger.info('更新项目配置成功') return ReturnJson.success('更新成功')
def post(self, request): """ post方法 新增用户 :param request: :return: """ logger.info('开始执行新增用户接口') data = request.data logger.info('开始进行参数校验') logger.info(str(data)) if not data.__contains__('username') or data['username'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) if not data.__contains__('password') or data['password'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) if not data.__contains__('last_name') or data['last_name'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) if not data.__contains__('first_name') or data['first_name'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) if not data.__contains__('department') or data['department'] == '': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) if not data.__contains__('roles') or len(data['roles']) == '0': return ReturnJson.faile(UserEnumeration.REGISTER_USER_TYPE_ERROR.value) logger.info('参数校验通过') # 开始检测用户是否已注册 # 条件1:用户名不可重复 if OpsUser.objects.filter(username=data['username']): return ReturnJson.faile(UserEnumeration.REGISTER_USERNAME_FORGET_ERROR.value) sid = transaction.savepoint() try: logger.info('用户不存在,开始创建新用户') user_info = OpsUser.objects.create_user(username=data['username'], password=data['password']) user_info.last_name = data['last_name'] user_info.first_name = data['first_name'] user_info.mobile_no = data['mobile_no'] user_info.email = data['email'] user_info.department = data['department'] user_info.save() logger.info("给用户添加角色") for i in data['roles']: user_info.role.add(i) logger.info("给用户添加角色成功") except Exception as ex: logger.error(ex) transaction.rollback(sid) return ReturnJson.faile(UserEnumeration.REGISTER_ERROR.value) else: transaction.savepoint_commit(sid) return ReturnJson.success('新增成功')
def post(self, requests): """ 根据用例ID和报告ID,获取测试用例步骤执行详情 :param requests: :return: """ data = requests.data logger.info("根据用例ID和报告ID,获取测试用例步骤执行详情。{}".format(data)) # user = requests.user.username user_id = requests.user.id logger.info("查询人为: {}".format(user_id)) try: logger.info("开始查询用例执行信息") result_data = JobReportInfoForJobCenter.objects.filter(case_id=int(data['case_id']), report_id=int(data['report_id'])).exclude( step_id__isnull=True) return ReturnJson.success([model_to_dict(re_data) for re_data in result_data]) except Exception as e: logger.error("查询用例执行信息失败: {}".format(e)) return ReturnJson.faile(JobCenterEnumeration.GET_REPORT_CASE_INTO_ERROR.value)
def get(self, request): """ 项目的版本号配置,列表和搜索 :param request: :return: """ data = request.GET.get('search_data') logger.info("系统参数配置列表,搜索数据:{}".format(data)) try: if data: search_data = {} data = eval(data) for key, value in data.items(): if bool(key) and bool(value): search_data[key] = data[key] roles = VersionForProject.objects.filter( **search_data).order_by('-abandon_flag', '-id') # 自定义分页实例化 page = GoodsPagination() # 根据分页查询数据 page_roles = page.paginate_queryset(queryset=roles, request=request, view=self) # 对查询数据进行序列化 roles_ser = VersionForProjectListSerializer( instance=page_roles, many=True) # 返回数据,以及前后页的url result_info = page.get_paginated_response(roles_ser.data) # return Response(roles_ser.data) # 只返回数据 return result_info else: # 没有搜索条件和搜索类型,那么默认为显示全部信息 # 根据id排序,搜索数据 # roles = VersionForProject.objects.get_queryset().order_by('-id') roles = VersionForProject.objects.get_queryset().order_by( '-abandon_flag', '-id') # 自定义分页实例化 page = GoodsPagination() # 根据分页处理数据 page_roles = page.paginate_queryset(queryset=roles, request=request, view=self) # 查询数据序列化处理 roles_ser = VersionForProjectListSerializer( instance=page_roles, many=True) # 返回数据,以及前后页的url result_info = page.get_paginated_response(roles_ser.data) # return Response(roles_ser.data) # 只返回数据 return result_info except Exception as e: logger.error(e) return ReturnJson.faile(BaseEnumeration.SYS_PARAM_ID_ERROR.value)
def post(self, requests): """ post方法创建测试任务 :param requests: :return: """ logger.info('开始执行创建测试任务接口') data = requests.data # username = request.user.username user_id = requests.user.id logger.info(str(data)) # 判断并获取请求头 domain_path = data["domain_info"] sid = transaction.savepoint() addJob = CreateJobData(data, user_id, domain_path) result = addJob.createJob() if result['state'] == 110: logger.error(result['data']) transaction.rollback(sid) return ReturnJson.faile(JobCenterEnumeration.CREATE_JOB_ERROR.value) transaction.savepoint_commit(sid) return ReturnJson.success(int(result['data']))
def put(self, request): """ 更改项目的版本号配置 :param request: :return: """ logger.info('开始执行更新项目的版本号配置接口') data = request.data user_id = request.user.id logger.info("更新数据:{}".format(data)) try: if not data.__contains__('id') or data['id'] == '': return ReturnJson.faile( BaseEnumeration.SYS_PARAM_ID_ERROR.value) info = VersionForProject.objects.get(id=int(data['id'])) if data.__contains__('info'): if VersionForProject.objects.filter( type=data['info'], pro_id=int( data['pro_id'])).exclude(id=int(data['id'])): logger.error("更新项目版本号配置失败: {}".format( BaseEnumeration.CREATE_SYS_VERSION_REPEAT_ERROR.value)) return ReturnJson.faile( BaseEnumeration.CREATE_SYS_VERSION_REPEAT_ERROR.value) info.type = data['info'] if data.__contains__('description'): info.description = data['description'] if data.__contains__('abandon_flag'): info.abandon_flag = data['abandon_flag'] if data.__contains__('pro_id'): info.pro_id = data['pro_id'] info.updated_by_id = user_id info.save() except Exception as ex: logger.error(ex) return ReturnJson.faile( BaseEnumeration.UPDATE_SYS_VERSION_ERROR.value) else: logger.info('更新项目的版本号配置成功') return ReturnJson.success('更新项目版本号配置成功')
def post(self, request): """ post方法,添加项目配置 :return: """ logger.info('开始执行添加项目配置接口') data = request.data logger.info(str(data)) user_id = request.user.id try: if data.__contains__('parent_id'): context = { 'created_by_id': user_id, 'updated_by_id': user_id, 'parent_id': int(data['parent_id']) } else: context = { 'created_by_id': user_id, 'updated_by_id': user_id, } if ProjectForBase.objects.filter(project_name=data['project_name'], parent_id=int(data['parent_id'])): logger.error("新增项目配置失败: {}".format( BaseEnumeration.CREATE_PROJECT_DATA_ERROR.value)) return ReturnJson.faile( BaseEnumeration.CREATE_PROJECT_DATA_ERROR.value) new_pro = ProjectSerializer(data=data, context=context) new_pro.is_valid(raise_exception=True) new_pro.save() except Exception as ex: logger.error(ex) logger.error(str(BaseEnumeration.CREATE_PROJECT_ERROR.value)) return ReturnJson.faile(BaseEnumeration.CREATE_PROJECT_ERROR.value) else: logger.info('新增项目配置成功') return ReturnJson.success('新增成功')
def get(self, requests): """ 获取迭代执行记录,包含查询 :param requests: :return: """ data = requests.GET.get('search_data') logger.info("获取迭代执行列表,搜索数据:{}".format(data)) try: if data: search_data = {} data = eval(data) data['it__pro__id__in'] = eval(data['it__pro__id__in']) if data.__contains__('it__id'): data['it_id'] = int(data['it_id']) for key, value in data.items(): if bool(key) and bool(value): search_data[key] = data[key] roles = IterationRecordForJobCenter.objects.filter(**search_data).order_by('-abandon_flag', '-id') # 自定义分页实例化 page = GoodsPagination() # 根据分页查询数据 page_roles = page.paginate_queryset(queryset=roles, request=requests, view=self) # 对查询数据进行序列化 roles_ser = IterationListRecordSerializer(instance=page_roles, many=True) # 返回数据,以及前后页的url result_info = page.get_paginated_response(roles_ser.data) # return Response(roles_ser.data) # 只返回数据 return result_info else: # 没有搜索条件和搜索类型,那么默认为显示全部信息 # 根据id排序,搜索数据 roles = IterationRecordForJobCenter.objects.get_queryset().order_by('-abandon_flag', '-id').filter(abandon_flag=1) # 自定义分页实例化 page = GoodsPagination() # 根据分页处理数据 page_roles = page.paginate_queryset(queryset=roles, request=requests, view=self) # 查询数据序列化处理 roles_ser = IterationListRecordSerializer(instance=page_roles, many=True) # 返回数据,以及前后页的url result_info = page.get_paginated_response(roles_ser.data) # return Response(roles_ser.data) # 只返回数据 return result_info except Exception as e: logger.error(e) return ReturnJson.faile(JobCenterEnumeration.GET_INFO_ERROR.value)
def put(self, requests): """ 更新父任务相关数据状态 :param requests: :return: """ data = requests.data logger.info("更新的父任务信息为: {}".format(data)) # user = requests.user.username user_id = requests.user.id logger.info("更新人为: {}".format(user_id)) try: logger.info("查找父任务相关信息并更新") data_obj = JobInfoForJobCenter.objects.get(id=int(data['data_id'])) sid = transaction.savepoint() if data_obj: data_obj.abandon_flag = data['abandon_flag'] data_obj.save() try: JobDataForJobCenter.objects.filter(job__id=int(data['data_id']))\ .update(abandon_flag=data['abandon_flag'], updated_at=time.strftime('%Y-%m-%d %H:%M:%S'), updated_by_id=user_id) try: sub_job_list = SubJobInfoForJobCenter.objects.filter(job__id=int(data['data_id'])) sub_job_list.update(abandon_flag=data['abandon_flag'], updated_at=time.strftime('%Y-%m-%d %H:%M:%S'), updated_by_id=user_id) sub_job_id = [int(info.id) for info in sub_job_list] try: SubJobDataForJobCenter.objects.filter(job__id__in=sub_job_id)\ .update(abandon_flag=data['abandon_flag'], updated_at=time.strftime('%Y-%m-%d %H:%M:%S'), updated_by_id=user_id) except Exception as e: logger.error("更新子任务数据状态失败: {}".format(e)) transaction.savepoint_rollback(sid) return ReturnJson.faile(JobCenterEnumeration.UPDATE_SUB_JOB_DATA_STATE_ERROR.value) except Exception as e: logger.error("更新子任务状态失败: {}".format(e)) transaction.savepoint_rollback(sid) return ReturnJson.faile(JobCenterEnumeration.UPDATE_SUB_JOB_STATE_ERROR.value) except Exception as e: logger.error("更新父任务数据状态失败: {}".format(e)) transaction.savepoint_rollback(sid) return ReturnJson.faile(JobCenterEnumeration.UPDATE_JOB_DATA_STATE_ERROR.value) logger.info("状态更新成功") transaction.savepoint_commit(sid) return ReturnJson.success("状态更新成功") else: transaction.savepoint_rollback(sid) logger.error("更新父任务状态失败,父任务不存在") return ReturnJson.faile(JobCenterEnumeration.UPDATE_JOB_STATE_ERROR.value) except Exception as e: logger.error("更新父任务状态失败: {}".format(e)) return ReturnJson.faile(JobCenterEnumeration.UPDATE_JOB_STATE_ERROR.value)