天天看點

關鍵字封裝-斷言結果

提示:關鍵字封裝-斷言結果

#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')