Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83788

Testing unauthorized pages with zope test browser

What's the correct 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 :)

Upvotes: 2

Views: 210

Answers (2)

Ross Patterson
Ross Patterson

Reputation: 5742

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

Upvotes: 3

ggozad
ggozad

Reputation: 13105

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)

Upvotes: 3

Related Questions