def get_es_result(assert_value, params, index_name, es_query):
        answer_list, resultlist = [], []
        if "question" in assert_value:
            result = ElasticConnect(index_name).get_search(es_query)
            totle_num = result["hits"]["total"].get("value")
            return totle_num

        elif "answer" in assert_value:
            result = ElasticConnect(index_name).get_search(es_query)
            totle_num = result["hits"]["total"].get("value")
            return totle_num
Esempio n. 2
0
    def faq_delete(url, params, assert_value):
        path = "/faqConfig/robotFAQ/delete"
        delete_id_list = []
        not_delete_id = [
            "101478400129073152", "101305312947044352", "101305407436324864",
            "101478344294498304"
        ]
        try:
            result = requests.post(url=url + path,
                                   data=json.loads(params)).json()
            if "code" in assert_value:
                re_code = str(result["code"])
                except_data = assert_value.split("-")[1]
                if re_code == "8":
                    try:
                        # 针对delete额外操作:修改用例表,将faqId重新从库中寻找
                        delete_id = ElasticConnect("robot_faq").get_search(
                            FaqDelete.query_es())["hits"]["hits"][0].get("_id")
                        not_delete_id.append(delete_id)
                        wb = openpyxl.load_workbook(
                            rootPath + "testdata\\robotfaq\\faq_robot.xlsx")
                        sheet = wb["delete_faq"]
                        FaqDelete.modify(sheet, '正常删除',
                                         '{ "ids":"[' + str(delete_id) + ']"}')
                        FaqDelete.modify(sheet, '重复删除',
                                         '{ "ids":"[' + str(delete_id) + ']"}')
                        wb.save(rootPath +
                                "testdata\\robotfaq\\faq_robot.xlsx")

                    except Exception as e:
                        print('修改表格出错!', '\n', e)

                    # 删除该测试账号下无用的账号,877为userId为11下的需要校验的robot manage,709用与查询robot config非空查询
                    es_result = ElasticConnect("robot_faq").get_search(
                        FaqDelete.query_es())["hits"]["hits"]
                    for i in es_result:
                        if i.get("_id") not in not_delete_id:
                            delete_id_list.append(int(i.get("_id")))
                    new_delete = json.dumps(
                        eval('{ "ids":"' + str(delete_id_list) + '"}'))
                    aother_result = requests.post(
                        url=url + path, data=json.loads(new_delete)).json()
                    print("删除多余faq成功")
                return re_code, except_data
            elif "message" in assert_value:
                re_message = result["message"]
                expect_data = assert_value.split("-")[1]
                return re_message, expect_data
            else:
                return result, assert_value
        except Exception:
            raise Exception
 def get_es_result(params, index_name, es_query):
     es_result, answer_list, resultlist, final_result_list = [], [], [], []
     result = ElasticConnect(index_name).get_search(
         es_query)
     normal_result = result["hits"]
     for i in range(len(normal_result["hits"])):
         faq_answer = ElasticConnect("template_faq_answer").get_search(
             FaqQueryTemplatePage.get_answer_query(eval(normal_result["hits"][i]["_source"].get("answerIds"))))[
             "hits"]["hits"]
         for j in range(len(faq_answer)):
             faq_answer[j].get("_source")
             answer_list.append({
                 "content": faq_answer[j]["_source"].get("content"),
                 "parentFAQId": str(faq_answer[j]["_source"].get("parentFAQId")),
                 "categoryId": str(faq_answer[j]["_source"].get("categoryId")),
                 "addTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                          time.localtime(float(faq_answer[j]["_source"].get("addTime")) / 1000)),
                 "modifyTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                             time.localtime(
                                                 float(faq_answer[j]["_source"].get("modifyTime")) / 1000)),
                 "templateId": str(faq_answer[j]["_source"].get("templateId"))
             })
         first_result = normal_result["hits"][i].get("_source")
         final_result = {"id": str(first_result.get("id")),
                         'question': first_result.get("question"),
                         'categoryId': str(first_result.get("categoryId")),
                         'answerIds': first_result.get("answerIds"),
                         'addTime': time.strftime("%Y-%m-%d %H:%M:%S",
                                                  time.localtime(float(first_result.get("addTime")) / 1000)),
                         'modifyTime': time.strftime("%Y-%m-%d %H:%M:%S",
                                                     time.localtime(float(first_result.get("modifyTime")) / 1000)),
                         'templateId': str(first_result.get("templateId")),
                         'answerForms': answer_list,
                         }
         resultlist.append(final_result)
         answer_list = []
     es_result = {
         "resultlist": resultlist,
         "totalrecord": normal_result["total"].get("value"),
         "curPage": eval(params).get("curPage") if "curPage" in params else 1,
         "pageSize": eval(params).get("pageSize") if "pageSize" in params else 10,
         "totalPage": math.ceil(int(normal_result["total"].get("value")) / (
             eval(params).get("pageSize"))) if "pageSize" in params else 10,
         "beginIndex": ((eval(params).get("curPage") if "curPage" in params else 1) - 1) * eval(params).get(
             "pageSize") if "pageSize" in params else 10
     }
     return json.dumps(es_result)
 def get_es_result(index_name, es_query):
     es_result = []
     result = ElasticConnect(index_name).get_search(es_query)
     categorys = result["hits"]
     es_result.append({
         "categoryId": "0",
         "categoryName": "未分类",
         "questionNum": categorys["total"].get("value"),
         "unAllot": True
     })
     return es_result
