本文整理匯總了Python中webtest_plus.TestApp.authenticate方法的典型用法代碼示例。如果您正苦於以下問題:Python TestApp.authenticate方法的具體用法?Python TestApp.authenticate怎麽用?Python TestApp.authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webtest_plus.TestApp
的用法示例。
在下文中一共展示了TestApp.authenticate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestAuthViews
# 需要導入模塊: from webtest_plus import TestApp [as 別名]
# 或者: from webtest_plus.TestApp import authenticate [as 別名]
class TestAuthViews(OsfTestCase):
def setUp(self):
self.app = TestApp(app)
self.user = AuthUserFactory()
self.app.authenticate(*self.user.auth)
def test_mendeley_oauth_start(self):
self.user.add_addon('mendeley')
settings = self.user.get_addon('mendeley')
settings.access_token = '12345abc'
print settings.has_auth
settings.save()
# assert_true(settings.has_auth)
url = views.mendeley_oauth_start(self)
print url
def test_mendeley_oauth_delete_user(self):
pass
def test_mendeley_oauth_delete_node(self):
pass
def test_mendeley_oauth_callback(self):
pass
示例2: TestMenbibAuthViews
# 需要導入模塊: from webtest_plus import TestApp [as 別名]
# 或者: from webtest_plus.TestApp import authenticate [as 別名]
class TestMenbibAuthViews(OsfTestCase):
def setUp(self):
self.app = TestApp(app)
self.user = AuthUserFactory()
self.app.authenticate(*self.user.auth)
def test_menbib_oauth_start(self):
url = api_url_for('menbib_oauth_start_user')
res = self.app.get(url)
assert_is_redirect(res)
@mock.patch('website.addons.menbib.views.auth.finish_auth')
def test_menbib_oauth_finish(self, mock_finish):
mock_finish.return_value = AuthResult('mytokenabc', 'myrefreshabc', 'cool', '3600')
url = api_url_for('menbib_oauth_finish')
res = self.app.get(url)
assert_is_redirect(res)
def test_menbib_oauth_delete_user(self):
self.user.add_addon('menbib')
user_settings = self.user.get_addon('menbib')
user_settings.access_token = '12345abc'
assert_true(user_settings.has_auth)
self.user.save()
url = api_url_for('menbib_oauth_delete_user')
res = self.app.delete(url)
user_settings.reload()
assert_false(user_settings.has_auth)
示例3: TestTestApp
# 需要導入模塊: from webtest_plus import TestApp [as 別名]
# 或者: from webtest_plus.TestApp import authenticate [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)
示例4: TestTestApp
# 需要導入模塊: from webtest_plus import TestApp [as 別名]
# 或者: from webtest_plus.TestApp import authenticate [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/")