使用课程得测试框架,这里就不能使用上个接口返回得token还得重新调用上个方法,得到返回得token,就知道给下面第一个接口使用了
import mysql
import mysql.connector
#发送验证码
import requests
class TestMo:
_mobile=13762629090
_password="a123123"
def test_code(self):
url="http://*****-h5.dev.hypercode.me/api/user/login/mobile/pwd/check/send"
payload={
"areaCode": "86",
"mobile": self._mobile,
"password": self._password,
"useType": "LOGIN"
}
headers={
"client":"android"
}
r=requests.post(url=url,json=payload,headers=headers)
print(r.json())
# assert r.json()["data"] in '通知发送成功'
print(r.text)
@classmethod
def code(self):
config={
"host":"*********",
"port":"3306",
"user":'admin',
"password":"*********",
"database":"****"
}
con=mysql.connector.connect(**config)
cursor = con.cursor()
sql="select * from captcha_send_record where send_mobile ={} or send_email ={} order by create_time desc limit 1;".format(self._mobile,self._mobile)
cursor.execute(sql)
for one in cursor:
Code=one[4]
print(Code)
return Code
con.close()
@classmethod
def setup_token(self):
# print("测试验证码", self.code())
url = "http://*****-h5.dev.hypercode.me/api/user/login"
payload = {
"areaCode": "86",
"captchaCode": self.code(),
"clientType": "android",
"mobile": self._mobile,
"password": self._password
}
headers = {
"client": "android"
}
y = requests.post(url=url, json=payload, headers=headers)
print(y.text)
token = y.json()["data"]["access_token"]
print(token,"获取得token")
return token
def test_Home(self):
# print("token测试",self.setup_token())
token=self.setup_token()
url="http://*****-h5.dev.hypercode.me/api/content/coinPrice"
headers={"Authorization":token,
"client": "android"
}
m=requests.get(url=url,headers=headers)
print(m.json())
r=m.json()["data"]["list"][1]["symbol"]
print(r)
return token
def test_info(self):
url="http://*****-h5.dev.hypercode.me/api/user/quereyUserInfo"
headers={
"Authorization": self.setup_token(),
"client": "android"
}
y=requests.post(url=url,headers=headers)
print(y.text)