本文为霍格沃兹测试开发学社学员学习笔记分享
原文链接:https://ceshiren.com/t/topic/28000
cookie
token
auth
oauth2(选修)
cookie 的获取(根据接口文档获取)
发送携带 cookie 的请求
Session()
对象class TestWithSession:
proxy = {"http": "http://127.0.0.1:8888", "https": "https://127.0.0.1:8888"}
req = requests.Session()
def setup_class(self):
url = "http://train-manage.atstudy.com/login"
data = {"username": "199****9999", "password": "a1***56"}
resp = self.req.request("post", url, data=data, proxies=self.proxy)
print(self.req.headers)
def test_get_userinfo(self):
url = "http://train-manage.atstudy.com/api/manage/User/Info"
resp = self.req.request("get", url, proxies=self.proxy)
print(resp.text)
def test_manage_tag(self):
url = "http://train-manage.atstudy.com/api/manage/Tag?type=1"
resp = self.req.request("get", url, proxies=self.proxy)
print(resp.text)
class TestWithToken:
proxy = {"http": "http://127.0.0.1:8888", "https": "http://127.0.0.1:8888"}
headers = {}
def setup_class(self):
token = self.login().json()["data"]["token"]
print(token)
self.headers["x-litemall-admin-token"] = token
@classmethod
def login(cls):
url = "https://litemall.hogwarts.ceshiren.com/admin/auth/login"
data = {"username": "hogwarts", "password": "test12345", "code": ""}
resp = requests.request("post", url, json=data, proxies=cls.proxy, verify=False)
return resp
def test_get_dashboard(self):
url = "https://litemall.hogwarts.ceshiren.com/admin/dashboard"
resp = requests.request("get", url, headers=self.headers, proxies=self.proxy, verify=False)
print(resp.text)
# print(1)
def test_category_list(self):
url = "https://litemall.hogwarts.ceshiren.com/admin/category/list"
resp = requests.request("get", url, headers=self.headers, proxies=self.proxy, verify=False)
print(resp.text)