def excecutePayWeChat(self, payNo, token, userId): meisooVar = MeisooVar() url = meisooVar.orderGW + "common/executeMoneyPay" rest = meisooVar.GwTokenStrategy(url, token, userId) form = {"payChannel": "2", "payNo": payNo} rest.setForm(form) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(self.host + rest.getUrl(), rest.getForm(), rest.getHeaders())
def refundAndOut(self, parkingNo, token, userId, phone): meisooVar = MeisooVar() url = meisooVar.orderGW + "terminal/pay/refundAndOut" rest = meisooVar.GwTokenStrategy(url, token, userId) form = {"parkItemName": parkingNo, "phone": phone} rest.setForm(form) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(self.host + rest.getUrl(), rest.getForm(), rest.getHeaders()) return rs
def posCarIn(self, parkingNo, token, userId): meisooVar = MeisooVar() url = meisooVar.orderGW + "terminal/carIn" rest = meisooVar.GwTokenStrategy(url, token, userId) form = {"parkingNo": parkingNo} rest.setForm(form) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(self.host + rest.getUrl(), rest.getForm(), rest.getHeaders()) orderNo = rfeLib.getValueFromJson(rs, "$.data.orderNo") return orderNo, parkingNo
def posBindPlateNo(self, parkingNo, token, userId, orderNo): meisooVar = MeisooVar() url = meisooVar.orderGW + "terminal/bindPlateNo" rest = meisooVar.GwTokenStrategy(url, token, userId) # 这里要调整,车牌号应该是随机的 plateNo = "渝ABC520" form = {"orderNo": orderNo, "plateNo": plateNo} rest.setForm(form) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(self.host + rest.getUrl(), rest.getForm(), rest.getHeaders()) result = rfeLib.getValueFromJson(rs, "$.flag") if result: return orderNo, parkingNo, plateNo
def betchRegist(self): rest = RestVariable() var_rest = rest.batchRegist() rfeLib = RfeLibrary() if isinstance(var_rest, Rest): if var_rest.getMethod() == "POST": reqId = var_rest.getExcepts() excepts = '{"apiId":null,"timestamp":null,"sign":null,"reqId":"' + reqId + '","status":0,"msg":"Success","result":[]}' print excepts url = "http://172.16.31.36:9090" + var_rest.getUrl() rs = rfeLib.reqByJson(method=var_rest.getMethod(), url=url, json=var_rest.getJson()) print rs.content
def testFace(self): var = RestVariable() var_rest = var.faceRecognizeVar() rfeLib = RfeLibrary() except_rs = '{"faceInfo":[{"fId":"B0001234","uId":"test3000004","userSex":1,"recognizeTime":"20180425140826","rate":0.452894}],"faceNum":1,"status":0,"reqId":"20180425140826728","msg":"Success"}' if isinstance(var_rest, Rest): if var_rest.getMethod() == "POST": url = "http://172.16.31.36:9090" + var_rest.getUrl() rs = rfeLib.reqByJson(var_rest.getMethod(), url, json=var_rest.getJson()) try: rfeLib.assertJson(except_rs, rs.content, 0) except_rs2 = '{"faceNum":' + str(len(var_rest.getExcepts( ))) + ',"status":0,"msg":"Success"}' rfeLib.assertJson(except_rs2, rs.content) excepts_userImg = var_rest.getExcepts() print excepts_userImg print rs.content actual_userInfo = rfeLib.getValueFromJson( rs.content, "$.faceInfo") print actual_userInfo self.assertFace(excepts_userImg, actual_userInfo) except Exception, e: raise AssertionError(repr(e))
def getParkingNo(self, token, userId): meisooVar = MeisooVar() url = meisooVar.terminalGW + "terminal/app/list" rest = meisooVar.GwTokenStrategy(url, token, userId) form = {"parkId": "14"} rest.setForm(form) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(self.host + rest.getUrl(), rest.getForm(), rest.getHeaders()) parkingNoList = rfeLib.getValueFromJson(rs, "$.data.list") msUtil = meisooUtil() freeParkingNoList = msUtil.getListElementWithNoKey( 'parkingState', parkingNoList) parkingNo = meisooVar.getListAnyElement(freeParkingNoList) return parkingNo
def createPreOrder(self, orderNo, parkingNo, plateNo, token, userId): meisooVar = MeisooVar() url = meisooVar.orderGW + "parkOut/createOrder" rest = meisooVar.GwTokenStrategy(url, token, userId) form = { "orderNo": orderNo, "plateNo": plateNo, "parkingNo": parkingNo, "duration": int(1) } rest.setForm(form) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(self.host + rest.getUrl(), rest.getForm(), rest.getHeaders()) payNo = rfeLib.getValueFromJson(rs, "$.data.payNo") return payNo, parkingNo
def batchRegister(self): rest = RestVariable() var_rest = rest.batchRegist() rfeLib = RfeLibrary() if isinstance(var_rest, Rest): if var_rest.getMethod() == "POST": reqId = var_rest.getExcepts() excepts = '{"apiId":null,"timestamp":null,"sign":null,"reqId":"' + reqId + '","status":0,"msg":"Success","result":[]}' with self.locust.client.post(url=var_rest.getUrl(), json=var_rest.getJson(), catch_response=True) as response: try: rfeLib.assertJson(excepts, response.content) except Exception, e: response.failure(repr(e) + ", " + response.content) else: response.success()
def excecutePayBalance(self): self.prePay() phone = "13983435205" payNo = self.payNo token = self.locust.user_info["token"] userId = self.locust.user_info["id"] # 余额支付,这里的phone是指绑定停车车牌号的用户的手机号 meisooVar = MeisooVar() url = meisooVar.orderGW + "common/executeMoneyPay" rest = meisooVar.GwTokenStrategy(url, token, userId) form = {"phone": phone, "payNo": payNo} rest.setForm(form) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(self.host + rest.getUrl(), rest.getForm(), rest.getHeaders()) try: # 判断缴费是否成功,成功则会返回channelOrder字段 channelOrder = rfeLib.getValueFromJson(rs, "$.data.channelOrder") except Exception, e: raise "Fail -> phone:" + phone + " payNo:" + payNo
def faceRecognize(self): var = RestVariable() var_rest = var.faceRecognizeVar() rfeLib = RfeLibrary() except_rs = '{"faceInfo":[{"fId":"B0001234","uId":"test3000004","userSex":1,"recognizeTime":"20180425140826","rate":0.452894}],"faceNum":1,"status":0,"reqId":"20180425140826728","msg":"Success"}' if isinstance(var_rest, Rest): if var_rest.getMethod() == "POST": with self.locust.client.post(url=var_rest.getUrl(), json=var_rest.getJson(), catch_response=True) as response: try: rfeLib.assertJson(except_rs, response.content, 0) except_rs2 = '{"faceNum":' + str(len(var_rest.getExcepts())) + ',"status":0,"msg":"Success"}' rfeLib.assertJson(except_rs2, response.content) excepts_userImg = var_rest.getExcepts() actual_userInfo = rfeLib.getValueFromJson(response.content, "$.faceInfo") self.assertRecognize(excepts_userImg, actual_userInfo) except Exception, e: response.failure(repr(e)) else: response.success()
class Lancher(HttpLocust): user_id = "82" user_name = "liuyanqing" password = "******" host_str = "http://betagateway.meitianiot.com:80" meisooVar = MeisooVar() login_var = meisooVar.LoginVar(user_name, password) rfeLib = RfeLibrary() rs = rfeLib.reqByDataform(host_str + login_var.getUrl(), login_var.getForm(), login_var.getHeaders()) token = rfeLib.getValueFromJson(rs, "$.data.auth") user_info = { "id": user_id, "phone": "liuyanqing", "code": "888888", "token": token } host = "http://10.10.253.8:8080" task_set = MeisooTasks min_wait = 1000 max_wait = 5000
def singleRegister(self): rest = RestVariable() var_rest = rest.batchRegist() rfeLib = RfeLibrary() if isinstance(var_rest, Rest): if var_rest.getMethod() == "POST": reqId = var_rest.getExcepts() excepts = '{"reqId": "20180511092955098", "status": 0, "msg": "Success"}' with self.locust.client.post(url=var_rest.getUrl(), json=var_rest.getJson(), catch_response=True) as response: try: rfeLib.assertJson(excepts, response.content, 0) excepts2 = '{"status": 0, "msg": "Success"}' rfeLib.assertJson(excepts2, response.content) except Exception, e: response.failure(repr(e)) else: response.success()
class RestVariable: apiId = "BOxALFZsYGw0GNzebQck1xKs" apiKey = "1285384ddfb057814bad78127bc789be" def __init__(self): self.rfeLibrary = RfeLibrary() self.rfeRfeTool = RfeLibTool() def faceRecognizeVar(self): url = "/api/v1/face/facerecognize" rest = Rest("post", url) timestamp = str(self.rfeLibrary.getTimestamp()) pre_sign = "api/v1/facerecognize" + self.apiKey + str(timestamp) sign = self.rfeLibrary.toMD5(pre_sign) userNum = self.rfeRfeTool.getRandInt(1, 5) faceInfos = [] excepts_msg = [] for i in range(userNum): userImg = self.rfeRfeTool.listRandFileName("feature/") with open("feature/" + userImg[0] + "/0.txt", "r") as fin: feature = fin.read() fId = userImg[ 0] + "_" + timestamp + "_" + self.rfeRfeTool.getRandStr() excepts_msg.append(fId) user = {"fId": fId, "feature": feature[:-1]} faceInfos.append(user) rest.setExcepts(excepts_msg) body = { "apiId": self.apiId, "timestamp": timestamp, "cameraId": "Auto_camer_001", "sign": sign, "cameraIp": "10.23.25.44", "faceInfos": faceInfos } rest.setJson(body) return rest def singleRegist(self): url = "/api/v1/face/singleregist" rest = Rest("post", url) timestamp = str(self.rfeLibrary.getTimestamp()) pre_sign = "api/v1/face/singleregist" + self.apiKey + str(timestamp) sign = self.rfeLibrary.toMD5(pre_sign) path = "imgs/gallery_f/" userImgs = self.rfeRfeTool.listRandFileName(path) userImg = self.rfeRfeTool.toBase64(path + userImgs[0]) userRegion = "Auto_Region_" + timestamp userSex = 1 uId = userImgs[0] + timestamp + self.rfeRfeTool.getRandStr() obj_json = { "apiId": self.apiId, "timestamp": timestamp, "userImg": userImg, "sign": sign, "uId": uId, "userSex": userSex, "userRegion": userRegion } rest.setJson(obj_json) rest.setExcepts(userImgs[0]) return rest def batchRegist(self): url = "/api/v1/face/batchregist" rest = Rest("post", url) timestamp = str(self.rfeLibrary.getTimestamp()) pre_sign = "api/v1/face/batchregist" + self.apiKey + str(timestamp) sign = self.rfeLibrary.toMD5(pre_sign) reqId = self.rfeRfeTool.listUUID()[0] registInfo = [] userNum = self.rfeRfeTool.getRandInt(1, 100) for i in range(userNum): path = "imgs/gallery_f/" userImgs = self.rfeRfeTool.listRandFileName(path) userImg = self.rfeRfeTool.toBase64(path + userImgs[0]) userRegion = "Auto_Region_" + timestamp userSex = 1 uId = userImgs[0] + timestamp + self.rfeRfeTool.getRandStr() user = { "uId": uId, "userSex": userSex, "userRegion": userRegion, "userImg": userImg } registInfo.append(user) obj_json = { "apiId": self.apiId, "timestamp": timestamp, "sign": sign, "reqId": reqId, "registInfo": registInfo } rest.setJson(obj_json) rest.setExcepts(reqId) return rest
def __init__(self): self.rfeLibrary = RfeLibrary() self.rfeRfeTool = RfeLibTool()