Exemple #1
0
def run(file_name, sheet_name, c1, c2):
    global token  #声明全局变量
    #首先取出测试用例
    all_case = read_data(file_name, sheet_name)

    uri = 'http://120.78.128.25:8766'
    #先执行第一条登录
    # test_data=all_case[0]   #2列:login/recharge  4列 get/post 5列 接口地址 6列 data 7列 期望结果

    for i in range(0, len(all_case)):
        test_data = all_case[i]
        response = http_request(uri + test_data[4], eval(test_data[5]), token,
                                test_data[3])
        if test_data[1] == 'login':
            token = 'Bearer ' + response['data']['token_info']['token']
        write_data(file_name, sheet_name, i + 2, c1, str(response))
        print(response)
        # 判断测试用例是否通过

        actual = {'code': response['code'], 'msg': response['msg']}
        if eval(test_data[6]) == actual:
            print('测试用例执行通过')
            write_data(file_name, sheet_name, c1, c2, 'PASS')
        else:
            print('测试用例执行不通过')
            write_data(file_name, sheet_name, c1, c2, 'FAILD')
Exemple #2
0
    def get_asset(self, request):
        params = {"version": 2, "request": request}

        data = http_request(self.API_PAGE, params)

        decompressed = zlib.decompress(data, 16 + zlib.MAX_WBITS)

        dl_url = ""
        dl_cookie = ""

        match = re.search(b"(https?:\/\/[^:]+)", decompressed)

        if match is None:
            raise Exception("Unexpected response.")

        else:
            dl_url = match.group(1).decode('utf-8')

        match = re.search(b"MarketDA.*?(\d+)", decompressed)

        if match is None:
            raise Exception("Unexpected response.")

        else:
            dl_cookie = match.group(1).decode('utf-8')

        return (dl_url, dl_cookie)
    def get_asset(self, request):
        params = {
            "version": 2,
            "request": request
        }

        data = http_request(self.API_PAGE, params)

        decompressed = zlib.decompress(data, 16 + zlib.MAX_WBITS)

        dl_url = ""
        dl_cookie = ""

        match = re.search(b"(https?:\/\/[^:]+)", decompressed)

        if match is None:
            raise Exception("Unexpected response.")

        else:
            dl_url = match.group(1).decode('utf-8')

        match = re.search(b"MarketDA.*?(\d+)", decompressed)

        if match is None:
            raise Exception("Unexpected response.")

        else:
            dl_cookie = match.group(1).decode('utf-8')

        return (dl_url, dl_cookie)
Exemple #4
0
def run(file_name, sheet_name):
    global Token
    all_case = read_data(file_name, sheet_name)
    for test_data in all_case:
        uri = "http://120.78.128.25:8766"
        response = http_request(uri + test_data[4],
                                eval(test_data[5]),
                                token=Token,
                                method=test_data[3])
        if 'login' in test_data[4]:
            Token = 'Bearer ' + response['data']['token_info']['token']
Exemple #5
0
def operate_case_success():
    if request.method == 'POST':
        selectdata = request.values.get("case")
        print(selectdata)
        cases = Case.query.filter(Case.inter_name == selectdata)
        print(cases)
        for case in cases:
            print(case)
            url = []
            url.append(case.url)
            method = []
            method.append(case.method)
            data = []
            data.append(case.data)
            inter_name = []
            inter_name.append(case.inter_name)
            case_name = []
            case_name.append(case.case_name)
            header = []
            header.append(case.header)
            msg = []
            msg.append(case.msg)
            code = []
            code.append(case.code)
            expect = []
            expect.append(case.expect)
            status = []
            status.append(case.status)
            actual = []
            actual.append(case.actual)
            id = []
            id.append(case.id)
            print(method, url, code, data)
            result = http_request.http_request(method[0], url[0], data[0])
            if result.json()["code"] == int(code[0]):
                print(result.json()["code"])
                status[0] = str(True)
                actual[0] = str(result.json())
            else:
                print(result.json()["code"])
                status[0] = str(False)
                actual[0] = str(result.json())
            addreport=Report(id=id[0],url=url[0],method=method[0],data=data[0],\
                             inter_name=inter_name[0],case_name=case_name[0],\
                             header=header[0],expect=expect[0],code=code[0],\
                             msg=msg[0],status=status[0],actual=actual[0])
            db.session.add(addreport)
            db.session.commit()
    else:
        return render_template('operatecase.html')
    return redirect(url_for('report'))
def generate_http_request(n):
	get_headers = {
	'host': '127.0.0.1',
	'connection': 'keep-alive',
	'x-requested-with': 'XMLHttpRequest',
	'upgrade-insecure-requests': '1',
	'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
	'referer': 'http://www.mysite.com/',
	'accept': 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8',
	'accept-encoding': 'gzip, deflate, sdch',
	'accept-language': 'bg-BG, bg;q=0.8, en;q=0.6, de;q=0.7',
	'accept-charset': 'utf-8, iso-8859-1;q=0.5, *;q=0.1',
	'dnt': '1',
	'cache-control': 'must-revalidate, public, max-age=0'
	}
	request = http_request('http://google.com/test/test.php?id='+str(n),'GET', headers=get_headers).request
	return request
    def login(self):
        params = {
            "Email": self.email,
            "Passwd": self.password,
            "service": self.LOGIN_SERVICE,
            "accountType": self.LOGIN_TYPE
        }

        data = http_request(self.LOGIN_PAGE, params)

        response = str(data.decode('UTF-8'))

        if "Error" in response:
            raise Exception("Invalid login credentials.")

        for line in response.split("\n"):
            if "Auth=" in line:
                self.token = line.split("=")[1]

        if self.token is None:
            raise Exception("Unexpected response.")