Esempio n. 5
0
 def get_question_info(question_ids):
     question_result = []
     questions = ElasticConnect("robot_faq").get_search(
         FaqQueryById.get_query_ids(question_ids))["hits"]["hits"]
     for i in range(len(questions)):
         question_single = {
             "id": str(questions[i]["_source"].get("id")),
             "question": questions[i]["_source"].get("question"),
             "parentId": str(questions[i]["_source"].get("parentId")),
             "categoryId": str(questions[i]["_source"].get("categoryId")),
             "enable": questions[i]["_source"].get("enable"),
             "effectiveType": questions[i]["_source"].get("effectiveType"),
             "addTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                      time.localtime(float(questions[i]["_source"].get("addTime")) / 1000)),
             "modifyTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                         time.localtime(float(questions[i]["_source"].get("modifyTime")) / 1000)),
             "userId": str(questions[i]["_source"].get("userId")),
             "robotId": str(questions[i]["_source"].get("robotId"))
         }
         question_result.append(question_single)
     return question_result
Esempio n. 6
0
 def get_es_result(index, es_query):
     es_result = []
     result = ElasticConnect(index).get_search(es_query)
     question_info = result["hits"]["hits"][0].get("_source")
     similar_questions, related_questions, related_questions = [], [], []
     if question_info.get("similarQuestionIds") is not None:
         similar_questions = FaqQueryById.get_question_info(question_info.get("similarQuestionIds"))
     if question_info.get("relateQuestionIds") is not None:
         for i in eval(question_info.get("relateQuestionIds")):
             related_question = FaqQueryById.get_es_result("robot_faq", FaqQueryById.get_relatinship_id(i))
             related_questions.append(related_question)
     if question_info.get("answerIds") is not None:
         answers = FaqQueryById.get_answer_info(question_info.get("answerIds"))
     es_result = {
         "id": str(question_info.get("id")),
         "question": question_info.get("question"),
         "parentId": str(question_info.get("parentId")),
         "similarQuestionIds": question_info.get("similarQuestionIds"),
         "similarQuestionforms": similar_questions,
         "categoryId": str(question_info.get("categoryId")),
         "hits": str(question_info.get("hits")),
         "enable": question_info.get("enable"),
         "effectiveType": question_info.get("effectiveType"),
         "relateQuestionIds": question_info.get("relateQuestionIds"),
         "relateQuestionForms": related_questions,
         "answerIds": question_info.get("answerIds"),
         "answerForms": answers,
         "addTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                  time.localtime(float(question_info.get("addTime")) / 1000)),
         "modifyTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                     time.localtime(float(question_info.get("modifyTime")) / 1000)),
         "userId": str(question_info.get("userId")),
         "robotId": str(question_info.get("robotId")),
         "sourceType": str(question_info.get("sourceType"))
     }
     if question_info.get("relateQuestionIds") is None:
         es_result.pop("relateQuestionIds")
     if question_info.get("similarQuestionIds") is None:
         es_result.pop("similarQuestionIds")
     return es_result
Esempio n. 7
0
 def get_answer_info(question_ids):
     answer_result = []
     answers = ElasticConnect("robot_faq_answer").get_search(
         FaqQueryById.get_query_ids(question_ids))["hits"]["hits"]
     for i in range(len(answers)):
         answer_single = {
             "id": str(answers[i]["_source"].get("id")),
             "condition": answers[i]["_source"].get("condition"),
             "parentFAQId": str(answers[i]["_source"].get("parentFAQId")),
             "categoryId": str(answers[i]["_source"].get("categoryId")),
             "content": answers[i]["_source"].get("content"),
             "addTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                      time.localtime(float(answers[i]["_source"].get("addTime")) / 1000)),
             "modifyTime": time.strftime("%Y-%m-%d %H:%M:%S",
                                         time.localtime(float(answers[i]["_source"].get("modifyTime")) / 1000)),
             "userId": str(answers[i]["_source"].get("userId")),
             "robotId": str(answers[i]["_source"].get("robotId"))
         }
         if answers[i]["_source"].get("condition") == None:
             answer_single.pop("condition")
         answer_result.append(answer_single)
     return answer_result
