Exemplo 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
Exemplo 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失敗")
Exemplo n.º 3
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))   
Exemplo n.º 4
0
 def testrun_case(self, data):
     #rows = excel_data.get_rows()
     #for i in range(rows):
     cookie = None
     get_cookie = None
     header = None
     #data = excel_data.get_rows_value(i+2)
     is_run = data[2]
     if is_run == 'yes':
         method = data[5]
         url = data[4]
         data1 = data[6]
         is_header = data[8]
         excepect_method = data[9]
         excepect_result = data[10]
         codition = data[3]
         if codition:
             pass
         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)
         code = str(res['errorCode'])
         message = res['errorDesc']
         if excepect_method == 'mec':
             config_message = handle_result(url, code)
             self.assertEqual(message, config_message)
             '''
             if message == config_message:
                 excel_data.excel_write_data(i+2,12,"通过")
             else:
                 excel_data.excel_write_data(i+2,12,"失败")
                 excel_data.excel_write_data(i+2,13,json.dumps(res))
             '''
         if excepect_method == 'errorcode':
             self.assertEqual(excepect_result, code)
             '''
             if excepect_result == code:
             
                 excel_data.excel_write_data(i+2,12,"通过")
             else:
                 excel_data.excel_write_data(i+2,12,"失败")
                 excel_data.excel_write_data(i+2,13,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)
             self.assertTrue(result)
             '''
Exemplo n.º 5
0
    def run_case(self):
        row = excel_data.get_row()

        for i in range(row):
            cookie = None
            get_cookie = None
            data = excel_data.get_row_value(i + 2)
            is_run = data[2]
            if is_run == 'yes':
                method = data[5]
                url = data[4]
                data1 = data[6]
                header = data[13]
                exthed_method = data[8]
                exthed_result = data[9]
                cookie_mother = data[7]
                if cookie_mother == "yes":
                    cookie = get_cookid_valus("app")

                if cookie_mother == "write":
                    get_cookie = {"is_cookie": "app"}
                if header == "yes":
                    is_header = get_header()
                res = request.run_main(method, url, data1, cookie, get_cookie,
                                       is_header)

                if exthed_method == 'mec':
                    code = "1003"
                    # message=res['errorCodeMes']
                    message = "用户名错误"
                    config_message = handle_result(url, code)
                    if message == config_message:
                        excel_data.excel_write_Data(i + 2, 11, "通过")
                        print("测试通过")
                    else:
                        excel_data.excel_write_Data(i + 2, 11, "失败")
                        excel_data.excel_write_Data(i + 2, 12, json.dumps(res))
                        print("测试失败")
                if exthed_method == 'errorcode':
                    code = "1006"
                    if exthed_result == code:
                        excel_data.excel_write_Data(i + 2, 11, "通过")
                        print("测试通过")
                    else:
                        excel_data.excel_write_Data(i + 2, 11, "失败")
                        excel_data.excel_write_Data(i + 2, 12, json.dumps(res))
                        print("测试失败")
                if exthed_method == "json":
                    code = res['errorCode']
                    # print("code=====",code)
                    if code == "10067":
                        status = "error"
                    else:
                        status = "succes"
                    excute_result = get_result_json(url, status)
                    result = handle_result_json(res, excute_result)
                    if result:
                        excel_data.excel_write_Data(i + 2, 11, "通过")
                    else:
                        excel_data.excel_write_Data(i + 2, 11, "失败")
                        excel_data.excel_write_Data(i + 2, 12, json.dumps(res))