Exemple #1
0
    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))
Exemple #2
0
def nlu(each):
    url = "https://nlu.sit.aimidea.cn:22012/nlu/v1"
    data = {"currentUtterance": "这款空调有什么特色", "sourceDevice": "空调", "multiDialog": "false", "slotMiss": "false",
            "suites": ["default"], "deviceId": "3141482994683870", "userGroup": "meiju",
            "userGroupCredential": "b82063f4-d39b-4940-91c3-5b67d741b4d3"}
    data["currentUtterance"] = each
    result = Request().requests(url, data, 'post')
    result = result.json()
    classifier = result['classifier']
    if classifier != "publicDomain":
        print(each + ":"+classifier)
        with open(result_path, 'a', encoding='utf8') as f:
            f.write(each+":"+str(result)+'\n')
            # f.close()
    else:
        print(each + ":"+classifier)
Exemple #3
0
def nlu(utterance):
    url = "https://nlu.sit.aimidea.cn:22012/nlu/v1"
    # data=dict()
    data = {
        "currentUtterance": "请马上关机",
        "sourceDevice": "空调",
        "multiDialog": "true",
        "slotMiss": "true",
        "suite": ["default"],
        "deviceId": "4311026980750221",
        "userGroup": "meiju",
        "userGroupCredential": "b82063f4-d39b-4940-91c3-5b67d741b4d3",
        "customDeviceNames": "",
        "customRoomNames": ""
    }
    data["currentUtterance"] = utterance
    result = Request().requests(url, data, 'post')
    nlu_result = result.json()
    return nlu_result
Exemple #4
0
    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)
Exemple #5
0
    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 OnlyInterface(**data):
    url = data['url']
    type = data['type']
    header = data['header']
    testdata = data['参数']
    check = data['校验']
    if isinstance(testdata, dict):
        pass
    else:
        try:
            testdata = eval(testdata)
        except Exception as e:
            Logger().error(e)
            testdata = {}

    up_data = data['继承参数']
    if up_data == '':
        up_data = {}
    else:
        try:
            up_data = eval(up_data)
        except Exception as e:
            Logger().error(e)
            up_data = {}

    parameter = data['调用参数']
    downdata = data['下传参数']
    if header == '':
        header = {}
    else:
        try:
            header = eval(header)
        except Exception as e:
            Logger().error(e)
            header = {}
    if parameter == '':
        testdata = testdata
    else:
        try:
            parameter = eval(parameter)
        except Exception as e:
            Logger().error(e)
            # parameter = ''
        else:
            for each in parameter:
                testdata[each] = up_data[each]
    respone = Request().requests(url, testdata, type, headers=header)
    respone = respone.json()

    try:
        if check != '':
            check = eval(check)
            for each in check.keys():
                assert respone[each] == check[each], "接口【%s】响应校验失败" % url
        else:
            Logger().info("跳过接口响应校验,测试继续")
    except Exception as e:
        Logger().error(e)
    else:
        if downdata != '':
            try:
                downdata = eval(downdata)
            except Exception as e:
                # downdata={}
                Logger().error(e)
            else:
                for key in downdata.keys():
                    down_value = downdata[key].split("=>")
                    s = respone
                    for i in range(0, len(down_value)):
                        s = s[down_value[i]]
                        i += 1
                    downdata[key] = s
                    up_data.update(downdata)
        result0 = [respone, up_data]
    return result0
Exemple #7
0
# foodname=foodname_data[0][redis_case]
# yuliao1=yuliao1%foodname
# # yuliao2 = yuliao2 % foodname
# data1["currentUtterance"]=yuliao1
# result1=Request().requests(url,data1,'POST')
# print(result1)
# if result1["intent"]["intentType"]=="questionWhichRoomStore":
#     print("pass")

