Ejemplo n.º 1
0
    def test_main_case(self, data):
        cookie = None
        get_cookie = None
        header = None
        depend_data = None
        is_run = data[2]
        case_id = data[0]
        i = excel_data.get_rows_number(case_id)
        if is_run == 'yes':
            is_depend = data[3]
            data1 = json.loads(data[7])
            try:
                if is_depend:
                    #获取依赖数据
                    depend_key = data[4]

                    depend_data = get_data(is_depend)
                    #print(depend_data)
                    data1[depend_key] = depend_data
                method = data[6]
                url = data[5]

                is_header = data[9]
                expect_method = data[10]
                expect_result = data[11]

                cookie_method = data[8]
                if cookie_method == 'yes':
                    cookie = get_cookie_value('app')
                if cookie_method == 'write':
                    ''' 
                        必须是获取到cookie
                        '''
                    get_cookie = {"is_cookie": "app"}
                if is_header == 'yes':
                    header = get_header()

                res = request.run_main(method, url, data1, cookie, get_cookie,
                                       header)
                #print(code)
                code = str(res['errorCode'])
                #print(res['errorCode'])
                message = res['errorDesc']
                #message+errorcode

                if expect_method == 'mec':
                    config_message = handle_result(url, code)
                    '''
                            if message == config_message:
                                excel_data.excel_write_data(i,13,"通过")
                            else:
                                excel_data.excel_write_data(i,13,"失败")
                                excel_data.excel_write_data(i,14,json.dumps(res))
                        '''
                    try:
                        self.assertEqual(message, config_message)
                        excel_data.excel_write_data(i, 13, "通过")
                    except Exception:
                        excel_data.excel_write_data(i, 13, "失败")
                        excel_data.excel_write_data(i, 14, json.dumps(res))
                        raise Exception

                if expect_method == 'errorcode':
                    '''
                        if expect_result == code:
                            excel_data.excel_write_data(i,13,"通过")
                        else:
                            excel_data.excel_write_data(i,13,"失败")
                            excel_data.excel_write_data(i,14,json.dumps(res))
                        '''
                    try:
                        self.assertEqual(expect_result, code)
                        excel_data.excel_write_data(i, 13, "通过")
                    except Exception as e:
                        excel_data.excel_write_data(i, 13, "失败")
                        excel_data.excel_write_data(i, 14, json.dumps(res))
                        raise e
                if expect_method == 'json':
                    if code == 1000:
                        status_str = 'sucess'
                    else:
                        status_str = 'error'
                    expect_result = get_result_json(url, status_str)
                    result = handle_result_json(res, expect_result)
                    '''
                        if result:
                            excel_data.excel_write_data(i,13,"通过")
                        else:
                            excel_data.excel_write_data(i,13,"失败")
                            excel_data.excel_write_data(i,14,json.dumps(res))
                        '''
                    try:
                        self.assertTrue(result)
                        excel_data.excel_write_data(i, 13, "通过")
                    except Exception as e:
                        excel_data.excel_write_data(i, 13, "失败")
                        excel_data.excel_write_data(i, 14, json.dumps(res))
                        raise e
            except Exception as e:
                excel_data.excel_write_data(i, 13, "失败")
                raise e
