TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
自己封装的请求
- 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
|
|