python接口测试如何关联_Unittest+Python接口自动化测试进行token关联

import json

import requests

from common.operation_json import OperetionJson

class OperationHeader:

def __init__(self, response):

self.response = json.loads(response)

def get_response_token(self):

'''

获取登录返回的token

'''

token = {"data":{"token":self.response['data']['token']}}

#token = {"token": self.response['data']['token']}

return token

# 把数据写入文件

def write_token(self):

op_json = OperetionJson()

op_json.write_data(self.get_response_token())

def get_response_msg(self):

reponse_msg = {"msg":self.response['msg']}

#print("reponse_msg:", reponse_msg)

return reponse_msg

if __name__ == '__main__':

# 一个登录接口数据,仅供参考

url = "http://192.168.1.117/api/user/login"

data = {

"username": "zhang",

"password": "123456",

"deviceId": 0

}

res = requests.post(url,data).json()

res1 = json.dumps(res)

print(type(res1))

op = OperationHeader(res1)

print(op.get_response_msg())

你可能感兴趣的:(python接口测试如何关联)