天天看点

关键字封装-断言结果

提示:关键字封装-断言结果

#encoding=utf-8

from util.get_log import *    


def assert_result(response, key_word): 
    try:
        assert key_word in response.text   #判断返回值是否包含断言关键字        
        return True
    except AssertionError as e:        
        return False
 



if __name__ =='__main__':
    import requests
    import json
   ''' 
   下面的url,head及接口参数需要换成自己的地址和请求头及接口参数
   '''
    url = "http://192.178.11.118:8084/login/lupu/pc"

    head = {"Content-Type": "application/json;charset=UTF-8",
            "Authorization": "Bearer 6ebfaa1e-03c5-416c-8842-8d0cb1830676"}

    data = json.dumps({"username": "auto001", "password": '111111', "client": "WW_PC", "secret": "secret_WW_2020"})
    response = requests.post(url=url, data=data, headers=head)
    print(response.text)
    asd = (str(response.json()))
    assert_result(response,'token')