def post(self): result = {"message": None} if (self.ags['api_name'] is not None): if (self.ags['operate'] == 'delete'): result = ApiMangerOperate().del_item(self.ags['api_name']) return result elif (self.ags['operate'] == 'add'): result = ApiMangerOperate().add_apis(self.ags) return result elif (self.ags['operate'] == 'update'): result = ApiMangerOperate().update_apis(self.ags) return result return result
def get_api_case(self): data = {} models = ApiMangerOperate().get_model_list() for model in models: data[model] = [0, 0] result = ApiMangerOperate().get_list() for item in result: if item[2] in data: if item[9] == 'Yes': data[item[2]][0] += 1 elif item[9] == 'No': data[item[2]][1] += 1 return {'message': True, 'data': data}
def post(self): f = request.files['files'] upload_path = os.path.join(Path().get_current_path(), 'static/uploads', secure_filename(f.filename)) f.save(upload_path) result = ExcelOperate().get_excellist(upload_path) os.remove(upload_path) result = ApiMangerOperate().batch_operate(result, user=self.ags.user) return result
def get_case_pass(self): data = {} models = ApiMangerOperate().get_model_list() for model in models: data[model] = [0, 0] result = db.session.query( api_manager.model, test_case.last_result, func.count(test_case.id)).filter( api_manager.id == test_case.api_id).group_by( test_case.api_id, test_case.last_result).all() for item in result: if item[0] in data: if item[1] == 'PASS': data[item[0]][0] += item[2] elif item[1] == 'FAIL': data[item[0]][1] += item[2] return {'message': True, 'data': data}
def batch_operate(self, *args, user): try: for item in args: # for i in range(2,item['Sheet']) for n in item: for i in range(2, item[n].__len__()): result = test_case.query.filter_by( id=item[n][i][1]).first() apis = ApiMangerOperate().get_list({"type": "id"}) api_id = ListOperate().get_item(apis, item[n][i][4], 0) if result: result.case_name = item[n][i][2] result.parameter = JsonOperate().parameter_to_json( item[n][i][5]) result.result = item[n][i][6] result.validation_type = item[n][i][7] result.mark = item[n][i][8] result.api_id = api_id result.updater = user result.update_time = datetime.datetime.now() db.session.flush() else: db.session.add( test_case( case_name=item[n][i][2], parameter=JsonOperate().parameter_to_json( item[n][i][5]), result=item[n][i][6], validation_type=item[n][i][7], mark=item[n][i][8], api_id=api_id, creater=user)) db.session.commit() db.session.close() return {"message": True} except Exception as e: db.session.close() return {"message": str(e)}
def add_case(self, *args): global admin try: for item in args: if item.case_name is not None: api_id = ApiMangerOperate().get_id(item.servi_name) admin = test_case( case_name=item.case_name, parameter=JsonOperate().parameter_to_json( item.parameter), result=item.result, validation_type=item.validation_type, mark=item.mark, api_id=api_id, creater=item.user) db.session.add(admin) db.session.commit() db.session.close() return {"message": True} except Exception as e: db.session.close() return {"message": str(e)}
def update_case(self, *args): try: for item in args: api_id = ApiMangerOperate().get_id(item.servi_name) result = test_case.query.filter_by(id=item['case_id']).first() if result: result.case_name = item.case_name result.parameter = JsonOperate().parameter_to_json( item.parameter) result.result = item.result result.validation_type = item.validation_type result.mark = item.mark result.api_id = str(api_id) result.updater = item.user result.update_time = datetime.datetime.now() db.session.flush() db.session.commit() db.session.close() return {"message": True} except Exception as e: db.session.close() return {"message": str(e)}
def get(self): result = ApiMangerOperate().get_model_list() return {"data": result}
def get(self): data = ApiMangerOperate().get_list() result = {"data": data} return result