for i in range(len(foodname_data)):
    foodname = foodname_data[i][1]
    yuliao1 = yuliao1.format(foodname)
    yuliao2 = yuliao2.format(foodname)
    data1["currentUtterance"] = yuliao1
    result1 = Request().requests(url, data1, 'POST')
    if result1["intent"]["intentType"] == "questionWhichRoomStore":
        print("食材【{}:{}】无冰箱语料测试结果:{}".format(i, foodname, "pass"))
        r.write_onlydata(new_book, i + 1, 3, "Pass")
    else:
        print("食材【{}:{}】无冰箱语料测试结果:{}".format(i, foodname, "fail"))
        r.write_onlydata(new_book, i + 1, 3, "Fail")
    data2["currentUtterance"] = yuliao2
    result2 = Request().requests(url, data2, 'POST')
    # print(result)
    if result2["intent"]["intentType"] == "questionWhichRoomStore":
        print("食材【{}:{}】有冰箱语料测试结果:{}".format(i, foodname, "pass"))
        r.write_onlydata(new_book, i + 1, 2, "PASS")
    else:
        print("食材【{}:{}】有冰箱语料测试结果:{}".format(i, foodname, "pass"))
        r.write_onlydata(new_book, i + 1, 2, "Fail")
    def test_ricecooker_400XM(self, tdata):
        test_id = tdata[0]
        test_content = tdata[2]
        data['text'] = tdata[4]
        data['device_info'][0]['serailNo'] = sn_ricecooker
        pre_data = tdata[3]
        Expect_nlu = tdata[5]
        Expect_lua = tdata[6]
        Expect_tts = tdata[7]

        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(rice_cooker_query, **pre_data)
            data["query_reply"] = pre_data

        Response = Request().requests(url, data, "POST").json()
        print("**************")
        print(Response)
        # 校验接口是的请求成功
        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(",", ",")
        test_row = int(test_id.split('_')[-1])
        try:
            lua = jsonpath.jsonpath(Response, "$..luaData")[0]
        except:
            lua = ''
        finally:
            r.write_onlydata(w, test_row, 8, str(nlu), sheetname='中高端电饭煲')
            r.write_onlydata(w, test_row, 9, str(lua), sheetname='中高端电饭煲')
            r.write_onlydata(w, test_row, 10, str(tts), sheetname='中高端电饭煲')

        try:
            assert str(nlu) == Expect_nlu, "NLU异常"
        except Exception as e:
            Logger().error(e)
            result = "NLU异常"
            raise e
        else:
            try:
                assert str(lua) == Expect_lua, "lua命令转换异常"
            except Exception as e:
                Logger().error(e)
                result = "lua命令转换异常"
                raise e
            else:
                try:
                    assert tts in eval(Expect_tts), "TTS返回异常"
                except Exception as e:
                    Logger().error(e)
                    result = "TTS返回异常"
                    raise e
                else:
                    result = "P"
                    Logger().info(u"【%s用例%s--%s】:测试通过!" %
                                  ("中高端电饭煲", test_id, test_content))
        finally:
            r.write_onlydata(w, test_row, 11, str(result), sheetname='中高端电饭煲')
Exemple #9
0
    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)
Exemple #10
0
def get_expectData(product_model, path, result_path, run_num=None):
    if run_num == None:
        run_num = 1
    host = Conf(http_conf_path).get_value("HTTP", "sit")
    url = "%s/v1/auto_test/control/virtual" % host
    data = Default_data(product_model)
    queryinfo = data['query_reply']
    r = Read_xls(path)
    data_list = r.read_data(product_model, start_line=2)
    w = r.copy_book()
    for i in range(len(data_list)):
        testid = data_list[i][0]
        tdata = data_list[i][3]
        try:
            tts_list = eval(data_list[i][7])
        except:
            tts_list = []
        try:
            testdata = json.loads(tdata)
        except:
            testdata = '{' + tdata.replace('&', ',') + '}'
            try:
                testdata = json.loads(testdata)
            except Exception as e:
                print(e)
            else:
                testdata = dict(queryinfo, **testdata)
        finally:
            print(testid)
            data['text'] = data_list[i][4]
            data["query_reply"] = testdata
            n = run_num
            while n > 0:
                Response = Request().requests(url, data, "POST").json()
                tts = str(Response['data']['tts']['data'][0]['text'])
                print(tts)
                tts_list.append(tts)
                nlu = Response['data']['nlu']
                try:
                    lua = jsonpath.jsonpath(Response, "$..luaData")[0]
                except Exception as e:
                    lua = ''
                print(lua)
                if n == 1:
                    tts_list.append(tts)
                    tts_lists = list(set(tts_list))
                    print(tts_lists)
                    r.write_onlydata(w,
                                     i + 1,
                                     5,
                                     str(nlu),
                                     sheetname=product_model)
                    r.write_onlydata(w,
                                     i + 1,
                                     6,
                                     str(lua),
                                     sheetname=product_model)
                    r.write_onlydata(w,
                                     i + 1,
                                     7,
                                     str(tts_lists),
                                     sheetname=product_model)
                else:
                    tts_list.append(tts)
                n -= 1
        i += 1
    r.save_write(w, result_path)
Exemple #11
0
from common.http_request_new import Request
import os

data = {
    'text':
    "redis_case、制冷时,把设定温度升高1℃,制热时把设定温度降低2℃,可省电10%。2、制热时尽量少开电辅热功能。3、使用环境较恶劣的需要经常清洗空调过滤网及外机.4、房间需要有良好的隔热效果和密封性。5、变频空调需要使用时间越长,省电效果要比定频空调更明显。"
}
yuliao = '''
redis_case、制冷时,把设定温度升高1℃,制热时把设定温度降低2℃,可省电10%。2、制热时尽量少开电辅热功能。3、使用环境较恶劣的需要经常清洗空调过滤网及外机.4、房间需要有良好的隔热效果和密封性。5、变频空调需要使用时间越长,省电效果要比定频空调更明显。
'''
# url="http://sit.aimidea.cn:11003/v1/orion/tts?text=%s"%yuliao
url = "http://sit.aimidea.cn:11003/v1/orion/tts"
a = Request().requests(url, data, "get")
print(a)
b = "start %s " % a
os.system(b)