Пример #1
0
 def move_case(cls, main_case_path, case_name, test_dir):
     """
     移动case文件
     :param main_case_path:
     :param case_name:
     :param test_dir:
     :return:
     """
     if type(main_case_path) == list:
         for path in main_case_path:
             # 寻找将执行用例的文件名称
             log.debug('case_name:%s' % case_name)
             find_case_path = Misc.ABSpath() + path
             # 寻找将执行用例的路径
             log.debug('find_case_path:' + str(find_case_path))
             case_path = find_case_path + case_name
             # 找到要执行的用例文件路径
             log.debug('case_path:' + str(case_path))
             Misc.copy_file(case_path, test_dir)
     else:
         log.debug('case_name:%s' % case_name)
         find_case_path = Misc.ABSpath() + main_case_path
         # 寻找将执行用例的路径
         log.debug('find_case_path:' + str(find_case_path))
         case_path = find_case_path + case_name
         # 找到要执行的用例文件路径
         log.debug('case_path:' + str(case_path))
         Misc.copy_file(case_path, test_dir)
Пример #2
0
    def set_test_result(cls, response, status_code, interfacename, casename, comment, result):
        """
        存入测试结果
        :param response:
        :param status_code:
        :param interfacename:
        :param casename:
        :param comment:
        :param result:
        :param main:
        :return:
        """
        base = Base()
        tr = test_result()
        tr.__init__()
        status = ''
        res_time = ''
        main = Run.Main
        type = base.getApiType(interfacename)

        try:
            res_time = Misc.read_from_file('res_time')[0]
            status = response['succ']
            cls.response_new = 'succ:%s' % response['succ']
            try:
                if response['succ'] != '1':
                    # 有可能不存在msg,try一下
                    cls.response_new = response['msg']
            except:
                pass
        except:
            status = status_code
            cls.response_new = Base.todo_string(response)
        finally:
            try:
                if main in 'api':

                    # 操作 api_pass_rate表
                    if result in 'Fail':
                        if 'xx' in url_target:
                            apr.update_fail_num(interfacename)
                        else:
                            aprwph.update_fail_num(interfacename)
                    else:
                        if 'xx' in url_target:
                            apr.update_pass_num(interfacename)
                        else:
                            aprwph.update_pass_num(interfacename)

                    # 操作api_performance表
                    if int(res_time) > 0.3:
                        status = 'Fail'
                    else:
                        status = 'Pass'
                    data = {
                        "if_name": interfacename,
                        "case_name": casename,
                        "res_time": res_time,
                        "type": type,
                        "status": status,
                    }
                    ap.insert_apiPerformance(data)

                # 操作test_result表
                data = {
                    "if_name": interfacename,
                    "case_name": casename,
                    "comment": comment,
                    "status": status,
                    "result": result,
                    "response": cls.response_new,
                    "url_target": url_target,
                    "type": type,
                    "main": main,
                }
                tr.insert_testResult(data)

            except Exception as msg:
                print (msg)
                raise