WebTest的扩展,具有有用的附加功能,包括请求式身份验证。

webtest-plus的Python项目详细描述


https://badge.fury.io/py/webtest-plus.pnghttps://travis-ci.org/sloria/webtest-plus.png?branch=master

带有有用附加功能的WebTest的扩展,包括requests样式的身份验证。

安装

$ pip install -U webtest-plus

用法

importunittestfrommyappimportappfromwebtest_plusimportTestAppclassTestMyApp(unittest.TestCase):defsetUp(self):self.app=TestApp(app)deftest_protected_endpoint(self):response=self.app.get("/secret/",expect_errors=True)assertresponse.status_code==401# Requests-style authenticationresponse=self.app.get("/secret/",auth=("admin","passw0rd"))assertresponse.status_code==200deftest_more_secrets(self):# Another way to authenticateself.app.authenticate(username="admin",password="passw0rd")assertself.app.get("/secret/").status_code==200self.app.deauthenticate()assertself.app.get("/secret/",expect_errors=True).status_code==401deftest_posting_json(self):# Testing json requests and responsesresponse=self.app.post_json("/postsecret/",{"secret":"myprecious"},auth=("admin","passw0rd"))assertresponse.request.content_type=="application/json"deftest_clicking(self):response=self.app.get("/")response=response.click("Protected link",auth=("admin","passw0rd"))assertresponse.status_code==200deftest_token_auth(self):response=self.app.get('/secret-requires-token/',expect_errors=True)assertresponse.status_code==401# Authenticate with JWTresponse=self.app.get('/secret-requires-token',auth='yourlongtokenhere',auth_type='jwt')assertresponse.status_code==200

功能

  • 基本HTTP身份验证
  • JSON Web Token身份验证
  • 自动跟踪重定向
  • 框架不可知

要求

  • Python>;=2.6或>;=3.3

许可证

麻省理工学院许可有关详细信息,请参阅捆绑的LICENSE文件。

变更日志

1.0.0(2017-05-17)

  • 修复使用auth(#3)时对utf编码值的处理多谢@biern的帮忙
  • 放弃对Python2.6的支持。
  • 测试Python3.6。

0.3.3(2015-03-17)

  • 实现TestApp.head

0.3.2(2014-06-04)

  • 导致UnboundLocalError的错误修复

0.3.1(2014-05-31)

  • 修复Python2上的字符串编码错误。

0.3.0(2014-05-31)

  • 添加对JSON web令牌身份验证的支持

0.2.1(2013-11-24)

  • 将身份验证添加到TestResponse.clickTestResponse.clickbutton

0.2.0(2013-10-15)

  • 添加对JSON方法的支持(例如app.post_json等)

0.1.0(2013-10-06)

  • 第一次释放。
  • HTTP基本身份验证正在工作

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
生成的代码为什么在无人机中使用Java是不安全的?   java实体继承和鉴别器列   java使用Struts 2中sj:datepicker的beforeShow事件   JavaMaven没有安装pom文件中的所有内容,导致“缺少必需的库”x124   java将自定义GIF从assets文件夹加载到recyclerview 安卓中   java实现稀疏数组   java在获得所需结果集后关闭连接对象   java在活动中将数组值添加到MClickListener()   java如何删除单元格工厂引用   java字符串。分号分隔   Java抽象和接口   java Intellij IDEA SLF4J:未能加载类“org.SLF4J.impl.StaticLoggerBinder”   java改造JsonArray recyclerview异常   JavaJUnit@Theory:有没有方法抛出有意义的异常?   如何在Java中将XML内容写入字符串?