示例#1
0
    def run(self):
        global questionsCollection
        global rlock
        global passed, failed

        while len(questionsCollection) > 0:
            # print(threading.current_thread().getName())
            # 得到 第一个对象,下标为 0
            standardQBeanTemp = questionsCollection.__getitem__(0)
            stdQ = standardQBeanTemp.question
            stdA = standardQBeanTemp.answer

            # 删除掉 下标为 0 第一个对象,须要 加锁
            rlock.acquire()
            try:
                questionsCollection.pop(0)
                print('共:' + str(excelSize - 1) + ' 个, 当前:' +
                      str(excelSize - 1 - len(questionsCollection)))
            except Exception:
                break
            finally:
                rlock.release()

            # 头信息
            header = {
                'Content-Type': 'application/json',
                'sessionId': str(gl.getTimestamp()),
                'userId': str(gl.getTimestamp()),
                'appId': 'b6ad1f823d8d4ffea36568330239f237'
            }
            # body(JSON) 信息
            bodystringStdQ = '{ "text": "' + stdQ + '"}'

            resposeJsonStdQ = httprequest.sendPostwithHeaders(
                url, header, bodystringStdQ)
            flag = False
            try:
                actualAnswer = resposeJsonStdQ['data'][0]['value']
            except BaseException:
                flag = True

            if flag == False:
                if gl.repaceSpecialCharactersinString(
                        actualAnswer) == gl.repaceSpecialCharactersinString(
                            stdA):
                    # print('pass')
                    standardQBeanTemp.testresult = 'pass'
                else:
                    standardQBeanTemp.testresult = 'fail'
                    remarks = '>>>期望标准答案:\n' + stdA + '\n>>>实际返回答案:\n' + actualAnswer
                    standardQBeanTemp.remarks = remarks
                    # print(remarks)
            else:
                standardQBeanTemp.testresult = 'fail'
                remarks = '>>>接口返回结果错误,见:\n' + str(resposeJsonStdQ)
                standardQBeanTemp.remarks = remarks

            questionsCollectionExcel.append(standardQBeanTemp)
示例#2
0
    def run(self):
        global questionsCollection
        global rlock
        global passed,failed

        while len(questionsCollection) > 0:
            # 得到 第一个对象,下标为 0
            IntenrtQbean =questionsCollection.__getitem__(0)
            intentQ = IntenrtQbean.question
            intentA = IntenrtQbean.answer

            # 删除掉 下标为 0 第一个对象,须要 加锁
            rlock.acquire()
            try:
                questionsCollection.pop(0)
                print('共:' + str(excelSize - 1) + ' 个, 当前:' + str(excelSize - 1 - len(questionsCollection)))
            except Exception:
                break
            finally:
                rlock.release()

            # 头信息
            header = {'Content-Type': 'application/json', 'sessionId': str(gl.getTimestamp()),
                          'userId': str(gl.getTimestamp()), 'appId': 'b6ad1f823d8d4ffea36568330239f237'}

            # body(JSON) 信息
            bodystringStdQ = '{ "text": "' + intentQ + '"}'


            resposeJsonStdQ = httprequest.sendPostwithHeaders(url, header, bodystringStdQ)
            flag = False
            try:
                actualAnswer =resposeJsonStdQ['info']['intent']
            except BaseException:
                flag = True

            if flag==False:
                if gl.repaceSpecialCharactersinString(actualAnswer) == gl.repaceSpecialCharactersinString(intentA):
                    IntenrtQbean.testresult == 'pass'
                else:
                    IntenrtQbean.testresult == 'fail'
                    remarks = '>>>期望意图:\n' + intentA + '\n>>>实际返回答案:\n' + actualAnswer
                    IntenrtQbean.remarks = remarks
            else:
                IntenrtQbean.testresult == 'fail'
                remarks = '>>>接口返回结果错误,见:\n' + str(resposeJsonStdQ)
                IntenrtQbean.remarks = remarks

            questionsCollectionExcel.append(IntenrtQbean)  #将测试结果写入测试集
