def getOrderListBySupplierIdAndDate(supplierId, dateStr): dbtool = DBTool(host='172.16.16.9', port=3306, username='******', password='******', db='trade') res = dbtool.execute_sql( "select order_id from t_order_merch where order_id in (select transaction_id from t_voucher_base where supplier_id='%s' and start_time='%s 00:00:00') and merch_state=0" % (supplierId, dateStr)) return res
def getOrderList(contacteeTag): dbtool = DBTool(host='172.16.16.9', port=3306, username='******', password='******', db='trade') sql = "select DISTINCT(order_id) from t_order_merch where order_id in (select order_id from t_order where contactee='%s') and merch_state=0" % contacteeTag logging.info(sql) res = dbtool.execute_sql(sql) return res
def checkTicket(orderIdList, macIds, percentRate=0.5, percentCheckRate=1.0): dbtool = DBTool(host='172.16.16.9', port=3306, username='******', password='******', db='trade') # time.sleep(10) maxMacLen = len(macIds) - 1 looplen = int(float(len(orderIdList)) * percentRate) print looplen logging.info("全部订单数量%d,退款比例%f,实际应退款单数:%d。" % (len(orderIdList), percentRate, looplen)) totalCount = 0 failCount = 0 passCount = 0 for i in range(0, looplen): logging.info('-=====OrderID:::--' + str(orderIdList[i][0]) + '=========尝试检票。。。=========') sql = """SELECT voucher_content from t_voucher_base where transaction_id = '%s' """ % orderIdList[ i][0] data = dbtool.execute_sql(sql) logging.info(sql) lenCheck = int(float(len(data)) * percentCheckRate) for j in range(0, lenCheck): try: indexMac = random.randint(0, maxMacLen) macId = macIds[indexMac] url = "http://voucher.stage.mftour.net/ticketService/QueryOrders?macId=%s&voucherContent=%s" % ( macId, data[j][0]) logging.info(url) getOrderDetailByReseller = requests.get(url=url, timeout=10) logging.info(getOrderDetailByReseller.text) queryOeders = json.loads(getOrderDetailByReseller.text) ticketURL = '' totalCount += 1 ticketURL = """ http://voucher.stage.mftour.net/ticketService/checkVoucher?macId=%s&voucherIds=%s""" % ( macId, queryOeders['voucherList'][0]['voucherId']) logging.info(ticketURL) checkTicketDevice = requests.get(url=ticketURL, timeout=10) retText = checkTicketDevice.text retdict = json.loads(retText) logging.info(retText) if retdict['code'] == '0001': logging.info("检票成功") passCount += 1 else: logging.info("检票失败") failCount += 1 except Exception, e: logging.info(e) logging.info("检票失败") failCount += 1 logging.info("共检票%d,成功%d,失败%d。" % (totalCount, passCount, failCount))
def checkTicket(cardIds): dbtool = DBTool(host='172.16.16.9', port=3306, username='******', password='******', db='trade') # time.sleep(10) for i in range(0, len(cardIds)): print '------------' + str(cardIds[i]) + '=====================' data = dbtool.execute_sql( """SELECT voucher_content from t_voucher_base where transaction_id = '%s' """ % cardIds[i]) for j in range(0, len(data)): url = "http://fhgc.stage.piaozhijia.com/ticketService/QueryOrders?macId=863789020447557&cardId=%s" % ( data[j]) print url getOrderDetailByReseller = requests.get(url=url, timeout=10) print getOrderDetailByReseller.text queryOeders = json.loads(getOrderDetailByReseller.text) ticketURL = '' try: ticketURL = """ http://fhgc.stage.piaozhijia.com/ticketService/checkTicketDevice?ticketData={"request_macid":%%20"863789020447557", "child_product_id":"%s", "ticket_id":"%s", "is_group":"2"}""" % ( queryOeders['responseBody'][0]['child_product_list'][0] ['child_product_id'], queryOeders['responseBody'][0]['ticket_id']) print ticketURL checkTicketDevice = requests.get(url=ticketURL, timeout=10) print checkTicketDevice.text except Exception, e: print e print ticketURL print getOrderDetailByReseller.text
logging.info(UsualTools().get_current_time() + (u"=>runPlatformTask.py: run_on_linux: logPath: %s " % log_path)) logging.info(UsualTools().get_current_time() + (u"=>runPlatformTask.py: run_on_linux: logLevel: %s " % logLevel)) # 循环遍历tb_task_run表,顺序执行任务,执行后填写 status 状态 1未执行 2进行中 3已执行 4执行异常 while True: try: db = '' db = DBTool(sc.dbhost, sc.dbport, sc.dbusername, sc.dbpassword, sc.dbname) key_list = "id,taskId,`name`,`describe`,protocol,systems,caseNum,caseList,addBy,environment,execBy,execTime,execType,execLevel,`status`,isSendEmail,isCodeRate" results = db.execute_sql( "select %s from tb_task_run where state=1 and (status=1 or status=2 or status=10) AND execType=1 order by addTime asc limit 1" % key_list) # (status=1 or status=2 or status=10) 这个判定是保证当前执行的不是取消状态,如果当前是取消状态再去取消,否则继续执行。 for res in results: #变量赋值 id = res[0] taskId = res[1] status = res[14] # 1待执行 2执行中 3执行完成 4执行异常 10待取消 11已取消 if status == 10: stopPlatformTask = "killall -9 runPlatformTask" startPlatformTask = "%s/runPlatformTask --webenv=%s--log=%s >%s/runPlatformTaskPrint.log 2>&1 &" % ( bin_path, testenv, logLevel, log_path) os.system(stopPlatformTask) tmpText = u"%s%s" % (PromptMsg.taskCanceled, taskId) print tmpText logging.info(UsualTools().get_current_time() +
################################################################################################## #初始化数据库配置conf sc = ServiceConf(testenv) db = DBTool(sc.dbhost, sc.dbport, sc.dbusername, sc.dbpassword, sc.dbname) conf_path = "" if UsualTools.isLinuxSystem(): #正式环境 conf_path = "/home" elif UsualTools.isWindowsSystem(): #王吉亮测试环境 conf_path = "D:/devcodes/DubboInterfaceTestFramework/DubboInterfaceTestFramework" elif UsualTools.isMacOS(): #liyaochao测试环境 conf_path = "/home" # =================获取所有配置====================== confSql = "select confName,confText from tb_conf where state=1 " confRes = db.execute_sql(confSql) confDict = {} for res in confRes: tmpConfKey = res[0] tmpConfText = res[1] tmpConfPath = "%s/caseDebugenv%s.conf" % (conf_path, tmpConfKey) confRetCode, confConfig = getConfigObj(tmpConfKey, tmpConfText, tmpConfPath) confDict[tmpConfKey] = confConfig confDict[tmpConfKey + "code"] = confRetCode if confRetCode['errorCode'] != '10000': print u"没有得到配置文件%s,错误信息:%s" % (tmpConfKey, confRetCode['errorMsg']) db.release() sys.exit(0) db.release()
def rerundOrder(orderIdList, percentOrder=0.1): s = requests.session() host = "http://saas.stage.mftour.net" url = "/saas/login/doLogin" headers = { "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0" } final_param = ['username', ''], ['password', ''] final_param[0][1] = "fhgc002" final_param[1][1] = "123456" retres = s.post(url="%s%s" % (host, url), data=final_param, headers=headers, timeout=10) token_url = "/saas/login/menus" retres = s.post(url="%s%s" % (host, token_url), timeout=10) looplen = int(float(len(orderIdList)) * percentOrder) logging.info("全部订单数量%d,退款比例%f,实际应退款单数:%d。" % (len(orderIdList), percentOrder, looplen)) dbtool = DBTool(host='172.16.16.9', port=3306, username='******', password='******', db='trade') totalCount = 0 failCount = 0 passCount = 0 for i in range(0, looplen): totalCount += 1 orderId = orderIdList[i][0] sqlrefund = "select merch_id from t_order_merch where order_id='%s'" % orderId refundIdList = dbtool.execute_sql(sqlrefund) print refundIdList refundId = refundIdList[0][0] host = "http://saas.stage.mftour.net" url = "/saas/orders/refund" headers = { "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0" } final_param = ['orderId', ''], ['refundIdsAndNums', ''], ['content', ''] final_param[0][1] = orderId final_param[1][1] = "%s,1" % refundId final_param[2][1] = "testrefundbywjl" retres = s.post(url="%s%s" % (host, url), data=final_param, headers=headers, timeout=10) retstr = retres.text try: retdict = json.loads(retstr.strip()) if retdict['code'] == "0000": print "退款成功" passCount += 1 else: print "退款失败" print retstr failCount += 1 except Exception, e: print e print "退款失败" print retstr failCount += 1
################################################################################################## #初始化数据库配置conf sc = ServiceConf(testenv) db = DBTool(sc.dbhost, sc.dbport, sc.dbusername, sc.dbpassword, sc.dbname) conf_path = "" if UsualTools.isLinuxSystem():#正式环境 conf_path = "/home" elif UsualTools.isWindowsSystem(): #王吉亮测试环境 conf_path = "D:/devcodes/DubboInterfaceTestFramework/DubboInterfaceTestFramework" elif UsualTools.isMacOS(): #liyaochao测试环境 conf_path = "/home" #=================获取所有配置====================== confSql = "select confName,confText from tb_conf where state=1 " confRes = db.execute_sql(confSql) confDict = {} for res in confRes: tmpConfKey = res[0]; tmpConfText = res[1] tmpConfPath = "%s/caseDebugenv%s.conf" % (conf_path,tmpConfKey) confRetCode,confConfig = getConfigObj(tmpConfKey,tmpConfText,tmpConfPath) confDict[tmpConfKey] = confConfig confDict[tmpConfKey+"code"] = confRetCode if confRetCode['errorCode'] != '10000': print u"没有得到配置文件%s,错误信息:%s" % (tmpConfKey,confRetCode['errorMsg']) db.release() sys.exit(0); db.release() ##################################################################################################
if UsualTools.isLinuxSystem(): logging.basicConfig( level='INFO', format= '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='/home/InterfaceFrameworkOnline/logs/runtask.log', filemode='w') # 循环遍历t_task表,顺序执行任务,执行时把state变成2,执行后变成3. conf = Config("../ConfFile/platform.conf").conf_dict while True: db = DBTool(conf['db']['host'], int(conf['db']['port']), conf['db']['username'], conf['db']['password'], conf['db']['dbname']) results = db.execute_sql( "select * from tb_taskpython where state=1 or state=2 order by create_time asc" ) for res in results: logging.info(u"执行命令:%s" % res[1]) sqlupdate = "update tb_taskpython set state=2 where id=%d" % res[ 0] db.execute_sql(sqlupdate) message = subprocess.Popen(res[1], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, err = message.communicate() outresult = "" for line in out.splitlines(): outresult = outresult + line + "\n" logging.debug(u"%s" % outresult)