python接口测试,获取响应文本中的token并传入下一方法

业务流程:忘记密码时,提交答案验证获取token,使用token更新密码
首先调用submit_answer方法,回答正确的密保答案后获取token,定义dic空字典变量,获取返回的响应文本,dic字典内容为:{‘status’: 0, ‘data’: ‘0cddd1d4-c4a5-4645-b59b-d1e62fde7ec5’}
将dic字典data值赋给self.token,供下一方法update_password使用self.token

    def submit_answer(self):
        url = "http://192.168.0.5:8080/jwshoplogin/user/forget_check_answer.do"
        submit_answer_data = {
            "username":"李超",
            "question":"问题1",
            "answer":"答案1"
        }
        response = requests.post(url,data = submit_answer_data)
        #print(response.text)
        msg = response.text.find("data")
        if msg > 0:
            print("提交密保答案接口测试成功")
        else:
            print("提交密保答案接口测试失败")
        #定义一个空字典变量
        dic = {}
        dic = eval(response.text)
        #根据字典key值data获取它的value
        self.token = dic["data"]
        print(self.token)
    def update_password(self):
        url = "http://192.168.0.5:8080/jwshoplogin/user/forget_reset_password.do"
        update_password_data = {
            "username":"李超",
            "passwordNew":"123123",
            "forgetToken":str(self.token)
        }

你可能感兴趣的:(接口测试)