WebTest的扩展,具有有用的附加功能,包括请求式身份验证。
webtest-plus的Python项目详细描述
带有有用附加功能的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.click和TestResponse.clickbutton
0.2.0(2013-10-15)
- 添加对JSON方法的支持(例如app.post_json等)
0.1.0(2013-10-06)
- 第一次释放。
- HTTP基本身份验证正在工作