def edit_test_suite(): log.log().logger.info(request) if request.method == 'GET': log.log().logger.info('post') info = request.values log.log().logger.info('info : %s' % info) id = viewutil.getInfoAttribute(info, 'id') log.log().logger.info('id: %s' % id) return render_template("uitest/edit_test_suite.html", id=id) if request.method == 'POST': info = request.form log.log().logger.info('info : %s' % info) id = viewutil.getInfoAttribute(info, 'id') name = viewutil.getInfoAttribute(info, 'name') run_type = viewutil.getInfoAttribute(info, 'run_type') description = viewutil.getInfoAttribute(info, 'description') if run_type == '' or name == '': message = '必填字段不得为空!' code = 500 else: test_suite_manage.test_suite_manage().update_test_suite( id, ['name', 'run_type', 'description'], [name, run_type, description]) message = 'success!' code = 200 result = jsonify({'code': code, 'msg': message}) return render_template("uitest/test_suite.html")
def save_new_test_suite(): log.log().logger.info(request) if request.method == 'GET': log.log().logger.info('post') return render_template("uitest/new_test_suite.html") if request.method == 'POST': info = request.values log.log().logger.info('info :%s' %info) name = viewutil.getInfoAttribute(info,'name') run_type = viewutil.getInfoAttribute(info,'run_type') description = viewutil.getInfoAttribute(info,'description') if run_type == '' or name == '' : message = '必填字段不得为空!' code = 500 else: import random, time batchId = str(random.randint(10000, 99999)) + str(time.time()) test_suite_manage.test_suite_manage().new_test_suite(name, run_type, description, batchId) newId = test_suite_manage.test_suite_manage().show_test_suites(["batchId"], [batchId], ['id'], 1) log.log().logger.info('newid %s' %newId) if len(newId): ext=newId[0]['id'] log.log().logger.info('ext %s' %ext) message = 'success!' code = 200 # return redirect('attach_test_batch?test_suite_id=%s' %ext) else: ext='' message = 'add failed!' code = 500 result = jsonify({'code': code, 'msg': message,'ext':ext}) log.log().logger.info(result) # log.log().logger.info('code is : %s'%result['code']) return result
def copy_test_suite(): log.log().logger.info(request) log.log().logger.info(request.method) # log.log().logger.info(request.value) if request.method == 'GET': log.log().logger.info('post') result = jsonify({'code': 500, 'msg': 'should be get!'}) return result if request.method == 'POST': info = request.form log.log().logger.info('info : %s' %info) id = viewutil.getInfoAttribute(info, 'id') log.log().logger.info("id: %s" %id) if id=='': result = jsonify({'code': 500, 'msg': 'test suite is not found!'}) else: import random, time batchId = str(random.randint(10000, 99999)) + str(time.time()) test_suite_manage.test_suite_manage().copy_test_suite(id, batchId) newId = test_suite_manage.test_suite_manage().show_test_suites(["batchId"], [batchId], ['id'], 1) log.log().logger.info('newid %s' %newId) if len(newId): ext = newId[0]['id'] log.log().logger.info('ext is: %s, id is: %s' %(ext, id)) if ext !='0': test_batch_manage.test_batch_manage().copy_test_batch(ext, id) message = 'success!' code = 200 result = jsonify({'code': 200, 'msg': 'copy success!'}) else: result = jsonify({'code': 500, 'msg': 'test suite is not found!'}) return result
def batch_new_testcase(self, test_suite_id, test_case_id_list, browser_type_list=['']): support_browser = ['Chrome', 'Firefox', ''] run_type = test_suite_manage.test_suite_manage().search_test_suite( test_suite_id, 'run_type') if run_type == 'Chrome': test_case_id_list = self.remove_android(test_case_id_list) log.log().logger.info('%s, %s' % (test_case_id_list, len(test_case_id_list))) if len(test_case_id_list) == 0: result = 0 else: for test_case_id in test_case_id_list: steps = test_case_manage.test_case_manage().search_test_case( [test_case_id], ['name', 'steps']) log.log().logger.info('%s, %s, %s' % (steps, steps[0][0], steps[0][1])) if len(steps): for browser_type in browser_type_list: if browser_type not in support_browser: log.log().logger.info( '%s browser is not support!' % browser_type) else: self.new_test_batch(test_suite_id, test_case_id, steps[0][0], steps[0][1], browser_type=browser_type) else: log.log().logger.info('test case not exist!') result = 1 return result
def batch_new_testcase_IP(self, test_suite_id, test_case_id_list, ip): run_type = test_suite_manage.test_suite_manage().search_test_suite( test_suite_id, 'run_type') if run_type == 'Chrome': test_case_id_list = self.remove_android(test_case_id_list) log.log().logger.info('%s, %s' % (test_case_id_list, len(test_case_id_list))) if len(test_case_id_list) == 0: result = 0 else: for test_case_id in test_case_id_list: steps = test_case_manage.test_case_manage().search_test_case( [test_case_id], ['name', 'steps']) log.log().logger.info('%s, %s,%s' % (steps, steps[0][0], steps[0][1])) if len(steps): self.new_test_batch_IP(test_suite_id, test_case_id, steps[0][0], steps[0][1], ip, status='0') else: log.log().logger.info('test case not exist!') result = 1 return result
def search_test_suite(): if request.method == 'POST': log.log().logger.info('post') if request.method == 'GET': info = request.values log.log().logger.info('info : %s' % info) limit = info.get('limit', 10) # 每页显示的条数 offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点 log.log().logger.info('get %s' % limit) log.log().logger.info('get offset %s' % offset) id = viewutil.getInfoAttribute(info, 'id') type = viewutil.getInfoAttribute(info, 'type') log.log().logger.info('type %s' % type) run_type = viewutil.getInfoAttribute(info, 'run_type') status = viewutil.getInfoAttribute(info, 'status') name = viewutil.getInfoAttribute(info, 'name') if id == '': if status == 'All': status = '' log.log().logger.info('info content: %s, %s, %s, %s' % (id, status, run_type, name)) conditionList = ['status', 'run_type', 'name'] valueList = [status, run_type, name] else: if type == 'testview': statusList = test_batch_manage.test_batch_manage( ).show_test_batch_status(id) else: statusList = [] log.log().logger.info('info content: %s, %s, %s, %s' % (id, status, run_type, name)) conditionList = ['id'] valueList = [id] fieldlist = [] rows = 1000 caseList = test_suite_manage.test_suite_manage().show_test_suites( conditionList, valueList, fieldlist, rows) log.log().logger.info(caseList) data = caseList if id != '': data1 = jsonify({ 'total': len(data), 'rows': data[0], 'status': statusList }) else: data1 = jsonify({ 'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)] }) log.log().logger.info('data1: %s' % data1) return data1, {'Content-Type': 'application/json'}
def delete_test_suite(): log.log().logger.info(request) if request.method == 'GET': log.log().logger.info('post') info = request.values log.log().logger.info('info : %s' %info) id = viewutil.getInfoAttribute(info, 'id') log.log().logger.info('id: %s' %id) return render_template("uitest/test_suite.html") if request.method == 'POST': info = request.form log.log().logger.info('info : %s' %info) id = viewutil.getInfoAttribute(info, 'id') act = viewutil.getInfoAttribute(info, 'act') if act == 'del': test_suite_manage.test_suite_manage().update_test_suite(id, ['isDeleted'], [1]) code = 200 message = 'delete success!' else: code=500 message = 'act is not del!' result = jsonify({'code': code, 'msg': message}) return result,{'Content-Type': 'application/json'}
def send_test_result(self, test_suit_id, to_email=[]): if len(to_email) == 0: to_email = [self.default_to_email] from app.db import test_batch_manage, test_suite_manage test_suit_id = str(test_suit_id) result = test_batch_manage.test_batch_manage().show_test_batch_status( test_suit_id) # print(result) test_title = 'test result for batch : ' + test_suit_id + '-' + test_suite_manage.test_suite_manage( ).search_test_suite(test_suit_id, 'name')[0][0] test_result = 'id: %s, 总用例数:%s, 成功用例数:%s, 失败用例数: %s, 通过率: %s , 报告地址: %s' % ( test_suit_id, result['total'], result['success'], result['fail'], result['successRate'], config.flask_host + '/test_batch_detail?test_suite_id=' + test_suit_id) self.sendEmail(to_email, test_title, test_result)
def runtest(): log.log().logger.info(request) if request.method == 'POST': log.log().logger.info('post') result = jsonify({'code': 500, 'msg': 'should be get!'}) return result else: log.log().logger.info(request.values) # log.log().logger.info(request.form) info = request.values id = viewutil.getInfoAttribute(info, 'id') test_case_id = viewutil.getInfoAttribute(info, 'test_case_id') ipVal = viewutil.getInfoAttribute(info, 'ipVal') type = viewutil.getInfoAttribute(info, 'type') if type == 'test_suite': test_suite_manage.test_suite_manage().new_test_run_list(id) result = jsonify({'code': 200, 'msg': 'success!'}) elif type == 'test_suite_rerun_all': ipList = ipVal.split(',') for i in range(len(ipList)): test_suite_manage.test_suite_manage().new_test_run_list(id) if ipList[i] == '': test_batch_manage.test_batch_manage().rerun_test_batch( id, 'all') else: test_batch_manage.test_batch_manage().rerun_test_batch_Ip( id, 'all', ipList[i]) result = jsonify({'code': 200, 'msg': 'success!'}) elif type == 'test_suite_rerun_part': test_suite_manage.test_suite_manage().new_test_run_list(id) test_batch_manage.test_batch_manage().rerun_test_batch(id, 'part') result = jsonify({'code': 200, 'msg': 'success!'}) elif type == 'test_batch': # test_suite_manage.test_suite_manage().new_test_run_list(id) test_batch_manage.test_batch_manage().rerun_test_batch_record( id, test_case_id) result = jsonify({'code': 200, 'msg': 'success!'}) elif type == 'test_case': ipList = ipVal.split(',') for i in range(len(ipList)): if ipList[i] == '': test_batch_manage.test_batch_manage().batch_new_testcase( '0', [id]) else: test_batch_manage.test_batch_manage( ).batch_new_testcase_IP('0', [id], str(ipList[i])) result = jsonify({'code': 200, 'msg': 'success!'}) else: result = jsonify({'code': 500, 'msg': 'type is not defined!'}) return result