import json import requests # 1 创建class # 2 将所有的def 函数 缩进放进类中 # 3 在方法的括号中假如self # 4 分析代码 将重复的部分 剥离出来 比入 获取token # 5 管理 url header 简化代码 # 6 写注释 class TestCrmeb: __header = {"Content-Type": "application/json;charset=UTF-8"} __url = "http://139.159.233.129:8899/adminapi/" def __init__(self): r = requests.request("post", self.__url + "login", headers=self.__header, json={"account": "admin", "pwd": "123456", "imgcode": "q"}) self.token = r.json().get("data").get("token") def test_list(self, limit): """查看订单列表""" r = requests.request("get", self.__url + "order/list", headers={**self.__header, "Authori-zation": "Bearer " + self.token}, params={"page": 1, "limit": limit}) print(json.dumps(r.json(), indent=2, ensure_ascii=False)) assert r.status_code == 200 assert r.json().get("msg") == "ok" def test_coupon(self): pass def xxx(self): pass if __name__ == '__main__': cb = TestCrmeb() cb.test_list(10)
11-26
391
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)