def test_handle_errors_false_redirect(self): self.folder._setObject('redirect', RedirectStub()) browser = Browser() browser.handleErrors = False with self.assertRaises(NotFound): browser.open('http://localhost/test_folder_1_/redirect') self.assertTrue(browser.contents is None)
def test_handle_errors_false(self): self.folder._setObject('stub', ExceptionStub()) browser = Browser() browser.handleErrors = False # Even errors which can be handled by Zope go to the client: with self.assertRaises(NotFound): browser.open('http://localhost/nothing-is-here') self.assertTrue(browser.contents is None)
def test_handle_errors_false(self): self.folder._setObject('stub', ExceptionStub()) browser = Browser() browser.handleErrors = False with self.assertRaises(ValueError): browser.open('http://localhost/test_folder_1_/stub') self.assertTrue(browser.contents is None) with self.assertRaises(NotFound): browser.open('http://localhost/nothing-is-here') self.assertTrue(browser.contents is None)
def test_handle_errors_false(self): self.folder._setObject('stub', ExceptionStub()) browser = Browser() browser.handleErrors = False # Custom exceptions get through with self.assertRaises(ValueError): browser.open('http://localhost/test_folder_1_/stub') self.assertTrue(browser.contents is None) # HTTPException subclasses are handled with self.assertRaises(HTTPError): browser.open('http://localhost/nothing-is-here') self.assertTrue(browser.headers['status'].startswith('404'))
def test_handle_errors_false_HTTPExceptionHandler_in_app(self): """HTTPExceptionHandler does not handle errors if requested via WSGI. This is needed when HTTPExceptionHandler is part of the WSGI pipeline. """ class WSGITestAppWithHTTPExceptionHandler(object): """Minimized testbrowser.WSGITestApp with HTTPExceptionHandler.""" def __call__(self, environ, start_response): publish = HTTPExceptionHandler(publish_module) wsgi_result = publish(environ, start_response) return wsgi_result self.folder._setObject('stub', ExceptionStub()) transaction.commit() browser = Browser(wsgi_app=WSGITestAppWithHTTPExceptionHandler()) browser.handleErrors = False with self.assertRaises(ValueError): browser.open('http://localhost/test_folder_1_/stub') self.assertIsNone(browser.contents)
def testSkinSwitchUsingFallbackForm(self): self.loginAsPortalOwner() folder_url = self.folder.absolute_url() portal_url = self.portal.absolute_url() # Add a second folder: self.portal.invokeFactory('Folder', id='folder2') folder2 = self.portal.folder2 wf_tool = getToolByName(self.portal, 'portal_workflow') wf_tool.doActionFor(folder2, 'publish') folder2_url = folder2.absolute_url() # Add a sub folder: folder2.invokeFactory('Folder', id='sub_folder') sub_folder = folder2.sub_folder wf_tool.doActionFor(sub_folder, 'publish') sub_folder_url = sub_folder.absolute_url() # Create a new default skin. new_default_skin(self.portal) # Set the default skin for the first folder. browser = Browser() browser.handleErrors = False self._login(browser) browser.open(folder_url + "/select_skin") control = browser.getControl(name="skin_name") self.assertEqual([], control.value) control.value = ["Monty Python Skin"] # Saving the form redirects back to the folder. browser.getControl(name="form.button.Save").click() self.assertEqual(folder_url, browser.url) # Going back to the form has the skin selected. browser.open(folder_url + "/select_skin") control = browser.getControl(name="skin_name") self.assertEqual(["Monty Python Skin"], control.value) # Set the default skin for the second folder. We have to do # this as portal owner. self._login(browser, login_name=ptc.portal_owner) browser.open(folder2_url + "/select_skin") control = browser.getControl(name="skin_name") self.assertEqual([], control.value) control.value = ["Sunburst Theme"] browser.getControl(name="form.button.Save").click() browser.open(folder2_url + "/select_skin") control = browser.getControl(name="skin_name") self.assertEqual(["Sunburst Theme"], control.value) # Set a different default skin for the sub folder. browser.open(sub_folder_url + "/select_skin") control = browser.getControl(name="skin_name") self.assertEqual([], control.value) control.value = ["Monty Python Skin"] browser.getControl(name="form.button.Save").click() browser.open(sub_folder_url + "/select_skin") control = browser.getControl(name="skin_name") self.assertEqual(["Monty Python Skin"], control.value) # What is the current skin name in a few contexts? self._login(browser) browser.open(portal_url + '/getCurrentSkinName') self.assertEqual(browser.contents, 'Monty Python Skin') browser.open(folder_url + '/getCurrentSkinName') self.assertEqual(browser.contents, 'Monty Python Skin') browser.open(folder2_url + '/getCurrentSkinName') self.assertEqual(browser.contents, 'Sunburst Theme') browser.open(sub_folder_url + '/getCurrentSkinName') self.assertEqual(browser.contents, 'Monty Python Skin') # Check the effect this has when visiting these contexts. We # do this with an almost empty browser view that shows a # viewlet that is specifically registered for the Monty Python # theme and not the Sunburst Theme theme. Plus a viewlet that # shows which marker interfaces the request provides. # First the portal root: browser.open(portal_url + '/@@viewlet-test') self.assertTrue('We want a shrubbery!' in browser.contents) self.assertTrue('interfaces.IMyTheme' in browser.contents) # Then the first folder: browser.open(folder_url + '/@@viewlet-test') self.assertTrue('We want a shrubbery!' in browser.contents) self.assertTrue('interfaces.IMyTheme' in browser.contents) # Then the second folder: browser.open(folder2_url + '/@@viewlet-test') self.assertFalse('We want a shrubbery!' in browser.contents) self.assertFalse('interfaces.IMyTheme' in browser.contents) # Then the sub folder: browser.open(sub_folder_url + '/@@viewlet-test') self.assertTrue('We want a shrubbery!' in browser.contents) self.assertTrue('interfaces.IMyTheme' in browser.contents)