import unittest import requests from utils.tools import readexcle, createreport, Db db = Db("192.168.50.11", 3312, "root", "szgr123", "gre_study") datalist = readexcle("./data/个人中心接口测试用例.xlsx", "Cases") host = "http://192.168.50.11" class TestExam(unittest.TestCase): @classmethod def setUpClass(cls): cls.requests = requests.Session() url = "http://test.geron-e.com:8095/api/app/login" headers = eval(datalist[0][4]) values = eval(datalist[0][5]) res = cls.requests.post(url, headers=headers, data=values) resl = res.json() cls.token = resl.get("data") print(resl.get("data")) @classmethod def tearDownClass(cls): print("测试结束!") def test_01_getBaseInfo(self): """个人中心接口测试""" url = host + datalist[1][2] headers = eval(datalist[1][4]) headers.update(sessionId=self.token) res = requests.get(url, headers=headers)
import unittest from utils.tools import readexcle,createreport import requests from config import host,exclename,sheetname datalist = readexcle(exclename,sheetname) class TestLogin(unittest.TestCase): def test_01_login(self): """登录接口测试用例""" url = host + datalist[0][2] headers = eval(datalist[0][4]) data = eval(datalist[0][5]) yuqi = int(datalist[0][6]) res = requests.post(url,headers=headers,json=data) # 断言 shiji = res.json()["status"] self.assertEqual(yuqi,shiji) def test_02_inspirernew(self): """登录接口测试用例""" url = host + datalist[1][2] headers = eval(datalist[1][4]) data = eval(datalist[1][5]) yuqi = int(datalist[1][6]) res = requests.post(url,headers=headers,json=data) # 断言 shiji = res.json()["status"]