当前位置: 首页>>代码示例>>Python>>正文


Python TestApp.head方法代码示例

本文整理汇总了Python中webtest_plus.TestApp.head方法的典型用法代码示例。如果您正苦于以下问题:Python TestApp.head方法的具体用法?Python TestApp.head怎么用?Python TestApp.head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webtest_plus.TestApp的用法示例。


在下文中一共展示了TestApp.head方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestTestApp

# 需要导入模块: from webtest_plus import TestApp [as 别名]
# 或者: from webtest_plus.TestApp import head [as 别名]
class TestTestApp(unittest.TestCase):

    def setUp(self):
        self.app = TestApp(app)
        self.auth = ("admin", "secret")

    def test_auth_get(self):
        res = self.app.get("/foo/bar/", auth=self.auth)
        assert_equal(res.status_code, 200)

    def test_bad_auth_get(self):
        # /foo/bar/ requires HTTP basic auth
        res = self.app.get("/foo/bar/", expect_errors=True)
        assert_equal(res.status_code, 401)
        bad_auth = ("no", "go")
        res = self.app.get("/foo/bar/", auth=bad_auth, expect_errors=True)
        assert_equal(res.status_code, 401)

    def test_auth_post(self):
        res = self.app.post("/foo/bar/baz/", auth=self.auth)
        assert_equal(res.status_code, 200)

    def test_auth_head(self):
        res = self.app.head("/foo/bar/baz/", auth=self.auth)
        assert_equal(res.status_code, 200)

    def test_auto_follow(self):
        res = self.app.get("/redirect/", auto_follow=True)
        assert_equal(res.status_code, 200)

    def test_authorize(self):
        self.app.authenticate(username='admin', password='secret')
        res = self.app.get("/foo/bar/")
        assert_equal(res.status_code, 200)
        self.app.deauthenticate()
        res = self.app.get("/foo/bar/", expect_errors=True)
        assert_equal(res.status_code, 401)

    def test_auth_put(self):
        assert_equal(self.app.put("/foo/bar/baz/", expect_errors=True).status_code,
                    401)
        assert_equal(self.app.put("/foo/bar/baz/", auth=self.auth).status_code, 200)

    def test_auth_patch(self):
        assert_equal(self.app.patch("/foo/bar/baz/", expect_errors=True).status_code,
                    401)
        assert_equal(self.app.patch("/foo/bar/baz/", auth=self.auth).status_code, 200)

    def test_auth_options(self):
        assert_equal(self.app.options("/foo/bar/baz/", expect_errors=True).status_code,
                    401)
        assert_equal(self.app.options("/foo/bar/baz/", auth=self.auth).status_code, 200)

    def test_auth_delete(self):
        assert_equal(self.app.delete("/foo/bar/baz/", expect_errors=True).status_code,
                    401)
        assert_equal(self.app.delete("/foo/bar/baz/", auth=self.auth).status_code, 200)

    def test_auth_post_json(self):
        assert_equal(self.app.post_json("/secretjson/", {"name": "Steve"},
                    expect_errors=True).status_code, 401)
        res = self.app.post_json("/secretjson/", {"name": "Steve"}, auth=self.auth)
        assert_equal(res.request.content_type, "application/json")
        assert_equal(res.status_code, 200)

    def test_click_with_auth(self):
        res = self.app.get("/")
        assert_raises(AppError, lambda: res.click("Bar"))
        res = self.app.get("/")
        res = res.click("Bar", auth=self.auth)
        assert_equal(res.status_code, 200)

    def test_click_with_authenticate(self):
        self.app.authenticate(username=self.auth[0], password=self.auth[1])
        res = self.app.get('/')
        res = res.click("Bar")
        assert_equal(res.status_code, 200)

    def test_clickbutton_with_auth(self):
        res = self.app.get("/")
        assert_raises(AppError, lambda: res.clickbutton("Click me"))
        res = self.app.get('/')
        res = res.clickbutton("Click me", auth=self.auth)

    def test_clickbutton_with_authenticate(self):
        self.app.authenticate(username=self.auth[0], password=self.auth[1])
        res = self.app.get('/')
        res = res.clickbutton("Click me")
        assert_equal(res.status_code, 200)
        assert_equal(res.request.path, "/foo/bar/")

    def test_auth_with_token(self):
        assert_equal(self.app.post('/requires_token/', expect_errors=True).status_code, 401)
        res = self.app.post('/requires_token/', auth='mytoken', auth_type='jwt')
        assert_equal(res.status_code, 200)

    def test_authenticate_with_token(self):
        self.app.authenticate_with_token('mytoken')
        res = self.app.post('/requires_token/')
        assert_equal(res.status_code, 200)
#.........这里部分代码省略.........
开发者ID:sloria,项目名称:webtest-plus,代码行数:103,代码来源:test_webtest_plus.py


注:本文中的webtest_plus.TestApp.head方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。