zoukankan      html  css  js  c++  java
  • Python接口测试-模块引用与映射

    PyCharm中发现模块引用老是有各种问题

    可以用映射来解决,例如需要调用登录模块里面的东西的时,可以这样处理:

    登录模块:1-login.py

    import this
    import requests
    import json
    import unittest
    import HTMLTestRunner
    
    
    yuming='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.text
        login_statuscode=r.status_code
        print(login_statuscode, login_response, s)
        return login_statuscode,login_response,s
    
    login(18200717108)

    在后面的一个接口中进行调用:

    ''' 
    用户登录状态
    这里用到了登录接口中的yuming、s
    ''' print('*'*100,' ','/personal/bala',' ','*'*100) url='{0}/personal/bala?_=1556108604971'.format(f.yuming) r=f.s.get(url=url,headers=headers11) print(r.status_code) print(r.text)

    未登录与登录后返回的结果不同:

    ****************************************************************************************************
    /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
  • 相关阅读:
    MySQL中TIMESTAMP和DATETIME区别
    图片标签的alt与title区别
    DEDE自带的采集功能,标题太短的解决方法
    Modernizr——为HTML5和CSS3而生!
    InnoDB,MyISAM,Memory区别
    Innodb,MyIsam,聚集索引和非聚集索引
    聚集索引与非聚集索引的总结
    程序kill -9与kill -15的区别,以及回调函数的作用
    linux 信号 SIGINT SIGTERM SIGKILL区别
    oracle mysql sqlserver 查看当前所有数据库及数据库基本操作命令
  • 原文地址:https://www.cnblogs.com/jpr-ok/p/10818921.html
Copyright © 2011-2022 走看看