开发者

Testing unauthorized pages with zope test browser

开发者 https://www.devze.com 2023-03-31 22:22 出处:网络
What\'s the corre开发者_运维问答ct procedure to check in the functional test case whether or not the page is accessible by the currently logged in user?

What's the corre开发者_运维问答ct procedure to check in the functional test case whether or not the page is accessible by the currently logged in user?

Please point a working example :)


To check if the page IS accessible is easy. You typically do

browser.open(url)

and check for something in browser.contents.

To make sure the page is inaccessible and for instance raises, you could import HTTPError

from urllib2 import HTTPError

obtain a browser instance, login with it, and do

self.assertRaises(HTTPError, browser.open, url)


>>> browser.handleErrors = False
>>> browser.open(unauthorized_url)
Traceback (most recent call last):
Unauthorized: ...
0

精彩评论

暂无评论...
验证码 换一张
取 消