Ejemplo n.º 2
0
 def run_case(self):
     rows = excel_data.get_rows()
     for i in range(rows):
         get_cookie = None
         cookie = None
         header = None
         data = excel_data.get_rows_value(i + 2)
         is_run = data[2]
         if is_run == "yes":
             method = data[5]
             # アクセスのapi
             url = data[4]
             data1 = data[6]
             is_header = data[8]
             # 予想結果判断の方法
             excepect_method = data[9]
             # 予想結果
             excepect_result = data[10]
             # クッキーの操作
             cookie_method = data[7]
             if cookie_method == "yes":
                 cookie = get_cookie_value("app")
             if cookie_method == "write":
                 """
                 cookie取得後書き込む
                 """
                 get_cookie = {"is_cookie": "app"}
             if is_header == "yes":
                 header = get_header()
             res = request.run_main(method, url, data1, cookie, get_cookie, header)
             # print(res)
             # 結果と予想結果を比較する
             # サーバーのerrorCode
             code = str(res["errorCode"])
             message = res["errorDesc"]
             if excepect_method == "mec":
                 config_message = handel_result(url, str(code))
                 if message == config_message:
                     excel_data.excel_write_data(i+2, 12, "成功")
                     print("テスト成功")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失敗")
                     # 失敗する場合は結果値も記入
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失敗")
             elif excepect_method == "errorcode":
                 if excepect_result == code:
                     excel_data.excel_write_data(i + 2, 12, "成功")
                     print("テスト成功")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失敗")
                     # 失敗する場合は結果値も記入
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失敗")
             elif excepect_method == "json":
                 # err_codeに基づいての判断
                 if code == "1000":
                     status_str = "success"
                 else:
                     status_str = "error"
                 excepect_result = get_result_json(url, status_str)
                 # サーバーからのリスポンスとjsonデータ比較
                 result = handel_result_json(res, excepect_result)
                 if result:
                     excel_data.excel_write_data(i + 2, 12, "成功")
                     print("テスト成功")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失敗")
                     # 失敗する場合は結果値も記入
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失敗")
Ejemplo n.º 3
0
 def run_case(self):
     rows = excel_data.get_rows()
     for i in range(rows):
         # i是从0开始的,excel中第一行内容的行号是i=2
         data = excel_data.get_rows_value(i + 2)
         #['imooc_001', '登录', 'yes', 'create_user', '/login/', 'post', '{"username":"******"}', 'yes', 'message', None]
         is_run = data[2]
         except_method = data[10]
         except_result = data[11]
         if is_run == "yes":
             url = data[5]
             method = data[6]
             data1 = data[7]
             res = request.run_main(method, url, data1)
             #int和str无法比较,需要强转一下
             code = str(res['errorCode'])
             desc = res['errorDesc']
             #如果预期结果方式为mec:message+errorcode
             if except_method == "mec":
                 config_message = handle_result(url, code)
                 if desc == config_message:
                     excel_data.excel_write_data(i + 2, 12, "通过")
                     print("case通过")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失败")
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失败")
             if except_method == "errorcode":
                 if except_result == code:
                     excel_data.excel_write_data(i + 2, 12, "通过")
                     print("case通过")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失败")
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失败")
             # 如果预期结果方式为json格式
             if except_method == "json":
                 if code == 1000:
                     status_str = "sucess"
                 else:
                     status_str = "error"
                 except_result_json = get_result_json(url, status_str)
                 # print(res,'-------',except_result_json)
                 result = handle_result_json(res, except_result_json)
                 if result:
                     excel_data.excel_write_data(i + 2, 12, "通过")
                     print("case通过")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失败")
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失败")
Ejemplo n.º 4
0
    def test_mainindex(self, data):
        """执行case主流程"""

        case_id = data[0]
        i = excel_data.get_rows_number(case_id)  # 行号

        header = None
        get_token = None

        is_run = data[2]

        if is_run == "yes":

            data1 = json.loads(data[7])
            is_depend = data[3]
            try:
                if is_depend:
                    """获取依赖数据"""
                    depend_key = data[4]
                    try:
                        depend_value = get_data(is_depend)
                    except:  # 依赖接口失败启动 mock函数获取依赖数据
                        depend_value = mock_depend()  # mock依赖
                    data1[depend_key] = depend_value

                url = data[5]
                method = data[6]

                expected_method = data[10]

                token_method = data[9]
                if token_method == 'yes':
                    """携带token"""
                    data2 = get_token_value("web")

                    header = data2
                if token_method == "write":
                    """写入token"""
                    get_token = {"is_token": "web"}

                res = BaseRequest.run(method, url, data1, get_token, header)

                code = res['meta']["status"]
                message = res['meta']["msg"]

                if expected_method == "mec":
                    configmes = handle_result_msg(url, code)

                    try:
                        self.assertEqual(configmes, message)
                        excel_data.excel_write_data(i, 13, "通过")
                    except AssertionError as e:
                        excel_data.excel_write_data(i, 13, "失败", "red")
                        raise e

                if expected_method == "json":  # expected_method自定义校验方法
                    if code == 200 or code == 201:
                        status_str = "success"

                    else:
                        status_str = "error"

                    except_res = get_result_json(url, status_str)
                    result = handle_result_json(res, except_res)

                    try:
                        self.assertTrue(result)
                        excel_data.excel_write_data(i, 13, "通过")
                    except AssertionError as e:
                        excel_data.excel_write_data(i, 13, "失败", "red")
                        raise e
            except Exception as e:
                raise e
            finally:
                excel_data.excel_write_data(
                    i, 14, json.dumps(res, indent=2, ensure_ascii=False))
Ejemplo n.º 5
0
    def run_case(self):
        rows = excel_data.get_rows()
        for i in range(rows):
            cookie=None
            get_cookie = None
            header = None
            depend_data = None
            data = excel_data.get_rows_value(i+2)
            is_run = data[2]
            if is_run == 'yes':
                is_depend = data[3]
                data1 = json.loads(data[7])
                if is_depend:
                    '''
                    获取依赖数据
                    '''
                    depend_key = data[4]
                    depend_data = get_data(is_depend)
                    #print(depend_data)
                    data1[depend_key] = depend_data

                method = data[6]
                url = data[5]
                
                is_header = data[9]
                excepect_method = data[10]
                excepect_result = data[11]
                cookie_method = data[8]
                if cookie_method == 'yes':
                    cookie = get_cookie_value('app')
                if cookie_method == 'write':
                    '''
                    必须是获取到cookie
                    '''
                    get_cookie={"is_cookie":"app"}
                if is_header == 'yes':
                    header = get_header()
                res = request.run_main(method,url,data1,cookie,get_cookie,header)
                #print(res)
                code = str(res['errorCode'])
                message = res['errorDesc']
                if excepect_method == 'mec': 
                    config_message = handle_result(url,code)
                    if message == config_message:
                        excel_data.excel_write_data(i+2,13,"通过")
                    else:
                        excel_data.excel_write_data(i+2,13,"失败")
                        excel_data.excel_write_data(i+2,14,json.dumps(res))
                if excepect_method == 'errorcode':
                    if excepect_result == code:
                        excel_data.excel_write_data(i+2,14,"通过")
                    else:
                        excel_data.excel_write_data(i+2,13,"失败")
                        excel_data.excel_write_data(i+2,14,json.dumps(res))
                if excepect_method == 'json':
                    if code == 1000:
                        status_str='sucess'
                    else:
                        status_str='error'
                    excepect_result = get_result_json(url,status_str)
                    result = handle_result_json(res,excepect_result)
                    if result:
                        excel_data.excel_write_data(i+2,13,"通过")
                    else:
                        excel_data.excel_write_data(i+2,13,"失败")
                        excel_data.excel_write_data(i+2,14,json.dumps(res))