开发者

Testing unauthorized pages with zope test browser

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