def del_task_info(self, task_id): task_info = TM.query.filter_by(task_id=task_id).first() if task_info is None: res = Result(msg='taskID无效,没有查找到对应的任务信息').success() else: db.session.delete(task_info) db.session.commit() res = Result(msg='删除测试任务成功').success() return make_response(res)
def add_project(self, user_id, pro_name, remark): if pro_name == '': res = Result(msg='项目名称不能为空').success() else: pro_id = self.__create_uuid() pro_info = PM(project_id=pro_id, project_name=pro_name, remark=remark, creator=user_id) db.session.add(pro_info) db.session.commit() res = Result(msg='项目新增成功').success() return make_response(res)
def user_register(self, username, password): if self.__query_user_info(username) is not None: res = Result(msg='用户名已存在,请更换用户名').success() else: # 新增用户信息 user_id = self.create_uuid() new_pwd = md5_encrypt(password) user_info = UserModel(user_id=user_id, username=username, password=new_pwd) db.session.add(user_info) db.session.commit() # 查询获取对象信息 data_obj = UserModel.query.filter_by(user_id=user_id).first() data = data_obj.query_one() res = Result(data).success() return make_response(res)
def edit_version(self, is_del, ver_id, version, remark): ver_info = VM.query.filter_by(ver_id=ver_id).first() if ver_info is None: res = Result(msg='Version ID 无效,没有找到对应的版本').fail() elif is_del == 1: ver_info.is_delete = 1 db.session.commit() res = Result(msg='版本号删除成功').success() elif version == '': res = Result(msg='版本号不能为空').fail() else: ver_info.version = version ver_info.remark = remark db.session.commit() res = Result(msg='版本号修改成功').success() return make_response(res)
def add_version(self, user_id, pro_id, version, remark): pro_info = ProjectModel.query.filter_by(project_id=pro_id).first() if pro_info is None: res = Result(msg='Project ID 无效,没有查找到对应的项目').fail() elif version == '': res = Result(msg='版本号不能为空').fail() else: ver_id = self.__create_uuid() version_info = VM(ver_id=ver_id, version=version, remark=remark, pro_id=pro_id, creator=user_id) db.session.add(version_info) db.session.commit() res = Result(msg='新增版本号成功').success() return make_response(res)
def add_suite(self, user_id, suite_name, remark, pro_id): if suite_name == '': res = Result(msg='项目名称不能为空').success() else: suite_id = self.__create_uuid() suite_info = SM( suite_id=suite_id, suite_name=suite_name, remark=remark, creator=user_id, pro_id=pro_id ) db.session.add(suite_info) db.session.commit() db.session.close() res = Result(msg='新增用例集成功').success() return make_response(res)
def get_suite_list(self, pro_id): suite_obj = db.session.query( SM.suite_id, SM.suite_name, SM.remark, UserModel.username, SM.pro_id, SM.update_time ).join(UserModel, UserModel.user_id == SM.creator) data_obj = suite_obj.filter(SM.is_delete == 0).filter(SM.pro_id == pro_id).order_by(SM.create_time.desc()) data = [self.__suite_info_serializer(item) for item in data_obj] res = Result(data).success() return make_response(res)
def edit_project(self, is_del, pro_id, pro_name, remark): pro_info = PM.query.filter_by(project_id=pro_id).first() if pro_info is None: res = Result(msg='Project ID 无效,没有查找到对应的项目').fail() # 判断是否删除 elif is_del == 1: pro_info.is_delete = 1 db.session.commit() res = Result(msg='项目删除成功').success() elif pro_name == '': res = Result(msg='项目名称不能为空').fail() else: pro_info.project_name = pro_name pro_info.remark = remark db.session.commit() res = Result(msg='项目信息修改成功').success() return make_response(res)
def error_response(error_code, errMsg=None): payload = { 'error_code': error_code, 'error': HTTP_STATUS_CODES.get(error_code, 'Unknown Error') } if errMsg: payload['errMsg'] = errMsg return Result(data=payload, msg='请求错误').fail()
def edit_suite(self, suite_id, suite_name, remark, is_delete): suite_info = SM.query.filter_by(suite_id=suite_id).first() if suite_info is None: res = Result(msg='suiteID无效,没有查到对应的用例集').success() elif is_delete == 1: suite_info.is_delete = 1 db.session.commit() db.session.close() res = Result(msg='测试用例集删除成功').success() elif suite_name == '': res = Result(msg='测试用例集名称不能为空') else: suite_info.suite_name = suite_name suite_info.remark = remark db.session.commit() db.session.close() res = Result(msg='修改测试用例集成功').success() return make_response(res)
def add_task_info(self, task_name, suite_id, ver_id, env_id, start_time, pro_id, user_id): if task_name == '': res = Result(msg='任务名称不能为空').success() else: task_id = self.__create_uuid() task_info = TM(task_id=task_id, task_name=task_name, suite_id=suite_id, ver_id=ver_id, env_id=env_id, pro_id=pro_id, creator=user_id, task_status=0, task_start_time=start_time, task_end_time=start_time) db.session.add(task_info) db.session.commit() db.session.close() res = Result(msg='新增测试任务成功').success() return make_response(res)
def get_project_list(self): # 获取数据对象 project_obj = db.session.query(PM.project_id, PM.project_name, PM.remark, PM.create_time, UserModel.username).join( UserModel, PM.creator == UserModel.user_id) # 数据对象进行筛选和排序 data_obj = project_obj.filter(PM.is_delete == 0).order_by( PM.create_time.desc()) data = [self.__pro_info_serializer(item) for item in data_obj] res = Result(data).success() return make_response(res)
def user_login(self, username, password): data_obj = self.__query_user_info(username) new_pwd = md5_encrypt(password) # 密码加密 access_token = None # 初始化access token if username == '' or password == '': res = Result(msg='用户名或密码不能为空').fail() elif data_obj is None or data_obj.query_one()['password'] != new_pwd: res = Result(msg='用户名或者密码错误').fail() else: data = data_obj.query_one() # expires_delta=False 关闭到期时间 access_token = create_access_token(identity=data['userID'], expires_delta=False) data['access_token'] = access_token pro_obj = ProjectModel.query.filter_by(is_delete=0).first() if pro_obj is None: data['projectID'] = 'NULL' else: data['projectID'] = pro_obj.query_one()['projectID'] data['projectName'] = pro_obj.query_one()['projectName'] res = Result(data, '登录成功').success() return make_response(res)
def get_version_list(self, pro_id): # 获取数据对象 version_obj = db.session.query(VM.ver_id, VM.version, VM.remark, VM.create_time, UserModel.username).join( UserModel, UserModel.user_id == VM.creator) # 数据对象进行筛选和排序 data_obj = version_obj.filter(VM.is_delete == 0).filter( VM.pro_id == pro_id).order_by(VM.create_time.desc()) data = [self.__ver_info_serializer(item) for item in data_obj] res = Result(data).success() return make_response(res)
def get_case_list(self, pro_id): # 获取数据对象 case_obj = db.session.query(TCM.case_id, TCM.case_name, TCM.level, TCM.method, TCM.req_url, TCM.header, TCM.body, TCM.case_assert, TCM.forward, TCM.mock, TCM.remark, TCM.create_time, UM.username).join( UM, UM.user_id == TCM.creator) # 数据对象进行筛选和排序 data_obj = case_obj.filter(TCM.pro_id == pro_id).order_by( TCM.create_time.desc()) data = [self.__case_info_serializer(item) for item in data_obj] res = Result(data).success() return make_response(res)
def suite_edit(): """ Desc: 编辑测试用例集(删除也用这个接口)(By Zoey) """ try: form_data = eval(request.get_data(as_text=True)) is_delete, suite_id = form_data['isDel'], form_data['suiteID'] if is_delete == 0: suite_name, remark = form_data['suiteName'], form_data['remark'] else: suite_name, remark = None, None response = TestSuite().edit_suite(suite_id, suite_name, remark, is_delete) return response except Exception as err: return Result(msg='参数错误').fail()
def get_api_test_report_list(self, pro_id): # 获取数据对象 report_obj = db.session.query( ARM.report_id, ARM.report_name, ARM.success, ARM.fail, ARM.create_time, ARM.pro_id, ARM.task_id, VersionModel.version ).join( TaskModel, TaskModel.task_id == ARM.task_id ).join( VersionModel, VersionModel.ver_id == TaskModel.ver_id ) # 数据对象进行筛选和排序 data_obj = report_obj.filter(ARM.pro_id == pro_id).order_by(ARM.create_time.desc()) data = [self.__api_test_report_serializer(item) for item in data_obj] res = Result(data).success() return make_response(res)
def get_task_list(self, pro_id): # 获取数据对象 task_obj = db.session.query(TM.task_id, TM.task_name, TM.create_time, TM.task_start_time, TM.task_end_time, TM.task_status, UserModel.username, VM.version, SM.suite_name).join( UserModel, UserModel.user_id == TM.creator).join( VM, VM.ver_id == TM.ver_id).join( SM, SM.suite_id == TM.suite_id) # 数据对象进行筛选和排序 data_obj = task_obj.filter(TM.pro_id == pro_id).order_by( TM.create_time.desc()) data = [self.__task_info_serializer(item) for item in data_obj] res = Result(data).success() return make_response(res)
def user_logout(self): res = Result(msg='退出成功').success() return make_response(res)