def test_good_list(): # url = "http://211.103.136.242:8064/categories/115/skus" #---使用配置文件的url了 #定义测试数据 url_y = ConfigYaml() url_path = url_y.get_conf_url() url = url_path + "/categories/115/skus" data = {"page": "1", "page_size": "10", "ordering": "create_time"} # r = requests.get(url,json=data) r = requeests_get(url, json=data) from utils.RequestsUtil import request request = request() r = request.get(url, json=data) # print(r.json()) print(r) code = r["code"] # print("-----test",code) AssertUtil().assert_code(code, 200) # body = r["body"] # print("-------test------",body) # AssertUtil().assert_in_body(body, 'count:14') #初始化数据对象 conn = init_db("db_1") #查询结果 res_db = conn.fetchone("select * from roles") print("数据库查询结果:%s" % res_db)
def test_login(): # 3、定义测试数据 conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/authorizations/" # url = "http://211.103.136.242:8064/authorizations/" data = {"username": "******", "password": "******"} # 4、发送POST请求 # r = requests.post(url,json=data) # r = requests_post(url,json=data) request = Request() r = request.post(url, json=data) # 5、输出结果 # print(r.json()) print(r) # 返回状态码 code = r['code'] AssertUtil().assert_code(code, 200) body = r['body'] # print(body) AssertUtil().assert_in_body(body, '"username": "******"') # 1、初始化数据库对象 conn = init_db('db_1') # 2、查询结果 res_db = conn.fetchone("select id from tb_users where username='******'") print("数据库查询结果:", res_db) # 3、验证 user_id = body['user_id'] assert user_id == res_db['id']
def test_login(): #3、定义测试数据 conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/authorizations/" #url = "http://211.103.136.242:8064/authorizations/" data = {"username": "******", "password": "******"} #4、发送POST请求 #r = requests.post(url,json=data) #r = requests_post(url,json=data) request = Request() r = request.post(url, json=data) #5、输出结果 #print(r.json()) print(r) #验证 #返回状态码 code = r["code"] #assert code == 200 AssertUtil().assert_code(code, 200) #返回结果内容 #body = json.dumps(r["body"]) body = r["body"] #assert '"user_id": 1, "username": "******"' in body AssertUtil().assert_in_body(body, '"user_id": 1, "username": "******"') #1、初始化数据库对象 conn = init_db("db_1") #2、查询结果 res_db = conn.fetchone( "select id,username from tb_users where username='******'") print("数据库查询结果", res_db) #3、验证 user_id = body["user_id"] assert user_id == res_db["id"]
def test_login(): # 3. 定义测试数据 url = ConfigYaml().get_conf_url() + "/authorizations/" # url = "http://211.103.136.242:8064/authorizations/" json_data = {"username": "******", "password": "******"} # 4. 发送post请求 # r = requests.post(url, json=json_data) # 调用封装的post方法 # res = requests_post(url, json=json_data) # 调用Requests重构的post方法 request = Request() res = request.post(url, json=json_data) # 5. 输出结果 # print(r.json()) print(res) # 验证 # 返回状态码 code = res["code"] # assert code == 201 AssertUtil().assert_code(code, 200) # 返回结果内容 # body = json.dumps(res["body"]) body = res["body"] # assert '"user_id": 1, "username": "******"' in body AssertUtil().assert_in_body(body, '"user_id": 1, "username": "******"') # 1.初始化数据库对象 conn = init_db("db_1") # 2.查询结果 res_db = conn.fetchone( "select id, username from tb_users where username = '******'") print("数据库查询结果", res_db) # 3. 验证结果 user_id = body["user_id"] assert user_id == res_db["id"]
def test_login(): """ 登录 """ conn = init_db('db_1') res_db = conn.fetch_one('select id from tb_user where username="******"') print(f"数据库查询数据:{res_db}") url = 'http://211.103.136.242:8064/authorizations/' data = {'username': '******', 'password': '******'} r = r_post(url, json=data) print(r) '''
def test_01(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=DeleteReportInfo" data = {"Inputs": "{ID:1}"} requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'ErrorCode': 0, 'Success': True, 'ExceptionMsg': '删除成功!'") print(body) conn = init_db("db_1") conn.execute("truncate table TB_IMS_REPORTFORMS")
def test_Login(): # 3、定义测试数据 conf_y = ConfigYaml() #加载config.Conf文件中的ConfigYaml类 url_path = conf_y.get_conf_url() # 读取配置文件中的url url = url_path + "/authorizations/" # 拼接url+登录参数 # url = "http://211.103.136.242:8064/authorizations/" data = {"username": "******", "password": "******"} # 4、发送Post请求 # r = requests_post(url,json = data) r = request.post(url, json=data) # 5、输出结果 # print(json.dumps(r,sort_keys=True,ensure_ascii = False,indent=4,separators=(', ', ': '))) #Json格式打印 #验证返回状态码 code = r["code"] # assert code == 200 #调用assert封装函数 AssertUtil().assert_code(code, 200) #验证返回结果内容 # body = json.dumps(r["body"]) # assert '"user_id": 1, "username": "******"' in body body = r["body"] # print(body) # AssertUtil().assert_in_body(body,'"user_id": 1') AssertUtil().assert_in_body(body, '"username": "******"') print( "***************************************************************************************************" ) #数据库断言 #1、初始化数据库对象 conn = init_db("db_1") #2、查询结果 res_db = conn.fetchone( "select id,username from tb_users where username = '******'") print("数据库查询结果:", res_db) #3、数据库断言 user_id = body["user_id"] assert user_id == res_db["id"] # 6、返回token result_token = r['body']['token'] # print(result_token) return result_token
import os import pytest from common import Base from config import Conf from common.Base import init_db if __name__ == '__main__': report_path = Conf.get_report_path() + os.sep + "result" report_html_path = Conf.get_report_path() + os.sep + "html" pytest.main(["-s", "--alluredir", report_path]) # 执行SQL还原数据 conn = init_db("db_1") conn.execute("truncate table TB_IMS_REPORTFORMS ") conn.execute("truncate table TB_IMS_FORMULA") # Base.allure_report(report_path, report_html_path) # Base.SendEmail()