本文整理匯總了Python中webtest_plus.TestApp.post方法的典型用法代碼示例。如果您正苦於以下問題:Python TestApp.post方法的具體用法?Python TestApp.post怎麽用?Python TestApp.post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webtest_plus.TestApp
的用法示例。
在下文中一共展示了TestApp.post方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestTestApp
# 需要導入模塊: from webtest_plus import TestApp [as 別名]
# 或者: from webtest_plus.TestApp import post [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_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)
示例2: TestTestApp
# 需要導入模塊: from webtest_plus import TestApp [as 別名]
# 或者: from webtest_plus.TestApp import post [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_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/")