关于python+request+unittest的问题
自己封装的请求def getJwtHeaders(as_user="cc",id = "id",secret = "secret"):
token = {
"exp": int(time.mktime(datetime.datetime.now().timetuple())) + 30,
"nbf": int(time.mktime(datetime.datetime.now().timetuple())),
"sub": id,
"aud":as_user,
}
jwt_token = jwt.encode(token,secret, algorithm="HS256")
return {
"Authorization": "JWT " + jwt_token,
}
"""封装graphql_query"""
class gqeury(token):
def query(self,query,operationName,variables):
self.query_path = os.path.join(dir_path,"gql/{}".format(query))
with open(self.query_path,"r") as f :
self.query = f.read()
self.data = {
"operationName":operationName,
"variables":variables,
"query":self.query
}
self.res = requests.post(url=self.url,json = self.data,headers=getJwtHeaders())
resp = self.res.json()
return resp
gqeury = gqeury()测试case:
@ddt
class check_Me(unittest.TestCase):
@data(*datas)
def test_meinfo(self,case):
getJwtHeaders(case)
# gqeury.getJwtHeaders()
self.r = gqeury.query(operationName=None, query="me.gql", variables={})
self.assertEqual("shuang.yu",self.r["data"]["me"]["username"],msg="验证失败")执行用例只有第一次会成功,其余的都会失败
报错信息:(check_Me.test_meinfo_3_lu_liang)
self = <test_me.check_Me testMethod=test_meinfo_3_lu_liang>, case = 'lu.liang'
@data(*datas)
def test_meinfo(self,case):
getJwtHeaders(case)
# gqeury.getJwtHeaders()self.r = gqeury.query(operationName=None, query="me.gql", variables={})
E TypeError: 'str' object is not callable
检查下报文头 看发完第一次后哪些改变了 执行一次后测试条件改变了 执行一次后测试条件改变了
页:
[1]