def test_FC_F6030(self, tdata): deviceModel = product_model[0] Logger().debug("testdata:---" + str(tdata)) rd = myRedis(redis_db=device_list[deviceModel]) data = Default_data(deviceModel) test_id = tdata[0] test_content = tdata[2] data['text'] = tdata[4] pre_data = tdata[3] try: pre_data = json.loads(pre_data) except: pre_data = '{' + pre_data.replace('&', ',') + '}' try: pre_data = json.loads(pre_data) except Exception as e: Logger().error(e) raise e finally: pre_data = dict(data['query_reply'], **pre_data) data["query_reply"] = pre_data Response = Request().requests(url, data, "POST").json() # 校验接口是的请求成功 try: jsonpath.jsonpath(Response, "$..code")[0] == '200' except Exception as e: Logger().error(e) raise e nlu = jsonpath.jsonpath(Response, "$..nlu")[0] tts = jsonpath.jsonpath(Response, "$..text")[0].replace(",", ",") mid = jsonpath.jsonpath(Response, "$..mid")[0] try: lua = jsonpath.jsonpath(Response, "$..luaData")[0] except: lua = '' finally: rd.delete(test_id) # 清除旧缓存 rd.push_list(tdata) rd.push_onlydata(test_id, str(nlu)) rd.push_onlydata(test_id, str(lua)) rd.push_onlydata(test_id, str(tts)) try: if not str(nlu) == str(tdata[5]): raise Exception("NLU异常:%s!=%s" % (str(nlu), str(tdata[5]))) if not str(lua) == str(tdata[6]): raise Exception("lua命令转换异常:%s!=%s" % (str(lua), str(tdata[6]))) if not tts in eval(tdata[7]): raise Exception("TTS返回异常:%s not in %s" % (tts, eval(tdata[7]))) except Exception as e: result = e Logger().error(e) raise e else: result = "P" Logger().info(u"【%s--用例%s:%s】测试通过!" % (deviceModel + product, test_id, test_content)) finally: rd.push_onlydata(test_id, str(result)) rd.push_onlydata(test_id, str(mid))
def test_FC_KJ400G(self, tdata): deviceModel = "KJ400G" Logger().debug("testdata:---" + str(tdata)) data = Default_data(deviceModel) test_id = tdata[0] test_content = tdata[2] data['text'] = tdata[4] pre_data = tdata[3] test_row = int(re.split('_', test_id)[-1]) try: pre_data = json.loads(pre_data) except: pre_data = '{' + pre_data.replace('&', ',') + '}' try: pre_data = json.loads(pre_data) except Exception as e: Logger().error(e) raise e finally: pre_data = dict(data['query_reply'], **pre_data) data["query_reply"] = pre_data Response = Request().requests(url, data, "POST").json() # 校验接口是的请求成功 try: jsonpath.jsonpath(Response, "$..code")[0] == '200' except Exception as e: Logger().error(e) raise e nlu = jsonpath.jsonpath(Response, "$..nlu")[0] tts = jsonpath.jsonpath(Response, "$..text")[0].replace(",", ",") mid = jsonpath.jsonpath(Response, "$..mid")[0] try: lua = jsonpath.jsonpath(Response, "$..luaData")[0] except: lua = '' finally: # file_lock.acquire() r.write_onlydata(w, test_row, 8, str(nlu), sheetname=deviceModel) r.write_onlydata(w, test_row, 9, str(lua), sheetname=deviceModel) r.write_onlydata(w, test_row, 10, str(tts), sheetname=deviceModel) try: if not str(nlu) == str(tdata[5]): raise Exception("NLU异常:%s!=%s" % (str(nlu), str(tdata[5]))) if not str(lua) == str(tdata[6]): raise Exception("lua命令转换异常:%s!=%s" % (str(lua), str(tdata[6]))) if not tts in eval(tdata[7]): raise Exception("TTS返回异常:%s not in %s" % (tts, eval(tdata[7]))) except Exception as e: result = e Logger().error(e) raise e else: result = "P" Logger().info(u"【%s用例%s--%s】:测试通过!" % ("净化器-%s" % deviceModel, test_id, test_content)) finally: r.write_onlydata(w, test_row, 11, result, sheetname=deviceModel) r.write_onlydata(w, test_row, 12, mid, sheetname=deviceModel)
def test_EC_POWER601(self, tdata): appoint = Appointment() deviceModel = product_model[0] Logger().debug("testdata:---" + str(tdata)) rd = myRedis(redis_db=device_list[deviceModel]) data = Default_data(deviceModel) test_id = tdata[0] test_content = tdata[2] data['text'] = tdata[4] pre_data = tdata[3] # 对预期NLU进行日期转换(如果有日期的才会用到) tdata[5] = appoint.run_nlu(tdata[5]) # 查询类LUA测试时间修改 # test_lua = eval(tdata[6]) try: sign_msg = jsonpath.jsonpath(eval(tdata[6]), "$..sign_msg")[0] except: pass else: eval(tdata[6])['error']['sign_msg'] = Appointment().run_tts( sign_msg) # tdata[6] = str(test_lua) # 对TTS进行转换(预约有时间时用到) tts_list = eval(tdata[7]) for i in range(len(tts_list)): tts_list[i] = appoint.run_tts(tts_list[i]) tdata[7] = str(tts_list) try: pre_data = json.loads(pre_data) except: pre_data = '{' + pre_data.replace('&', ',') + '}' try: pre_data = json.loads(pre_data) except Exception as e: Logger().error(e) raise e finally: pre_data = dict(data['query_reply'], **pre_data) data["query_reply"] = pre_data Response = Request().requests(url, data, "POST").json() # 校验接口是的请求成功 try: jsonpath.jsonpath(Response, "$..code")[0] == '200' except Exception as e: Logger().error(e) raise e nlu = jsonpath.jsonpath(Response, "$..nlu")[0] tts = jsonpath.jsonpath(Response, "$..text")[0].replace(",", ",") mid = jsonpath.jsonpath(Response, "$..mid")[0] try: lua = jsonpath.jsonpath(Response, "$..luaData")[0] except: lua = '' finally: rd.delete(test_id) # 清除旧缓存 rd.push_list(tdata) rd.push_onlydata(test_id, str(nlu)) rd.push_onlydata(test_id, str(lua)) rd.push_onlydata(test_id, str(tts)) # lua校验错误时,跳过lua校验(预约时间校验出错,处理困难) if lua != '': if lua['error'] == {}: if not str(lua) == str(tdata[6]): raise Exception("lua命令转换异常:%s!=%s" % (str(lua), str(tdata[6]))) try: if not str(nlu) == str(tdata[5]): raise Exception("NLU异常:%s!=%s" % (str(nlu), str(tdata[5]))) if not tts in eval(tdata[7]): raise Exception("TTS返回异常:%s not in %s" % (tts, eval(tdata[7]))) except Exception as e: result = e Logger().error(e) raise e else: result = "P" Logger().info(u"【%s--用例%s:%s】测试通过!" % (deviceModel + product, test_id, test_content)) finally: rd.push_onlydata(test_id, str(result)) rd.push_onlydata(test_id, str(mid))
def test_AC_yb101(self, tdata): deviceModel = 'yb101' data = Default_data(deviceModel) test_id = tdata[0] test_content = tdata[2] data['text'] = tdata[4] pre_data = tdata[3] try: pre_data = json.loads(pre_data) except: pre_data = '{' + pre_data.replace('&', ',') + '}' try: pre_data = json.loads(pre_data) except Exception as e: Logger().error(e) raise e finally: pre_data = dict(data['query_reply'], **pre_data) data["query_reply"] = pre_data Response = Request().requests(url, data, "POST").json() nlu = jsonpath.jsonpath(Response, "$..nlu")[0] tts = jsonpath.jsonpath(Response, "$..text")[0] test_row = int(test_id.split('_')[-1]) mid = jsonpath.jsonpath(Response, "$..mid")[0] try: lua = jsonpath.jsonpath(Response, "$..luaData")[0] except: lua = '' finally: r.write_onlydata(w, test_row, 8, str(nlu), sheetname=deviceModel) r.write_onlydata(w, test_row, 9, str(lua), sheetname=deviceModel) r.write_onlydata(w, test_row, 10, str(tts), sheetname=deviceModel) try: assert str(nlu) == tdata[5], "NLU异常" except Exception as e: Logger().error(e) result = "NLU异常" raise e else: try: assert str(lua) == tdata[6], "lua命令转换异常" except Exception as e: Logger().error(e) result = "lua命令转换异常" raise e else: try: assert tts in eval(tdata[7]), "TTS返回异常" except Exception as e: Logger().error(e) result = "TTS返回异常" raise e else: result = "P" Logger().info( u"【%s用例%s--%s】:测试通过!" % ("%s空调" % deviceModel, test_id, test_content)) finally: r.write_onlydata(w, test_row, 11, str(result), sheetname=deviceModel) r.write_onlydata(w, test_row, 12, mid, sheetname=deviceModel)