Exemple #8
0
    def login(self):
        params = {
            "Email": self.email,
            "Passwd": self.password,
            "service": self.LOGIN_SERVICE,
            "accountType": self.LOGIN_TYPE
        }

        data = http_request(self.LOGIN_PAGE, params)

        response = str(data.decode('UTF-8'))

        if "Error" in response:
            raise Exception("Invalid login credentials.")

        for line in response.split("\n"):
            if "Auth=" in line:
                self.token = line.split("=")[1]

        if self.token is None:
            raise Exception("Unexpected response.")
Exemple #9
0
def run(file_name, sheet_name, c1, c2):  #修改全局变量 行根据id走的  c1,c2写入结果和判断结果
    global Token  #在这里声明  函数外的Token和函数内的Token是同一个值   必须要声明一下
    all_case = read_data(file_name, sheet_name)  # 获取到所有的测试数据
    print("获取到的所有数据是:", all_case)
    for test_data in all_case:  # 长度为4  这个意思是每一行的数据依次传过来,所以第一次传test_data[0]的值是1
        # 在http_request进行请求的时候,判断是否是登录请求
        # print('test_data[6]的值是,',test_data[6])
        # if test_data[0] == 1: #他就是一个登录的用例  获取到登录的,就可以获取到token值
        # if test_data[1] == '登录': #判断两把是否相等  比较运算符
        ip = "http://120.78.128.25:8766"  #先进行请求  #Token最初始值是NOne
        #test_data[4] 就是获取Excel表格中第5列的URL地址,每循环一次执行下一行
        response = http_request(ip + test_data[4],
                                eval(test_data[5]),
                                token=Token,
                                method=test_data[3])
        if 'login' in test_data[4]:  #成员运算符
            Token = "Bearer " + response['data']['token_info'][
                'token']  # 获取登录token
        print("最后的结果值:{}".format(response))

        #开始写入结果
        write_data(file_name, sheet_name, test_data[0] + 1, c1, str(response))

        actual = {
            'code': response['code'],
            'msg': response['msg']
        }  #实际结果 result
        if test_data[
                6] == actual:  #test_data[6]指的是期望结果与实际结果是否相等  test_data[6]为expected          write_data('test_data.xlsx', 'recharge', test_data[0] + 1,9, str(response)
            print('测试用例执行通过')
            #写入数据  一步步定位Excel表、表单、行列
            write_data(file_name, sheet_name, test_data[0] + 1, c2,
                       'PASS')  #test_data[0] + 1就是获取它的id,从第二行开始
        else:
            print('测试用例执行不通过')
            write_data(file_name, sheet_name, test_data[0] + 1, c2, 'FAIL')
Exemple #10
0
 def __init__(self):
     self.http = http_request()
     self.has_cookie = False
     self.addr = None
     self.domain = None
 def __init__(self, cookie = config.NEXUSCOOKIE, nexus_url = config.NEXUS_URL, nexus_page_url = config.NEXUS_PAGE_URL,  nexus_download_url = config.NEXUS_DOWNLOAD_URL):
     self.http = http_request(cookie)
     self.nexus_url = nexus_url
     self.nexus_page_url = nexus_url + nexus_page_url
     self.nexus_download_url = nexus_url + nexus_download_url
     self.current_page = 0
Exemple #12
0
 def __init__(self):
     self.http = http_request()
     self.torrents = None
     self.sign = None
     self.time = None
     self.uid = 0
 def __init__(self):
     self.http = http_request()
     self.has_cookie = False
     self.addr = None
     self.domain = None
 def __init__(self):
     self.http = http_request()
     self.torrents = None
     self.sign = None
     self.time = None
     self.uid = 0
 def __init__(self):
     self.current_page = 0
     self.http = http_request()
Exemple #16
0
IP = "http://120.78.128.25:8766"

#http请求头信息
headers = {
    "X-Lemonban-Media-Type": "lemonban.v2",
    "Content-Type": "application/json;charset=UTF-8"
}

#开始测试注册的用例
file_name = 'test_case.xlsx'
register_sheet = 'register'
for test_case in register_test_cases:
    test_result = {}
    print("**------------目前正在测试{}模块的第{}条用例,用例标题为:{}------------**".format(
        test_case[1], test_case[0], test_case[2]))
    result = http_request(test_case[3], IP + test_case[4], eval(test_case[5]),
                          headers)
    # print("测试结果是:{}".format(result))
    test_result['code'] = result['code']
    test_result['msg'] = result['msg']
    #判断结果是否通过
    if test_result == eval(test_case[6]):
        print("期望与实际结果一致,测试通过!")
        write_data(file_name, register_sheet, test_case[0] + 1, 8,
                   str(test_result))
        write_data(file_name, register_sheet, test_case[0] + 1, 9, '测试通过')
    else:
        print("期望与实际结果不一致,测试不通过!")
        write_data(file_name, register_sheet, test_case[0] + 1, 8,
                   str(test_result))
        write_data(file_name, register_sheet, test_case[0] + 1, 9, '测试不通过')
    print("")
 def __init__(self):
     self.current_page = 0
     self.http = http_request()
Exemple #18
0
 def __init__(self):
     self.http = http_request()
Exemple #19
0
 def __init__(self):
     self.http = http_request()