def test_01_login_success(): # 登录成功的测试用例 data_res = read_excel( "data/测谈网测试用例.xlsx", "登录") # 调取read_excel的方法,读取数据,data/测谈网测试用例.xlsx为文件的相对路径,登录为页面的名字 url = data_res[0][2] # 读取上行取出来的值中的用例名称 data = eval(data_res[0][4]) # 读取出来的值中的参数,读出来的数据是字符串,所以用eval强转为字典 header = eval(data_res[0][5]) #读取出来的值中的请求头,用eval强转为字典 res = requests.post(url=url, json=data, headers=header) # print(res.text) #可以打印查询到内容 assert res.status_code == 200 assert res.json()["status"] == 200 # pytest -s可以打印断言结果 # 测试用例(方法的结果):. 成功 F:失败了(代码报错,断言失败) # 数据库校验 # 直接调用query方法 sql = "select * from t_user where username = '******'".format(data["username"]) assert len(query(sql)) != 0 # 保存最后一次登录的token # 先取出token token传参 token = res.json()["data"]["token"] save_file(token=token)
def test_03_getcomments(): """ 查看评论列表成功 """ u = get_url(data[2][2]) h = eval(data[2][5]) d = eval(data[2][4]) res = requests.post(url=u, headers=h, json=d) assert res.status_code == data[2][6] assert res.json()["status"] == data[2][7] save_file(file_path='./conf/comment_id.txt', content=str(res.json()["data"]["contentlist"][0]['id']))
def test_02_login_success(): data = read_excel("data\测谈网测试用例.xlsx", "登录") u = data[0][2] d = eval(data[0][4]) h = eval(data[0][5]) res = requests.post(url=u, json=d, headers=h) print(res.json()) assert res.status_code == 200 assert res.json()["status"] == int(data[0][6]) #数据库检验 sql = "select * from t_user where username = '******'".format(d["username"]) assert query(sql) != 0 save_file(token=res.json()["data"]["token"])
def test_01_login_success(): u = "http://118.24.105.78:2333/login" h = {"Content-Type": "application/json"} d = {"username": "******", "password": "******"} res = requests.post(url=u, headers=h, json=d) assert res.status_code == 200 assert res.json()["status"] == 200 # 第三步数据查询 sql = "select * from t_user where username='******'".format(d["username"]) assert len(query(sql)) != 0 # 保存token save_file(content=res.json()["data"]["token"])
def test_00_login_success(): url = "http://118.24.105.78:2333/login" data = {"username":"******","password":"******"} h = {"Content-Type":"application/json"} res = requests.post(url=url,json=data,headers=h) print(res.text) assert res.status_code == 200 assert res.json()["status"] == 200 sql = "select * from t_user where username = '******'" assert len(query(sql)) !=0 token = res.json()["data"]["token"] save_file(token=token)
def test_02_login_success(): u = get_url(data[0][2]) h = eval(data[0][5]) d = eval(data[0][4]) res = requests.post(url=u, headers=h, json=d) assert res.status_code == data[0][6] assert res.json()["status"] == data[0][7] print(res.text) # 数据库查询 sql = "select * from t_user where username ='******'".format(d["username"]) assert len(query(sql)) != 0 save_file(file_path='./conf/user_token.txt', content=res.json()["data"]["token"]) save_file(file_path='./conf/user_uid.txt', content=str(res.json()["data"]["userinfo"]["uid"]))
def test_06_new_comment(): """ 添加评论 """ u = get_url(data[5][2]) h = eval(data[5][5]) d = eval(data[5][4]) res = requests.post(url=u, headers=h, json=d) assert res.status_code == data[5][6] assert res.json()["status"] == data[5][7] print(res.text) sql = "select * from t_user_comments where uid = 1333416969 and fid = 13824 ORDER BY createtime desc limit 1;" # sql = "select * from t_user_comments where uid = '{}' and fid = '{}'".format(read_file(file_path ='./conf/user_uid.txt'),read_file(file_path ='./conf/question_id.txt') my_comment_id = query(sql)[0][0] print(my_comment_id) assert len(query(sql)) != 0 save_file(file_path='./conf/my_comment_id.txt', content=str(my_comment_id))
def test_02_login_sussess(): # 登陆成功的测试用例 data_res = read_excel("data\测谈网测试用例.xlsx", "登陆") url = data_res[0][2] # 根据excel直接读取 data = eval(data_res[0][4]) # eval是读取字典内容 header = eval(data_res[0][5]) res = requests.post(url=url, json=data, headers=header) print(res.text) # 状态码和结果码成功的断言 assert res.status_code == 200 assert res.json()['status'] == int(data_res[0][6]) # 数据库的校验 sql = "select * from t_user where username = '******'".format(data["username"]) assert len(query(sql)) != 0 # 保存最后一次登陆的 token值 token = res.json()["data"]["token"] save_file(token=token)