跳转到主要内容

WebTest的扩展,包含有用的额外功能,包括requests风格的认证。

项目描述

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

WebTest的扩展,包含有用的额外功能,包括requests风格的认证。

安装

$ pip install -U webtest-plus

用法

import unittest
from myapp import app
from webtest_plus import TestApp

class TestMyApp(unittest.TestCase):

    def setUp(self):
        self.app = TestApp(app)

    def test_protected_endpoint(self):
        response = self.app.get("/secret/", expect_errors=True)
        assert response.status_code == 401
        # Requests-style authentication
        response = self.app.get("/secret/", auth=("admin", "passw0rd"))
        assert response.status_code == 200

    def test_more_secrets(self):
        # Another way to authenticate
        self.app.authenticate(username="admin", password="passw0rd")
        assert self.app.get("/secret/").status_code == 200
        self.app.deauthenticate()
        assert self.app.get("/secret/", expect_errors=True).status_code == 401

    def test_posting_json(self):
        # Testing json requests and responses
        response = self.app.post_json("/postsecret/", {"secret": "myprecious"},
                                        auth=("admin", "passw0rd"))
        assert response.request.content_type == "application/json"

    def test_clicking(self):
        response = self.app.get("/")
        response = response.click("Protected link", auth=("admin", "passw0rd"))
        assert response.status_code == 200

    def test_token_auth(self):
        response = self.app.get('/secret-requires-token/', expect_errors=True)
        assert response.status_code == 401

        # Authenticate with JWT
        response = self.app.get('/secret-requires-token',
            auth='yourlongtokenhere', auth_type='jwt')
        assert response.status_code == 200

功能

  • 基本HTTP认证

  • JSON Web Token认证

  • 自动跟随重定向

  • 框架无关

需求

  • Python >= 2.6 或 >= 3.3

许可证

MIT许可。有关更多详细信息,请参阅捆绑的LICENSE文件。

变更日志

1.0.0 (2017-05-17)

  • 修复使用auth时处理utf编码值的处理 (#3)。感谢@biern的捕捉和补丁。

  • 放弃对Python 2.6的支持。

  • 针对Python 3.6进行测试。

0.3.3 (2015-03-17)

  • 实现TestApp.head

0.3.2 (2014-06-04)

  • 修复导致未绑定局部错误的bug。

0.3.1 (2014-05-31)

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

0.3.0 (2014-05-31)

  • 添加对JSON Web Token认证的支持。

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基本认证正常工作。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定该选择哪个,请了解有关安装包的更多信息。

源代码分布

webtest-plus-1.0.0.tar.gz (8.9 kB 查看哈希值)

上传时间 源代码

构建分布

webtest_plus-1.0.0-py2.py3-none-any.whl (9.8 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下提供支持