Esempio n. 8
0
    def get_expect_result(params, index, es_query):

        get_es_result = ElasticConnect(index).get_search(es_query)["hits"]
        es_results, final_result = [], {}
        for i in range(len(get_es_result["hits"])):
            if "question" in params:
                result = {
                    "id":
                    str(get_es_result["hits"][i]["_source"].get("id")),
                    "question":
                    get_es_result["hits"][i]["_source"].get("question"),
                    "similarQuestionCount":
                    len(
                        eval(get_es_result["hits"][i]["_source"].get(
                            "similarQuestionIds"))) if get_es_result["hits"][i]
                    ["_source"].get("similarQuestionIds") is not None else 0,
                    "effectiveType":
                    get_es_result["hits"][i]["_source"].get("effectiveType"),
                    "userId":
                    str(get_es_result["hits"][i]["_source"].get("userId")),
                    "robotId":
                    str(get_es_result["hits"][i]["_source"].get("robotId")),
                    "modifyTime":
                    time.strftime(
                        "%Y-%m-%d %H:%M:%S",
                        time.localtime(
                            float(get_es_result["hits"][i]["_source"].get(
                                "modifyTime")) / 1000))
                }
                if "keyword" not in params and get_es_result["hits"][i][
                        "_source"].get("similarQuestionIds") is None:
                    result.pop("similarQuestionCount")

            elif "similarQuestion" in params:
                belongStandardQuestion = ElasticConnect(
                    "robot_faq").get_search(
                        FaqSearchPage.get_question_query(
                            str(get_es_result["hits"][i]["_source"].get(
                                "parentId")))
                    )["hits"]["hits"][0]["_source"].get("question")
                result = {
                    "id":
                    str(get_es_result["hits"][i]["_source"].get("id")),
                    "similarQuestion":
                    get_es_result["hits"][i]["_source"].get("question"),
                    "belongStandardQuestionId":
                    str(get_es_result["hits"][i]["_source"].get("parentId")),
                    "belongStandardQuestion":
                    belongStandardQuestion,
                    "effectiveType":
                    get_es_result["hits"][i]["_source"].get("effectiveType"),
                    "effectiveStartTime":
                    str(get_es_result["hits"][i]["_source"].get(
                        "effectiveStartTime")),
                    "effectiveEndTime":
                    str(get_es_result["hits"][i]["_source"].get(
                        "effectiveEndTime")),
                    "userId":
                    str(get_es_result["hits"][i]["_source"].get("userId")),
                    "robotId":
                    str(get_es_result["hits"][i]["_source"].get("robotId")),
                }
            elif "answer" in params:
                question_result = ElasticConnect("robot_faq").get_search(
                    FaqSearchPage.get_question_query(
                        str(get_es_result["hits"][i]["_source"].get(
                            "parentFAQId"))))["hits"]["hits"][0]["_source"]
                belongStandardQuestion = question_result.get("question")
                effectiveType = question_result.get("effectiveType")
                effectiveStartTime = str(
                    question_result.get("effectiveStartTime"))
                effectiveEndTime = str(question_result.get("effectiveEndTime"))
                result = {
                    "id":
                    str(get_es_result["hits"][i]["_source"].get("id")),
                    "answer":
                    get_es_result["hits"][i]["_source"].get("content"),
                    "belongStandardQuestionId":
                    str(get_es_result["hits"][i]["_source"].get(
                        "parentFAQId")),
                    "belongStandardQuestion":
                    belongStandardQuestion,
                    "effectiveType":
                    effectiveType,
                    "effectiveStartTime":
                    effectiveStartTime,
                    "effectiveEndTime":
                    effectiveEndTime,
                    "userId":
                    str(get_es_result["hits"][i]["_source"].get("userId")),
                    "robotId":
                    str(get_es_result["hits"][i]["_source"].get("robotId")),
                }
            es_results.append(result)
        final_result = {
            "resultlist":
            es_results,
            "totalrecord":
            get_es_result["total"].get("value"),
            "curPage":
            int(eval(params).get("curPage")) if "curPage" in params else 1,
            "pageSize":
            int(eval(params).get("pageSize")) if "pageSize" in params else 10,
            "totalPage":
            math.ceil(
                int(get_es_result["total"].get("value")) /
                (int(eval(params).get("pageSize"))
                 if "pageSize" in params else 10)),
            "beginIndex":
            (int((eval(params).get("curPage")) if "curPage" in params else 1) -
             1) *
            (int(eval(params).get("pageSize")) if "pageSize" in params else 10)
        }
        return final_result
Esempio n. 9
0
    def get_expect_result(params, index, es_query):

        get_question = ElasticConnect(index).get_search(es_query)["hits"]
        final_result = get_question["total"].get("value")
        return final_result