Python接口测试-模块引用与映射
生活随笔
收集整理的這篇文章主要介紹了
Python接口测试-模块引用与映射
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
PyCharm中發(fā)現(xiàn)模塊引用老是有各種問題
可以用映射來解決,例如需要調(diào)用登錄模塊里面的東西的時,可以這樣處理:
登錄模塊:1-login.py
import this import requests import json import unittest import HTMLTestRunneryuming='http://test-a.==.cn''''登錄''' s=requests.session() def login(phone):headers54 = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8','Accept': 'application/json, text/javascript, */*; q=0.01','Referer': '{0}/systLogonUser/login.do'.format(yuming)}url54='{0}/systLogonUser/adminLogon.do'.format(yuming)data54 ={'userName':phone,'pwd':'123456Aa','verifyCode':121}r=s.post(url=url54,data=data54,headers=headers54)login_response=r.textlogin_statuscode=r.status_codeprint(login_statuscode, login_response, s)return login_statuscode,login_response,slogin(18200717108)在后面的一個接口中進(jìn)行調(diào)用:
'''用戶登錄狀態(tài)
這里用到了登錄接口中的yuming、s
''' print('*'*100,'\n','/personal/bala','\n','*'*100) url='{0}/personal/bala?_=1556108604971'.format(f.yuming) r=f.s.get(url=url,headers=headers11) print(r.status_code) print(r.text)
未登錄與登錄后返回的結(jié)果不同:
****************************************************************************************************/personal/bala **************************************************************************************************** 200 {"time":"20760719022042","code":"105","msg":"未登錄"} **************************************************************************************************** /personal/bala **************************************************************************************************** 200 {"time":"20760719022042","accountBala":"8210100.80","usableBala":"7543000.80","frozenBala":"667100.00","code":"0","msg":"OK"} Process finished with exit code 0
?
轉(zhuǎn)載于:https://www.cnblogs.com/jpr-ok/p/10818921.html
總結(jié)
以上是生活随笔為你收集整理的Python接口测试-模块引用与映射的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在冬天使用一汽丰田电动车,为了更好地保护
- 下一篇: 面包车发动机多少钱 了解面包车发动机价格