def test_01_getcomment_success_type2(res, url, head, body): sqlcount = "SELECT count(*) FROM t_user_comments c \ join t_user u on c.uid=u.id \ WHERE ctype = {} \ AND fid = {} \ AND c.STATUS = 0 \ ORDER BY c.updatetime \ DESC LIMIT {},10;".format(body["ctype"], body["fid"], 10 * (int(body["pagenum"]) - 1)) num = db.query(sqlcount)[0][0] assert num == res.json()["data"]["counts"] #判断数据量是否相等 assert len(res.json()["data"]["contentlist"]) == 10 or len( res.json()["data"]["contentlist"]) == num #判断每页数量是否为10,小于10是否为数据库中总数 assert res.status_code == 200 assert res.json()["status"] == 200 sql = "SELECT comment FROM t_user_comments c \ join t_user u on c.uid=u.id \ WHERE ctype = {} \ AND fid = {} \ AND c.STATUS = 0 \ ORDER BY c.updatetime \ DESC LIMIT {},10;".format(body["ctype"], body["fid"], 10 * (int(body["pagenum"]) - 1)) numle = num % 10 #第一页第几个,如果总数大于10,取余数,总数小于10,取本身 assert num == 0 or db.query(sql)[numle - 1][0] == res.json( )["data"]["contentlist"][numle - 1]["comment"] #查到的最后一个元素是否相同 return res
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_01_gettagelist_success_tag3(res, url, head): assert res.json()["status"] == 200 #状态码 assert res.status_code == 200 #结果码 sql = "select count(*) from (SELECT tags FROM t_content_tags\ WHERE ctype = {} AND STATUS = 0\ GROUP BY tags) a;".format(url[-1]) assert len(res.json()["data"]["tags"].split(",")) == db.query(sql)[0][0] return res
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_03_deletequestion(): r = read_excel('data\\测谈网接口测试用例.xlsx','Sheet1') u = r[18][2] d = eval(r[18][3]) #字符串转换成字典 h = eval(r[18][4]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[18][6] assert res.json()['status'] == r[18][7] sql = 'select * from t_article where id="{}"'.format(read_file('./conf/user_qid.txt')) assert len(query(sql)) == 0
def test_01_mb(): r = read_excel('data\\测谈网接口测试用例.xlsx', 'Sheet1') u = r[15][2] d = eval(r[15][3]) #字符串转换成字典 h = eval(r[15][4]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[15][6] assert res.json()['status'] == r[15][7] sql = "select mb from t_user where username = '******'" assert len(query(sql)) != 0
def test_02_updatearticle(): r = read_excel('data\\测谈网接口测试用例.xlsx', 'Sheet1') u = r[5][2] d = eval(r[5][3]) h = eval(r[5][4]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[5][6] assert res.json()['status'] == r[5][7] sql = 'select * from t_article where id="{}" and title="{}"'.format( read_file('./conf/user_articleid.txt'), d['title']) assert len(query(sql)) != 0
def test_05_comment_update(): # 修改评论 u = datas[4][2] h = eval(datas[4][3]) d = eval(datas[4][4]) res = requests.post(url=u,headers=h,json=d) assert res.status_code == datas[4][5] assert res.json()['status'] == datas[4][6] sql = "select * from t_user_comments where id={} and comment='{}'".format(read_file('./tmp/inspirer_comment_id.txt'),d['comment']) assert len(query(sql)) != 0
def test_06_comment_delete(): # 删除评论 u = datas[5][2] h = eval(datas[5][3]) d = eval(datas[5][4]) res = requests.post(url=u,headers=h,json=d) assert res.status_code == datas[5][5] assert res.json()['status'] == datas[5][6] sql = "select * from t_user_comments where id={} and status='1'".format(read_file('./tmp/question_comment_id.txt')) assert len(query(sql)) != 0
def test_03_comment_new(): # 新建评论 u = datas[2][2] h = eval(datas[2][3]) d = eval(datas[2][4]) res = requests.post(url=u,headers=h,json=d) assert res.status_code == datas[2][5] assert res.json()['status'] == datas[2][6] sql = "select * from t_user_comments where ctype='{}' and comment='{}' and fid={}".format(d['ctype'],d['comment'],d['fid']) assert len(query(sql)) != 0
def test_03_deletearticle(): r = read_excel('data\\测谈网接口测试用例.xlsx', 'Sheet1') u = r[6][2] d = eval(r[6][3]) h = eval(r[6][4]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[6][6] assert res.json()['status'] == r[6][7] sql = 'select status from t_article where id="{}"'.format( read_file('./conf/user_articleid.txt')) assert query(sql)[0] == ('1', )
def test_05_userfuser(): # 用户关注用户 u = datas[4][2] h = eval(datas[4][3]) res = requests.get(url=u, headers=h) # print(res.text) assert res.status_code == datas[4][5] assert res.json()['status'] == datas[4][6] sql = "select * from t_user_follows where fid=322 and status=0" assert len(query(sql)) != 0
def test_01_update_userinfo(): # 修改个人资料 u = datas[0][2] h = eval(datas[0][3]) d = eval(datas[0][4]) res = requests.post(url=u,headers=h,json=d) print(res.text) assert res.status_code == datas[0][5] assert res.json()['status'] == datas[0][6] sql = "select * from t_user where nickname='{}' and phone='{}' and sex='{}' and email='{}'".format(d['nickname'],d['phone'],d['sex'],d['email']) assert len(query(sql)) !=0
def test_02_login_filed(): #request请求代码 url=d[1][2] data=eval(d[1][4]) res = requests.post(url=url,json=data) assert res.status_code ==d[1][6] assert res.json()["status"]==d[1][7] #sql验证 sql="select * from tb_user where username='******' and password = '******'".format(data['username'],data['password']) assert len(query(sql)) ==0
def test_01_xgtx(): r = read_excel('data\\测谈网接口测试用例.xlsx', 'Sheet1') u = r[3][2] h = eval(r[3][4]) d = eval(r[3][3]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[3][6] assert res.json()['status'] == r[3][7] sql = 'select * from t_user where username ="******" and headpic ="{}"'.format( 'huang255k', d['ximg']) assert len(query(sql)) != 0
def test_03_user_fell(): # 收藏 u = datas[2][2] h = eval(datas[2][3]) d = eval(datas[2][4]) res = requests.post(url=u,headers=h,json=d) print(res.text) assert res.status_code == datas[2][5] assert res.json()['status'] == datas[2][6] sql = "select * from t_questions_user_status where qid={} and cstatus={}".format(d['cid'],0) assert len(query(sql)) != 0
def test_04_get_user_status(): #查看用户对于文章/灵感/问题等的关注、收藏、点赞的状态 u = datas[3][2] h = eval(datas[3][3]) d = eval(datas[3][4]) res = requests.post(url=u,headers=h,json=d) print(res.text) assert res.status_code == datas[3][5] assert res.json()['status'] == datas[3][6] sql ="select * from t_questions_user_status where qid={} and gstatus={} and cstatus={}".format(d['fid'],res.json()['data'][0]['gstatus'],res.json()['data'][0]['cstatus']) assert len(query(sql)) != 0
def test_01_new_article(): """ 新建文件case """ 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] aid = res.json()["data"]["articleid"] sql = "select * from t_article where id = {}".format(aid) assert len(query(sql)) != 0
def test_01_fblg(): url = "http://118.24.105.78:2333/inspirer/new" data = {"content": "内容", "ximg": "dsfsdf.jpg"} header = {"Content-Type": "application/json", "token": read_file()} res = requests.post(url=url, json=data, headers=header) print(res.text) assert res.status_code == 200 assert res.json()["status"] == 200 # 数据库查询 id = res.json()["data"]["inspirerid"] sql = "select * from t_inspirer where id={}".format(id) assert len(query(sql)) == 1
def test_01_login_success(): # 登录成功 u = datas[0][2] h = eval(datas[0][3]) d = eval(datas[0][4]) 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)) write_file('./tmp/token.txt', 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_01_newquestion(): r = read_excel('data\\测谈网接口测试用例.xlsx','Sheet1') u = r[16][2] d = eval(r[16][3]) #字符串转换成字典 h = eval(r[16][4]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[16][6] assert res.json()['status'] == r[16][7] qid = res.json()['data']['questionid'] write_file('./conf/user_qid.txt', str(qid)) sql = "select * from t_questions where id = '{}'".format(read_file('./conf/user_qid.txt')) assert len(query(sql)) != 0
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_01_new_aritcle(): """ 新建文章case """ u = "http://118.24.105.78:2333/article/new" h = {"Content-Type":"application/json","token":read_file()} d = {"title":"为什么要学习测试","content":"内容","tags":"测试123","brief":"介绍","ximg":"dsfsdf.jpg"} res = requests.post(url=u, headers=h, json=d) assert res.status_code == 200 assert res.json()["status"] == 200 print(res.text) # 数据库查询 aid = res.json()["data"]["articleid"] sql = "select * from t_article where id = {}".format(aid) assert len(query(sql)) != 0
def test_01_inspirer_new(): # 新建灵感 u = datas[0][2] h = eval(datas[0][3]) d = eval(datas[0][4]) res = requests.post(url=u,headers=h,json=d) assert res.status_code == datas[0][5] assert res.json()['status'] == datas[0][6] #print(res.text) sql = "select * from t_inspirer where id={} and content='{}'".format(res.json()['data']['inspirerid'],d['content']) assert len(query(sql)) != 0 write_file('./tmp/inspirerid.txt',res.json()['data']['inspirerid'])
def test_01_login(): r = read_excel('data\\测谈网接口测试用例.xlsx', 'Sheet1') u = r[2][2] d = eval(r[2][3]) #字符串转换成字典 h = eval(r[2][4]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[2][6] assert res.json()['status'] == r[2][7] #数据库查询 sql = "select * from t_user where username = '******'".format(d['username']) assert len(query(sql)) != 0 token = res.json()['data']['token'] write_file('./conf/user_token.txt', token)
def test_01_newarticle(): r = read_excel('data\\测谈网接口测试用例.xlsx', 'Sheet1') u = r[4][2] d = eval(r[4][3]) h = eval(r[4][4]) res = requests.post(url=u, json=d, headers=h) assert res.status_code == r[4][6] assert res.json()['status'] == r[4][7] articleid = res.json()['data']['articleid'] write_file('./conf/user_articleid.txt', str(articleid)) sql = 'select * from t_article where id="{}"'.format( read_file('./conf/user_articleid.txt')) assert len(query(sql)) != 0
def test_01_fblg(): # 构造请求 url = 'http://118.24.105.78:2333/inspirer/new' data = {"content": "内ssss容", "ximg": "dsfsdf.jpg"} h1 = {"Content-Type": "application/json", "token": read_file()} res = requests.post(url=url, json=data, headers=h1) print(res.text) # 断言 assert res.status_code == 200 assert res.json()['status'] == 200 # 数据库查询 inspirerid = res.json()['data']['inspirerid'] sql = "select * from t_inspirer where id={}".format(inspirerid) assert len(query(sql)) == 1
def test_01_login(): u = "http://192.144.148.91:2333/login" h = {"Content-Type": "application/json"} d = {"username": "******", "password": "******"} res = requests.post(url=u, json=d, headers=h) #断言结果 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 #tooken保存 token = res.json()["data"]["token"] write_file("user_token.txt", token)
def test_01_new_question(): # 新建问题 u = datas[0][2] h = eval(datas[0][3]) d = eval(datas[0][4]) res = requests.post(url=u, headers=h, json=d) assert res.status_code == datas[0][5] assert res.json()['status'] == datas[0][6] write_file('./tmp/questionid.txt', res.json()['data']['questionid']) questionid = read_file('./tmp/questionid.txt') sql = "select * from t_questions where id={} and title='{}' and content='{}' and tags='{}' and brief='{}' and ximg='{}'".format( questionid, d['title'], d['content'], d['tags'], d['brief'], d['ximg']) assert len(query(sql)) != 0