示例#3
0
文件: intent.py 项目: anyuliuyi/sanyi
    def run(self):
        global questionsCollection
        global rlock
        global passed, failed
        while len(questionsCollection) > 0:
            # print(threading.current_thread().getName())
            # 得到 第一个对象,下标为 0
            standardQBeanTemp = questionsCollection.__getitem__(0)
            answer = standardQBeanTemp.stdquestion
            TestQ = standardQBeanTemp.testquestion

            # 删除掉 下标为 0 第一个对象,须要 加锁
            rlock.acquire()
            try:
                questionsCollection.pop(0)
                print('共:' + str(questioncount) + ' 个, 当前:' +
                      str(questioncount - len(questionsCollection)))
            except Exception:
                break
            finally:
                rlock.release()
            # 头信息
            header = {
                'Content-Type': 'application/json',
                "cache-control": "no-cache",
                "Postman-Token": "24786e26-bdb4-47a6-8150-01bdae22728d",
                'userId': str(gl.getTimestamp()),
                'appId': 'csbot',
            }

            # body(JSON) 信息
            bodystringTestQ = '{ "text": "' + str(TestQ) + '"}'

            resposeJsonTestQ = httprequest.sendPostwithHeaders(
                url, header, bodystringTestQ)

            flag = False

            try:
                module = resposeJsonTestQ['info']['module']
                intent = resposeJsonTestQ['info']['intent']
            except Exception as e:
                flag = True
            if flag == False:
                if gl.repaceSpecialCharactersinString(
                        intent) == gl.repaceSpecialCharactersinString(
                            answer) and module == "task_engine":
                    standardQBeanTemp.testresult = 'pass'
                    # print('---> Pass')
                else:
                    standardQBeanTemp.testresult = 'fail'
                    remarks = '>>>期望返回结果:\n' + answer + '\n>>>实际返回结果:\n' + intent + '\n 出话模块:' + module
                    standardQBeanTemp.remarks = remarks

            else:
                standardQBeanTemp.testresult = 'fail'
                remarks = '>>>接口实际返回结果:\n' + str(resposeJsonTestQ)
                standardQBeanTemp.remarks = remarks

            questionsCollectionExcel.append(standardQBeanTemp)
    def run(self):
        global questionsCollection
        global rlock
        global passed, failed
        while len(questionsCollection) > 0:
            # print(threading.current_thread().getName())
            # 得到 第一个对象,下标为 0
            standardQBeanTemp = questionsCollection.__getitem__(0)
            StdQ = standardQBeanTemp.stdquestion
            TestQ = standardQBeanTemp.testquestion

            # 删除掉 下标为 0 第一个对象,须要 加锁
            rlock.acquire()
            try:
                questionsCollection.pop(0)
                print('共:' + str(questioncount) + ' 个, 当前:' +
                      str(questioncount - len(questionsCollection)))
            except Exception:
                break
            finally:
                rlock.release()
            # 头信息
            header = {
                'Content-Type': 'application/json',
                'sessionId': str(gl.getTimestamp()),
                'userId': str(gl.getTimestamp()),
                'appId': 'b6ad1f823d8d4ffea36568330239f237'
            }

            # body(JSON) 信息
            bodystringTestQ = '{ "text": "' + str(TestQ) + '"}'
            bodystringStdQ = '{ "text": "' + str(StdQ) + '"}'

            resposeJsonTestQ = httprequest.sendPostwithHeaders(
                url, header, bodystringTestQ)
            resposeJsonStdQ = httprequest.sendPostwithHeaders(
                url, header, bodystringStdQ)
            flag = False
            try:
                AnswerTestQ = resposeJsonTestQ['data'][0]['value']
                AnswerStdQ = resposeJsonStdQ['data'][0]['value']
            except Exception as e:
                flag = True
            if flag == False:
                if gl.repaceSpecialCharactersinString(
                        AnswerTestQ) == gl.repaceSpecialCharactersinString(
                            AnswerStdQ):
                    standardQBeanTemp.testresult = 'pass'
                    # print('---> Pass')
                else:
                    standardQBeanTemp.testresult = 'fail'
                    remarks = '>>>标准问返回:\n' + AnswerStdQ + '\n>>>测试问返回:\n' + AnswerTestQ
                    standardQBeanTemp.remarks = remarks

            else:
                standardQBeanTemp.testresult = 'fail'
                remarks = '>>>标准问接口返回:\n' + str(
                    resposeJsonStdQ) + '\n>>>测试问接口返回:\n' + str(
                        resposeJsonTestQ)
                standardQBeanTemp.remarks = remarks

            questionsCollectionExcel.append(standardQBeanTemp)