def assert_in(asserqiwang,fanhuijson):
if len(asserqiwang.split('=')) > 1:
data = asserqiwang.split('&')
result = dict([(item.split('=')) for item in data])
value1=([(int(fanhuijson[key])) for key in result.keys()])
value2=([(int(value)) for value in result.values()])
if value1==value2:
return 'pass'
else:
return 'fail'
else:
raise ('请填写期望值')
class reques():
def __init__(self):
self.headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:51.0) Gecko/20100101 Firefox/51.0"}
def get(self, url):#get消息
try:
r = requests.get(url, headers=self.headers)
r.encoding = 'UTF-8'
json_response = json.loads(r.text)
return json_response
except Exception as e:
print('get请求出错,出错原因:%s'%e)
return {}
def post(self, url, params):#post消息
data = json.dumps(params)
try:
r =requests.post(url,params=params,headers=self.headers)
json_response = json.loads(r.text)
return json_response
except Exception as e:
print('post请求出错,原因:%s'%e)
def delfile(self,url,params):#删除的请求
try:
del_word=requests.delete(url,params,headers=self.headers)
json_response=json.loads(del_word.text)
return json_response
except Exception as e:
print('del请求出错,原因:%s' % e)
return {}
def putfile(self,url,params):#put请求
try:
data=json.dumps(params)
me=requests.put(url,data)
json_response=json.loads(me.text)
return json_response
except Exception as e:
print('put请求出错,原因:%s'%e)
return json_response
class TestApi(object):
def __init__(self,url,key,connent,fangshi):
self.url=url
self.key=key
self.connent=connent
self.fangshi=fangshi
def testapi(self):
global response
if self.fangshi=='POST':
self.parem = {'key': self.key, 'info': self.connent}
response=reques.post(self.url,self.parem)
elif self.fangshi=="GET":
self.parem = {'key': self.key, 'info': self.connent}
response = reques.post(self.url, self.parem)
return response
def getcode(self):
code=self.testapi()['code']
return code
def getJson(self):
json_data = self.testapi()
return json_data