def getBrowser(self, url, user=USER_A_ID, streaming=False): """Create a browser, optionally with auth details in headers""" import plone.testing._z2_testbrowser if streaming: old_getresponse = plone.testing._z2_testbrowser.Zope2Connection.getresponse def newgetresponse(self): if self.response.body == '': # Read stdout, and plonk data from there into body so rest will pick it up self.response.stdout.seek(0) out = self.response.stdout.read() self.response.body = out.split("\r\n\r\n")[-1] return old_getresponse(self) plone.testing._z2_testbrowser.Zope2Connection.getresponse = newgetresponse browser = Browser(self.layer['app']) if user: browser.addHeader('Authorization', 'Basic %s:%s' % ( user, 'secret' + user[0], )) if url: browser.open(url) return browser
class AutoCSRFProtectTests(unittest.TestCase, _BaseAutoTest): def setUp(self): self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.request = self.layer['request'] login(self.portal, TEST_USER_NAME) self.browser.open(self.portal.absolute_url() + '/login_form') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() def open(self, path): self.browser.open(self.portal.absolute_url() + '/' + path) def test_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = createToken() view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), True) def test_incorrect_CSRF_header(self): self.request.environ['HTTP_X_CSRF_TOKEN'] = 'foobar' view = AuthenticatorView(None, self.request) self.assertEqual(view.verify(), False) def test_only_add_auth_when_user_logged_in(self): logout() self.open('logout') self.open('test-unprotected') try: self.browser.getForm('one').getControl(name="_authenticator") self.assertEqual('anonymous should not be protected', '') except LookupError: pass
class TestAngularJsPortletNavigationFunctional(unittest.TestCase): layer = PLONE_APP_ANGULARJS_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer["app"] self.portal = self.layer["portal"] self.request = self.layer["request"] from plone.testing.z2 import Browser from plone.app.testing import SITE_OWNER_NAME from plone.app.testing import SITE_OWNER_PASSWORD self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader("Authorization", "Basic %s:%s" % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)) def test_api_navigation_nested(self): self.portal.invokeFactory("Folder", "news", title="News") self.portal.news.invokeFactory("Folder", "news1", title="News 1") import transaction transaction.commit() self.browser.open(self.portal_url + "/++api++v1/portlet_navigation?path=/news/news1") output = json.loads(self.browser.contents) self.assertEqual(output[0]["id"], u"news") self.assertEqual(output[0]["children"][0]["id"], u"news1")
class DocumentFunctionalTest(unittest.TestCase): layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ['Manager']) fti = DexterityFTI('leadimagedocument') self.portal.portal_types._setObject('leadimagedocument', fti) fti.klass = 'plone.dexterity.content.Item' fti.behaviors = ( 'plone.app.contenttypes.behaviors.leadimage.ILeadImage', ) self.fti = fti alsoProvides(self.portal.REQUEST, IPloneAppContenttypesLayer) alsoProvides(self.request, IPloneAppContenttypesLayer) from plone.app.contenttypes.behaviors.leadimage import ILeadImage alsoProvides(self.request, ILeadImage) self.portal.invokeFactory( 'leadimagedocument', id='leadimagedoc', title=u'Document with a lead image' ) import transaction transaction.commit() # Set up browser self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_lead_image_in_edit_form(self): self.browser.open(self.portal_url + '/leadimagedoc/edit') self.assertTrue('Lead Image' in self.browser.contents) self.assertTrue('Lead Image Caption' in self.browser.contents) def test_lead_image_viewlet_shows_up(self): self.browser.open(self.portal_url + '/leadimagedoc/edit') # Image upload file_path = os.path.join(os.path.dirname(__file__), "image.jpg") file_ctl = self.browser.getControl( name='form.widgets.ILeadImage.image' ) file_ctl.add_file(open(file_path), 'image/png', 'image.jpg') # Image caption self.browser.getControl( name='form.widgets.ILeadImage.image_caption' ).value = 'My image caption' # Submit form self.browser.getControl('Save').click() self.assertTrue('My image caption' in self.browser.contents) self.assertTrue('image.jpg' in self.browser.contents) self.assertTrue('<div class="leadImage">' in self.browser.contents)
def getBrowser(self, loggedIn=True): """ instantiate and return a testbrowser for convenience """ browser = Browser(self.layer['app']) if loggedIn: browser.addHeader('Authorization', 'Basic %s:%s' % ( TEST_USER_NAME, TEST_USER_PASSWORD)) return browser
class PortletsFunctionalTestCase(unittest.TestCase, Functional): """Base class for functional integration tests for plone.app.portlets. This may provide specific set-up and tear-down operations, or provide convenience methods. """ layer = PLONE_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.request = self.layer['request'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.browser = Browser(self.app) self.browser.handleErrors = True self.app.acl_users.userFolderAddUser('app', 'secret', ['Manager'], []) from plone.testing import z2 z2.login(self.app['acl_users'], 'app') import transaction transaction.commit() self.site_administrator_browser = Browser(self.app) self.site_administrator_browser.handleErrors = False self.site_administrator_browser.addHeader( 'Authorization', 'Basic %s:%s' % ('app', 'secret') )
def test_render_home_page(self): app = self.layer['app'] portal = self.layer['portal'] transaction.commit() browser = Browser(app) browser.open(portal.absolute_url()) self.assertTrue('<!-- Theme home.html -->' in browser.contents)
class FolderFunctionalTest(unittest.TestCase): layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_add_folder(self): self.browser.open(self.portal_url) self.browser.getLink(url='http://nohost/plone/++add++Folder').click() self.browser.getControl(name='form.widgets.IDublinCore.title')\ .value = "My folder" self.browser.getControl(name='form.widgets.IDublinCore.description')\ .value = "This is my folder." self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('my-folder/view')) self.assertTrue('My folder' in self.browser.contents) self.assertTrue('This is my folder' in self.browser.contents)
def prepare_for_acquisition_tests(self): """create content and an alternate authenticated browser session creates the following content structure: |-- f1 | |-- test |-- test """ # create a page at the root and one nested with the same id. p1 = self.portal.invokeFactory( type_name='Document', id='test', title='Test Page at Root') folder_1 = self.portal['f1'] p2 = folder_1.invokeFactory( type_name='Document', id='test', title='Test Page in Folder') contained_test_page = folder_1[p2] transaction.commit() # create an alternate browser also logged in with manager browser_2 = Browser(self.layer['app']) browser_2.handleErrors = False browser_2.addHeader( 'Authorization', 'Basic {0}:{1}'.format(TEST_USER_NAME, 'secret')) # return the id of the root page, the nested page itself, and the # alternate browser return p1, contained_test_page, browser_2
def test_tag_filtering(self): app = self.layer['app'] portal = self.layer['portal'] browser = Browser(app) browser.open(portal.test.absolute_url() + '/search') self.assertTrue('Test page title' in browser.contents) self.assertFalse('<h1 id="test-title">' in browser.contents)
class ReviewListTestCase(PloneTestCase): """dsfsdaf""" def afterSetUp(self): self.uf = self.portal.acl_users self.uf.userFolderAddUser('reviewer', 'secret', ['Reviewer'], []) transaction.commit() self.browser = Browser(self.layer['app']) self.wftool = getToolByName(self.portal, 'portal_workflow') def createDocument(self, id, title, description): self.setRoles(['Manager', ]) self.portal.invokeFactory(id=id, type_name='Document') doc = getattr(self.portal, id) doc.setTitle(title) doc.setDescription(description) # we don't want it in the navigation doc.setExcludeFromNav(True) doc.reindexObject() transaction.commit() return doc def submitToReview(self, obj): '''call the workflow action 'submit' for an object''' self.wftool.doActionFor(obj, 'submit') def test_unauthenticated(self): ''' unauthenticated users do not have the necessary permissions to view the review list ''' self.browser.open('http://nohost/plone/full_review_list') self.assertTrue('Login Name' in self.browser.contents) def test_authenticated(self): ''' unauthenticated users do not have the necessary permissions to view the review list ''' self.browser.addHeader('Authorization', 'Basic %s:%s' % ('reviewer', 'secret')) self.browser.open('http://nohost/plone/full_review_list') self.assertTrue('Full review list:' in self.browser.contents) def test_with_content(self): ''' unauthenticated users do not have the necessary permissions to view the review list ''' doc = self.createDocument( 'testdoc', 'Test Document', 'Test Description') self.wftool.doActionFor(doc, 'submit') transaction.commit() self.browser.addHeader('Authorization', 'Basic %s:%s' % ('reviewer', 'secret')) self.browser.open('http://nohost/plone/full_review_list') self.assertTrue('Full review list:' in self.browser.contents) # test if the table with review items contains an entry for testdoc self.assertTrue('value="/plone/testdoc"' in self.browser.contents)
def getBrowser(self, loggedIn=True): """ instantiate and return a testbrowser for convenience """ browser = Browser(self.layer['app']) if loggedIn: auth = 'Basic %s' % self.getCredentials() browser.addHeader('Authorization', auth) return browser
def test_tile_rendering(self): try: self.portal.invokeFactory('Folder', 'test-folder') except: self.portal.invokeFactory('Document', 'test-folder') self.folder = self.portal['test-folder'] self.folder.invokeFactory('Document', 'd1') d1 = self.folder.get('d1') d1.setTitle(u'New title') d1.text = RichTextValue(u"""\ <p> <img src="/++resource++collective.tinymcetiles.plugin/placeholder.gif" alt="./@@dummy.tile/tile-1" class="mceItem mceTile" /> </p> """, 'text/html', 'text/x-html-safe', 'utf-8') transaction.commit() browser = Browser(self.portal) browser.handleErrors = False browser.open(d1.absolute_url()) self.assertIn('Test tile rendered', browser.contents) self.assertIn('<p>With child tags</p>', browser.contents) self.assertIn('And tail text', browser.contents)
class RichTextBehaviorFunctionalTest(RichTextBase, unittest.TestCase): """ basic use cases and tests for richtext behavior""" layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING _behaviors = ( 'plone.app.contenttypes.behaviors.richtext.IRichText',) _portal_type = 'SomeDocument' def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.wf = getToolByName(self.portal, "portal_workflow") self.portal.acl_users._doAddUser('user_std', 'secret', ['Member'], []) self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ['Manager']) self._setupFTI() self.portal.invokeFactory(self._portal_type, 'doc1') setRoles(self.portal, TEST_USER_ID, ['Member']) import transaction transaction.commit() # Set up browser self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_richtext_in_edit_form(self): self.browser.open(self.portal_url + '/doc1/edit') self.assertTrue('mce_editable' in self.browser.contents) def test_richtext_behavior(self): IRichText.providedBy(self.portal.doc1)
def test_cache_without_GZIP(self): ploneSettings = getUtility(IRegistry).forInterface(IPloneCacheSettings) ploneSettings.enableCompression = False app = self.layer['app'] portal = self.layer['portal'] # Folder content setRoles(portal, TEST_USER_ID, ('Manager',)) portal.invokeFactory('Folder', 'f1') portal['f1'].setTitle(u"Folder one") portal['f1'].setDescription(u"Folder one description") portal['f1'].reindexObject() # Publish the folder portal.portal_workflow.doActionFor(portal['f1'], 'publish') import transaction transaction.commit() browser = Browser(app) browser.open(portal['f1'].absolute_url()) # Title - pulled in with rules.xml self.assertTrue(portal['f1'].Title() in browser.contents) # Elsewhere - not pulled in self.assertFalse("Accessibility" in browser.contents) # The theme self.assertTrue("This is the theme" in browser.contents)
def test_render_plone_page(self): app = self.layer['app'] portal = self.layer['portal'] transaction.commit() browser = Browser(app) browser.open(portal.absolute_url()) self.assertTrue('<div id="wrapper">' in browser.contents)
def test_collection_templates(self): data = getData('image.png') # add an image that will be listed by the collection self.portal.invokeFactory("Image", "image", title="Image example", image=data) # Search for images query = [{ 'i': 'Type', 'o': 'plone.app.querystring.operation.string.is', 'v': 'Image', }] # set the query and publish the collection self.collection.setQuery(query) commit() logout() # open a browser to see if our image is in the results browser = Browser(self.layer['app']) browser.handleErrors = False browser.open(self.collection.absolute_url()) self.assertTrue("Image example" in browser.contents) # open summary_view template browser.open('%s/summary_view' % self.collection.absolute_url()) self.assertTrue("Image example" in browser.contents) # open folder_summary_view template browser.open('%s/folder_summary_view' % self.collection.absolute_url()) self.assertTrue("Image example" in browser.contents) # open thumbnail_view template browser.open('%s/thumbnail_view' % self.collection.absolute_url()) self.assertTrue("Image example" in browser.contents)
def setUp(self): self.app = self.layer['app'] self.request = self.layer['request'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.browser = Browser(self.app) self.browser.handleErrors = False # we have to create a user on the zope root. this just does not work # with plone.app.testing and TEST_USER or SITE_OWNER self.app.acl_users.userFolderAddUser('app', 'secret', ['Manager'], []) from plone.testing import z2 z2.login(self.app['acl_users'], 'app') import transaction transaction.commit() self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ('app', 'secret') ) self.site_administrator_browser = Browser(self.app) self.site_administrator_browser.handleErrors = False self.site_administrator_browser.addHeader( 'Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,) )
class TestRequestAccess(unittest.TestCase): layer = PLONE_LOGIN_FUNCTIONAL_TESTING def setUp(self): # Make sure our browserlayer is applied alsoProvides(IPloneLoginLayer) self.browser = Browser(self.layer['app']) def test_insufficient_privileges_only_shows_access_button_when_site_can_send_email(self): # noqa mailhost = getUtility(IMailHost) self.assertEqual(mailhost.smtp_host, '') self.browser.open('http://nohost/plone/login') self.browser.getControl('Login Name').value = TEST_USER_NAME self.browser.getControl('Password').value = TEST_USER_PASSWORD self.browser.getControl('Log in').click() self.assertIn('You are now logged in', self.browser.contents) self.browser.open('http://nohost/plone/@@overview-controlpanel') self.assertIn('Insufficient Privileges', self.browser.contents) self.assertNotIn('Request Access', self.browser.contents) mailhost.smtp_host = 'localhost' setattr(self.layer['portal'], 'email_from_address', '*****@*****.**') transaction.commit() self.browser.open('http://nohost/plone/@@overview-controlpanel') self.assertIn('Insufficient Privileges', self.browser.contents) self.assertIn('Request Access', self.browser.contents)
class TestFunctional(FunctionalTestCase): """Full-blown browser tests for News Items.""" def setUp(self): """Custom shared utility setup for tests.""" self.portal = self.layer['portal'] self.browser = Browser(self.layer['app']) self.browser.handleErrors = False self.login() # login in self.browser so we can add content # this has been failing for a long time but we didn't catch it on Travis # moving on now, will come back to this at some later date @unittest.expectedFailure def test_image_is_required(self): """Try to add a News Item without an image.""" # go to add form self.browser.open('http://nohost/plone/createObject?type_name=News+Item') # fill in the title field (leave the rest empty) self.browser.getControl('Title').value = u"Test item" # click Save self.browser.getControl('Save').click() # check if `required` error is there self.assertRegexpMatches( self.browser.url, 'http://nohost/plone/portal_factory/News%20Item/news_item.[^/]+/atct_edit' ) self.assertIn( 'Image is required, please correct.', self.browser.contents )
class LinkFunctionalTest(unittest.TestCase): layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_add_link(self): self.browser.open(self.portal_url) self.browser.getLink('Link').click() self.assertTrue('Title' in self.browser.contents) self.assertTrue('Description' in self.browser.contents) self.assertTrue('Text' in self.browser.contents) self.browser.getControl(name='form.widgets.IDublinCore.title')\ .value = "My link" self.browser.getControl(name='form.widgets.IDublinCore.description')\ .value = "This is my link." self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('my-link/view')) self.assertTrue('My link' in self.browser.contents) self.assertTrue('This is my link' in self.browser.contents)
def test_absolutePrefix_enabled_path_vhosting(self): app = self.layer['app'] portal = self.layer['portal'] from Products.SiteAccess import VirtualHostMonster VirtualHostMonster.manage_addVirtualHostMonster(app, 'virtual_hosting') import transaction transaction.commit() self.settings.enabled = True self.settings.absolutePrefix = u'/foo' portalURL = portal.absolute_url() prefix = '/'.join(portalURL.split('/')[:-1]) suffix = portalURL.split('/')[-1] vhostURL = ( "{0:s}/VirtualHostBase/http/example.org:80/{1:s}/VirtualHostRoot" "/_vh_fizz/_vh_buzz/_vh_fizzbuzz/".format(prefix, suffix) ) import transaction transaction.commit() browser = Browser(app) browser.open(vhostURL) self.assertFalse('<img src="relative.jpg" />' in browser.contents) self.assertTrue( '<img src="/fizz/buzz/fizzbuzz/foo/relative.jpg" />' in browser.contents )
def test_theme_enabled_resource_directory(self): app = self.layer['app'] portal = self.layer['portal'] self.settings.enabled = True theme = getTheme('plone.app.theming.tests') applyTheme(theme) self.assertEqual(self.settings.rules, u'/++theme++plone.app.theming.tests/rules.xml') self.assertEqual(self.settings.currentTheme, u"plone.app.theming.tests") self.assertEqual(self.settings.doctype, u"<!DOCTYPE html>") import transaction; transaction.commit() browser = Browser(app) browser.open(portal.absolute_url()) # Title - pulled in with rules.xml self.assertTrue(portal.title in browser.contents) # Elsewhere - not pulled in self.assertFalse("Accessibility" in browser.contents) # The theme self.assertTrue("This is the theme" in browser.contents) # Doctype self.assertTrue(re.match("<!DOCTYPE html>\s+<html", browser.contents))
def test_uuid_view(self): from plone.uuid.interfaces import IUUID portal = self.layer['portal'] app = self.layer['app'] setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory('Document', 'd1') d1 = portal['d1'] uuid = IUUID(d1) import transaction transaction.commit() from plone.testing.z2 import Browser browser = Browser(app) browser.addHeader( 'Authorization', 'Basic {0}:{1}'.format(TEST_USER_ID, TEST_USER_PASSWORD, ) ) browser.open('{0}/@@uuid'.format(d1.absolute_url())) self.assertEqual(uuid, browser.contents)
def test_theme_different_path(self): app = self.layer['app'] portal = self.layer['portal'] setRoles(portal, TEST_USER_ID, ('Manager',)) portal.invokeFactory('Folder', 'news', title=u"News") setRoles(portal, TEST_USER_ID, ('Member',)) self.settings.enabled = True import transaction; transaction.commit() browser = Browser(app) browser.open(portal.absolute_url()) # Title - pulled in with rules.xml self.assertTrue(portal.title in browser.contents) # Elsewhere - not pulled in self.assertFalse("Accessibility" in browser.contents) # The theme self.assertTrue("This is the theme" in browser.contents) browser.open(portal['news'].absolute_url()) # Title - pulled in with rules.xml self.assertTrue("News" in browser.contents) # Elsewhere - not pulled in self.assertFalse("Accessibility" in browser.contents) # The theme self.assertTrue("This is the other theme" in browser.contents)
class TestInvitation(TestCase): layer = FTW_PARTICIPATION_FUNCTIONAL_TESTING def setUp(self): super(TestInvitation, self).setUp() self.portal = self.layer['portal'] self.portal_url = self.portal.portal_url() self.demo_folder = self.portal.get(self.portal.invokeFactory( 'Folder', 'demo-folder')) transaction.commit() self.browser = Browser(self.layer['app']) self.browser.handleErrors = False def test_userid_differ_userlogin(self): member = self.portal.portal_membership.getMemberById(TEST_USER_ID_2) member.setMemberProperties({'email':'*****@*****.**'}) inv1 = Invitation(target=self.demo_folder, email='*****@*****.**', inviter='admin', roles=['Reader']) url = '%s/@@invitations?iid=%s' % (self.portal_url, inv1.iid) transaction.commit() self.browser.addHeader('Authorization', 'Basic %s:%s' % ( TEST_USER_ID_2, TEST_USER_PW_2, )) self.browser.open(url) self.assertIn('Invitations', self.browser.contents)
def test_redirect_to_uuid_invalid_uuid(self): from mechanize import HTTPError portal = self.layer['portal'] app = self.layer['app'] setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory('Document', 'd1') portal.invokeFactory('Document', 'd2') import transaction transaction.commit() from plone.testing.z2 import Browser browser = Browser(app) browser.addHeader( 'Authorization', 'Basic {0}:{1}'.format(TEST_USER_ID, TEST_USER_PASSWORD, ) ) try: url = '{0}/@@redirect-to-uuid/gibberish' browser.open(url.format(portal.absolute_url())) self.fail('No error raised') except HTTPError, e: self.assertEqual(e.code, 404)
def test_theme_stored_in_plone_site(self): app = self.layer['app'] portal = self.layer['portal'] # We'll upload the theme files to the Plone site root rules_contents = open( os.path.join(os.path.split(__file__)[0], 'localrules.xml') ) theme_contents = open( os.path.join(os.path.split(__file__)[0], 'theme.html') ) portal.manage_addDTMLMethod('theme.html', file=theme_contents) portal.manage_addDTMLMethod('rules.xml', file=rules_contents) # These paths should be relative to the Plone site root self.settings.rules = u'/rules.xml' self.settings.enabled = True import transaction transaction.commit() browser = Browser(app) browser.open(portal.absolute_url()) # Title - pulled in with rules.xml self.assertTrue(portal.title in browser.contents) # Elsewhere - not pulled in self.assertFalse("Accessibility" in browser.contents) # The theme self.assertTrue("This is the theme" in browser.contents)
def test_navroot_params_on_404_widget_in_path(self): app = self.layer['app'] portal = self.layer['portal'] setRoles(portal, TEST_USER_ID, ['Contributor']) portal.invokeFactory('Folder', 'subfolder') self.settings.enabled = True self.settings.parameterExpressions = { 'navigation_root_id': 'python:portal_state.navigation_root().getId()' # noqa } transaction.commit() browser = Browser(app) browser.addHeader('Accept', 'text/html') error = None try: browser.open( '{0:s}/widget/oauth_login/info.txt'.format( portal['subfolder'].absolute_url() ) ) except HTTPError as e: error = e self.assertEqual(error.code, 404) self.assertTrue("This is the theme" in browser.contents)
def setUp(self): self.portal = self.layer['portal'] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ['Manager']) self.doc1 = api.content.create( container=self.portal, type='Document', title=u'Some Document', ) self.doc1.text = RichTextValue(u'One two', 'text/plain', 'text/html') self.browser = Browser(self.layer['app']) self.browser.handleErrors = False modified(self.doc1) self.statscache = getUtility(IHistoryStatsCache) self.statscache.refresh() import transaction transaction.commit() # Set up browser self.browser = Browser(self.layer['app']) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic {}:{}'.format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) # noqa: P101 )
class EditingControlPanelFunctionalTest(unittest.TestCase): """Test that changes in the editing control panel are actually stored in the registry. """ layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.app = self.layer['app'] self.request = self.layer['request'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() registry = getUtility(IRegistry) self.settings = registry.forInterface(IEditingSchema, prefix='plone') self.browser = Browser(self.app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_editing_control_panel_link(self): self.browser.open("%s/plone_control_panel" % self.portal_url) self.browser.getLink('Editing').click() def test_editing_control_panel_backlink(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.assertTrue("Plone Configuration" in self.browser.contents) def test_editing_control_panel_sidebar(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.browser.getLink('Site Setup').click() self.assertEqual(self.browser.url, 'http://nohost/plone/@@overview-controlpanel') def test_visible_ids(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.browser.getControl("Show 'Short Name' on content?")\ .selected = True self.browser.getControl('Save').click() self.assertEqual(self.settings.visible_ids, True) @unittest.skip("TODO: Not implemented yet.") def test_visible_ids_active(self): pass def test_default_editor(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.browser.getControl("Default editor").value = ["None"] self.browser.getControl('Save').click() self.assertEqual(self.settings.default_editor, "None") @unittest.skip("TODO: Not implemented yet.") def test_default_editor_active(self): pass def test_available_editors_hidden(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.assertTrue('Available editors' not in self.browser.contents) def test_ext_editor(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.browser.getControl("Enable External Editor feature")\ .selected = True self.browser.getControl('Save').click() self.assertEqual(self.settings.ext_editor, True) @unittest.skip("TODO: Not implemented yet.") def test_ext_editor_active(self): pass def test_enable_link_integrity_checks(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.browser.getControl("Enable link integrity checks")\ .selected = True self.browser.getControl('Save').click() self.assertEqual(self.settings.enable_link_integrity_checks, True) def test_enable_link_integrity_checks_active(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.browser.getControl("Enable link integrity checks")\ .selected = True self.browser.getControl('Save').click() self.assertTrue( ILinkIntegrityInfo(self.request).integrityCheckingEnabled()) def test_lock_on_ttw_edit(self): self.browser.open("%s/@@editing-controlpanel" % self.portal_url) self.browser.getControl("Enable locking for through-the-web edits")\ .selected = True self.browser.getControl('Save').click() self.assertEqual(self.settings.lock_on_ttw_edit, True) @unittest.skip("TODO: Not implemented yet.") def test_lock_on_ttw_edit_active(self): pass
def test_controlpanel(self): setRoles(self.portal, TEST_USER_ID, ('Manager', )) transaction.commit() from uniofleicester.jscontent.interfaces import IAllowedSectionsSchema registry = getUtility(IRegistry) settings = registry.forInterface(IAllowedSectionsSchema) self.assertEqual(settings.section, [ '/', ]) browser = Browser(self.layer['app']) browser.handleErrors = False browser.open("{}/login".format(self.portal.absolute_url())) browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl(name='submit').click() browser.open("{}/@@allowed-sections".format( self.portal.absolute_url())) browser.getControl(name='form.widgets.section').value = "/news\n/study" browser.getControl(name='form.buttons.save').click() self.assertEqual(settings.section, [u'/news', u'/study'])
class AudioFunctionalTest(unittest.TestCase): layer = MEDIA_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_add_audio(self): self.browser.open(self.portal_url) self.browser.getLink('Audio').click() self.browser.getControl( name='form.widgets.IDublinCore.title').value = "My audio" self.browser.getControl( name='form.widgets.IDublinCore.description')\ .value = "This is my audio." file_path = os.path.join(test_file_dir, "test.mp3") file_ctl = self.browser.getControl( name='form.widgets.IAudio.audio_file') file_ctl.add_file(open(file_path), 'audio/mp3', 'test.mp3') self.browser.getControl('Save').click() self.assertTrue('My audio' in self.browser.contents) self.assertTrue('This is my audio' in self.browser.contents) self.assertTrue('<audio' in self.browser.contents) self.assertIn('++widget++form.widgets.IAudio.audio_file/@@stream', self.browser.contents)
class FolderViewFunctionalTest(unittest.TestCase): layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] setRoles(self.portal, TEST_USER_ID, ['Manager']) self.portal_url = self.portal.absolute_url() self.portal.invokeFactory('Folder', id='folder', title='My Folder') self.folder = self.portal.folder self.folder_url = self.folder.absolute_url() self.folder.invokeFactory('Document', id='doc1', title='Document 1') import transaction transaction.commit() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic {0}:{1}'.format( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_folder_view(self): self.browser.open(self.folder_url + '/view') self.assertIn('My Folder', self.browser.contents) self.assertIn('Document 1', self.browser.contents) def test_folder_summary_view(self): self.browser.open(self.folder_url + '/summary_view') self.assertIn('My Folder', self.browser.contents) self.assertIn('Document 1', self.browser.contents) def test_folder_full_view(self): self.browser.open(self.folder_url + '/full_view') self.assertIn('My Folder', self.browser.contents) self.assertIn('Document 1', self.browser.contents) def test_folder_tabular_view(self): self.browser.open(self.folder_url + '/tabular_view') self.assertIn('My Folder', self.browser.contents) self.assertIn('Document 1', self.browser.contents) def test_folder_album_view(self): self.folder.invokeFactory('Image', id='image1', title='Image 1') img1 = self.folder['image1'] img1.image = dummy_image() import transaction transaction.commit() self.browser.open(self.folder_url + '/album_view') self.assertIn('My Folder', self.browser.contents) self.assertIn('<img src="http://nohost/plone/folder/image1/@@images', self.browser.contents) def test_list_item_wout_title(self): """In content listings, if a content object has no title use it's id. """ self.folder.invokeFactory('Document', id='doc_wout_title') import transaction transaction.commit() # Document should be shown in listing view (and it's siblings) self.browser.open(self.folder_url + "/listing_view") self.assertIn('doc_wout_title', self.browser.contents) # And also in tabular view self.browser.open(self.folder_url + "/tabular_view") self.assertIn('doc_wout_title', self.browser.contents)
class FolderFunctionalTest(unittest.TestCase): layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic {0}:{1}'.format( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_add_folder(self): self.browser.open(self.portal_url) self.browser.getLink(url='http://nohost/plone/++add++Folder').click() widget = 'form.widgets.IDublinCore.title' self.browser.getControl(name=widget).value = 'My folder' widget = 'form.widgets.IShortName.id' self.browser.getControl(name=widget).value = '' widget = 'form.widgets.IDublinCore.description' self.browser.getControl(name=widget).value = 'This is my folder.' self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('my-folder/view')) self.assertTrue('My folder' in self.browser.contents) self.assertTrue('This is my folder' in self.browser.contents) def test_add_folder_with_shortname(self): self.browser.open(self.portal_url) self.browser.getLink(url='http://nohost/plone/++add++Folder').click() widget = 'form.widgets.IDublinCore.title' self.browser.getControl(name=widget).value = 'My folder' widget = 'form.widgets.IShortName.id' self.browser.getControl(name=widget).value = 'my-special-folder' self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('my-special-folder/view'))
class TestCookieAuth(unittest.TestCase): layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer['portal'] self.folder = self.portal['test-folder'] self.browser = Browser(self.layer['app']) self.auth_info = '%s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD) self.cookie = base64.encodestring(self.auth_info)[:-1] self.folder.manage_permission('View', ['Manager'], acquire=0) logout() def testAutoLoginPage(self): # Should send us to login_form self.browser.open(self.folder.absolute_url()) self.assertIn('200', self.browser.headers['status']) self.assertEqual( self.browser.url, 'http://nohost/plone/login?came_from=http%3A//nohost/plone/test-folder' # noqa: E501 ) def testInsufficientPrivileges(self): # Should send us to login_form self.browser.open(self.portal.absolute_url()) self.browser.cookies['__ac'] = self.cookie self.browser.open(self.folder.absolute_url()) self.assertIn('200', self.browser.headers['status']) self.assertEqual( self.browser.url, 'http://nohost/plone/login?came_from=http%3A//nohost/plone/test-folder' # noqa: E501 ) def testSetSessionCookie(self): # The __ac cookie should be set for the session only self.browser.open('http://nohost/plone/login') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl('Log in').click() self.assertIn('200', self.browser.headers['status']) self.assertIn('__ac', self.browser.cookies) self.assertEqual( self.browser.cookies.getinfo('__ac')['path'], '/', ) self.assertIsNone(self.browser.cookies.getinfo('__ac')['expires'])
def testCanRenderHomepage(self): browser = Browser(self.layer['app']) browser.open('http://nohost/test') self.assertTrue('Welcome' in browser.contents)
def test_edit(self): browser = Browser(self.layer['app']) browser.handleErrors = False self.folder.invokeFactory('Document', 'd1') self.folder['d1'].setTitle(u'New title') transaction.commit() uuid = IUUID(self.folder['d1']) # Login browser.open(self.portal.absolute_url() + '/login') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl('Log in').click() # Enter the edit screen browser.open(self.folder['d1'].absolute_url() + '/edit') # Confirm pass CSRF protection try: browser.getControl(name='form.button.confirm').click() except LookupError: pass # We should now have cookies with the drafts information cookies = browser.cookies.forURL(browser.url) self.assertEqual( '"{0}"'.format(self.folder['d1'].absolute_url_path()), cookies['plone.app.drafts.path'], ) self.assertEqual('"{0}"'.format(uuid), cookies['plone.app.drafts.targetKey']) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), ) # We can now save the page. The cookies should expire. browser.getControl(name='form.button.save').click() self.assertNotIn( 'plone.app.drafts.targetKey', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.path', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), )
def test_add_to_portal_root_save(self): browser = Browser(self.layer['app']) browser.handleErrors = False # Login browser.open(self.portal.absolute_url() + '/login') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl('Log in').click() # Enter the add screen for a temporary # portal_factory-managed object browser.open( '{}/portal_factory/Document/document.2010-02-04.2866363923/edit?_authenticator={}' .format( # noqa self.portal.absolute_url(), createToken())) # We should now have cookies with the drafts information cookies = browser.cookies.forURL(browser.url) self.assertEqual( '"/plone/portal_factory/Document/document.2010-02-04.2866363923"', # noqa cookies['plone.app.drafts.path'], ) self.assertEqual( '"0%3ADocument"', cookies['plone.app.drafts.targetKey'], ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), ) # We can now fill in the required fields and save. # The cookies should expire. browser.getControl(name='title').value = u'New document' browser.getControl(name='form.button.save').click() self.assertNotIn( 'plone.app.drafts.targetKey', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.path', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), )
class FileFunctionalTest(unittest.TestCase): layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,) ) def test_add_file(self): self.browser.open(self.portal_url) self.browser.getLink('File').click() self.browser.getControl(name='form.widgets.title')\ .value = "My file" self.browser.getControl(name='form.widgets.description')\ .value = "This is my file." file_path = os.path.join(os.path.dirname(__file__), "image.jpg") file_ctl = self.browser.getControl(name='form.widgets.file') file_ctl.add_file(open(file_path), 'image/png', 'image.jpg') self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('image.jpg/view')) self.assertTrue('My file' in self.browser.contents) self.assertTrue('This is my file' in self.browser.contents) @unittest.skip("IShortName not available") def test_shortname_file(self): self.browser.open(self.portal_url) self.browser.getLink('File').click() self.browser.getControl(name='form.widgets.title')\ .value = "My file" self.browser.getControl(name='form.widgets.IShortName.id')\ .value = "my-special-file" file_path = os.path.join(os.path.dirname(__file__), "image.jpg") file_ctl = self.browser.getControl(name='form.widgets.file') file_ctl.add_file(open(file_path), 'image/png', 'image.jpg') self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('my-special-file/view')) def test_mime_icon_pdf_for_file_(self): self.browser.open(self.portal_url) self.browser.getLink('File').click() self.browser.getControl(name='form.widgets.title')\ .value = "My file" self.browser.getControl(name='form.widgets.description')\ .value = "This is my pdf file." file_path = os.path.join(os.path.dirname(__file__), "file.pdf") file_ctl = self.browser.getControl(name='form.widgets.file') file_ctl.add_file(open(file_path), 'application/pdf', 'file.pdf') self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('file.pdf/view')) self.assertTrue('pdf.png' in self.browser.contents) def test_alternative_mime_icon_doc_for_file(self): self.browser.open(self.portal_url) self.browser.getLink('File').click() self.browser.getControl(name='form.widgets.title')\ .value = "My file" self.browser.getControl(name='form.widgets.description')\ .value = "This is my doc file." file_path = os.path.join(os.path.dirname(__file__), "file.doc") file_ctl = self.browser.getControl(name='form.widgets.file') file_ctl.add_file(open(file_path), 'application/msword', 'file.doc') self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('file.doc/view')) self.assertTrue('custom.png' in self.browser.contents) def test_mime_icon_odt_for_file_(self): self.browser.open(self.portal_url) self.browser.getLink('File').click() self.browser.getControl(name='form.widgets.title')\ .value = "My file" self.browser.getControl(name='form.widgets.description')\ .value = "This is my odt file." file_path = os.path.join(os.path.dirname(__file__), "file.odt") file_ctl = self.browser.getControl(name='form.widgets.file') file_ctl.add_file(open(file_path), 'application/vnd.oasis.opendocument.text', 'file.odt') self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('file.odt/view')) self.assertTrue('application.png' in self.browser.contents)
def test_add_to_folder(self): browser = Browser(self.layer['app']) browser.handleErrors = False # Login browser.open(self.portal.absolute_url() + '/login') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl('Log in').click() # Enter the add screen for a temporary portal_factory-managed object browser.open(self.folder.absolute_url() + '/++add++MyDocument') # We should now have cookies with the drafts information cookies = browser.cookies.forURL(browser.url) self.assertEqual( '"{0}"'.format(self.folder.absolute_url_path()), cookies['plone.app.drafts.path'], ) self.assertEqual( # noqa '"{0}"'.format(IUUID(self.folder)), cookies['plone.app.drafts.targetKey'], ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), ) # We can now cancel the edit. The cookies should expire. browser.getControl(name='form.buttons.cancel').click() self.assertNotIn( 'plone.app.drafts.targetKey', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.path', browser.cookies.forURL(browser.url), )
def test_add_to_folder(self): browser = Browser(self.layer['app']) browser.handleErrors = False uuid = IUUID(self.folder) # Login browser.open(self.portal.absolute_url() + '/login') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl('Log in').click() # Enter the add screen for a temporary # portal_factory-managed object browser.open( '{}/portal_factory/Document/document.2010-02-04.2866363923/edit?_authenticator={}' .format( # noqa self.folder.absolute_url(), createToken())) # We should now have cookies with the drafts information cookies = browser.cookies.forURL(browser.url) path = '"{0}/portal_factory/Document/document.2010-02-04.2866363923"' # noqa self.assertEqual( path.format(self.folder.absolute_url_path()), cookies['plone.app.drafts.path'], ) self.assertEqual( '"{0}%3ADocument"'.format(uuid), cookies['plone.app.drafts.targetKey'], ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), ) # We can now cancel the edit. The cookies should expire. browser.getControl(name='form.button.cancel').click() self.assertNotIn( 'plone.app.drafts.targetKey', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.path', browser.cookies.forURL(browser.url), )
def test_composite_views(self): # This is a clone of the same test for 'without-caching-proxy' # Can we just call that test from this context? catalog = self.portal['portal_catalog'] skins_tool = self.portal['portal_skins'] # Add folder content setRoles(self.portal, TEST_USER_ID, ('Manager',)) self.portal.invokeFactory('Folder', 'f1') self.portal['f1'].title = "one" self.portal['f1'].description = u"Folder one description" self.portal['f1'].reindexObject() # Add page content self.portal['f1'].invokeFactory('Document', 'd1') self.portal['f1']['d1'].title = u"Document one" self.portal['f1']['d1'].description = u"Document one description" testText = "Testing... body one" self.portal['f1']['d1'].text = RichTextValue( testText, 'text/plain', 'text/html' ) self.portal['f1']['d1'].reindexObject() # Publish the folder and page self.portal.portal_workflow.doActionFor(self.portal['f1'], 'publish') self.portal.portal_workflow.doActionFor(self.portal['f1']['d1'], 'publish') # Should we set up the etag components? # - set member? No # - reset catalog counter? Maybe # - set server language? # - turn on gzip? # - set skin? Maybe # - leave status unlocked # import transaction; transaction.commit() # Request the authenticated folder now = stable_now() browser = Browser(self.app) browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,)) browser.open(self.portal['f1'].absolute_url()) self.assertEqual('plone.content.folderView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertEqual('"|test_user_1_|%d|en|%s|0|0' % (catalog.getCounter(), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Set the copy/cut cookie and then request the folder view again browser.cookies.create('__cp', 'xxx') browser.open(self.portal['f1'].absolute_url()) # The response should be the same as before except for the etag self.assertEqual('plone.content.folderView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertEqual('"|test_user_1_|%d|en|%s|0|1' % (catalog.getCounter(), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) # Request the authenticated page now = stable_now() browser = Browser(self.app) browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,)) browser.open(self.portal['f1']['d1'].absolute_url()) self.assertTrue(testText in browser.contents) self.assertEqual('plone.content.itemView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertEqual('"|test_user_1_|%d|en|%s|0' % (catalog.getCounter(), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the authenticated page again -- to test RAM cache. browser = Browser(self.app) browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,)) browser.open(self.portal['f1']['d1'].absolute_url()) self.assertEqual('plone.content.itemView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) # Authenticated should NOT be RAM cached self.assertEqual(None, browser.headers.get('X-RAMCache')) # Request the authenticated page again -- with an INM header to test 304 etag = browser.headers['ETag'] browser = Browser(self.app) browser.raiseHttpErrors = False # we really do want to see the 304 browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,)) browser.addHeader('If-None-Match', etag) browser.open(self.portal['f1']['d1'].absolute_url()) # This should be a 304 response self.assertEqual('304 Not Modified', browser.headers['Status']) self.assertEqual('', browser.contents) # Request the anonymous folder now = stable_now() browser = Browser(self.app) browser.open(self.portal['f1'].absolute_url()) self.assertEqual('plone.content.folderView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertEqual('"||%d|en|%s|0|0' % (catalog.getCounter(), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the anonymous page now = stable_now() browser = Browser(self.app) browser.open(self.portal['f1']['d1'].absolute_url()) self.assertEqual('plone.content.itemView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) self.assertTrue(testText in browser.contents) # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertEqual('"||%d|en|%s|0' % (catalog.getCounter(), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the anonymous page again -- to test RAM cache. # Anonymous should be RAM cached now = stable_now() browser = Browser(self.app) browser.open(self.portal['f1']['d1'].absolute_url()) self.assertEqual('plone.content.itemView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) # This should come from RAM cache self.assertEqual('plone.app.caching.operations.ramcache', browser.headers['X-RAMCache']) self.assertTrue(testText in browser.contents) self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertEqual('"||%d|en|%s|0' % (catalog.getCounter(), skins_tool.default_skin), _normalize_etag(browser.headers['ETag'])) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the anonymous page again -- with an INM header to test 304. etag = browser.headers['ETag'] browser = Browser(self.app) browser.raiseHttpErrors = False browser.addHeader('If-None-Match', etag) browser.open(self.portal['f1']['d1'].absolute_url()) self.assertEqual('plone.content.itemView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) # This should be a 304 response self.assertEqual('304 Not Modified', browser.headers['Status']) self.assertEqual('', browser.contents) # Edit the page to update the etag testText2 = "Testing... body two" self.portal['f1']['d1'].text = RichTextValue( testText2, 'text/plain', 'text/html' ) self.portal['f1']['d1'].reindexObject() import transaction; transaction.commit() # Request the anonymous page again -- to test expiration of 304 and RAM. etag = browser.headers['ETag'] browser = Browser(self.app) browser.addHeader('If-None-Match', etag) browser.open(self.portal['f1']['d1'].absolute_url()) self.assertEqual('plone.content.itemView', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.weakCaching', browser.headers['X-Cache-Operation']) # The etag has changed so we should get a fresh page. self.assertEqual(None, browser.headers.get('X-RAMCache')) self.assertEqual('200 Ok', browser.headers['Status'])
def test_edit_multiple_existing_drafts(self): browser = Browser(self.layer['app']) browser.handleErrors = False self.folder.invokeFactory('MyDocument', 'd1') self.folder['d1'].title = u'New title' transaction.commit() uuid = IUUID(self.folder['d1']) # Create two drafts for this object - we don't expect either to be used storage = getUtility(IDraftStorage) storage.createDraft(TEST_USER_ID, str(uuid)) storage.createDraft(TEST_USER_ID, str(uuid)) # Login browser.open(self.portal.absolute_url() + '/login') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl('Log in').click() # Enter the edit screen browser.open(self.folder['d1'].absolute_url() + '/edit') # We should now have cookies with the drafts information cookies = browser.cookies.forURL(browser.url) self.assertEqual( '"{0}"'.format(self.folder['d1'].absolute_url_path()), cookies['plone.app.drafts.path'], ) self.assertEqual( '"{0}"'.format(uuid), cookies['plone.app.drafts.targetKey'], ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), ) # We can now save the page. The cookies should expire. browser.getControl(name='form.buttons.save').click() self.assertNotIn( 'plone.app.drafts.targetKey', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.path', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), )
def test_content_files(self): # Add folder content setRoles(self.portal, TEST_USER_ID, ('Manager',)) self.portal.invokeFactory('Folder', 'f1') self.portal['f1'].title = u"Folder one" self.portal['f1'].description = u"Folder one description" self.portal['f1'].reindexObject() # Add content image self.portal['f1'].invokeFactory('Image', 'i1') self.portal['f1']['i1'].title = u"Image one" self.portal['f1']['i1'].description = u"Image one description" self.portal['f1']['i1'].image = test_image() self.portal['f1']['i1'].reindexObject() import transaction; transaction.commit() # Request the image with Manager role now = stable_now() browser = Browser(self.app) browser.addHeader('Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)) browser.open(self.portal['f1']['i1'].absolute_url()) self.assertEqual('plone.content.file', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # Folder not published yet so image should not be cached in proxy # so this should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertFalse(None == browser.headers.get('Last-Modified')) # remove this when the next line works #self.assertEqual('---lastmodified---', browser.headers['Last-Modified']) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request an image scale with Manager role now = stable_now() browser = Browser(self.app) browser.addHeader('Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)) browser.open(self.portal['f1']['i1'].absolute_url() + '/@@images/image/preview') self.assertEqual('plone.content.file', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # Folder not published yet so image scale should not be cached in proxy # so this should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertFalse(None == browser.headers.get('Last-Modified')) # remove this when the next line works #self.assertEqual('---lastmodified---', browser.headers['Last-Modified']) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Publish the folder self.portal.portal_workflow.doActionFor(self.portal['f1'], 'publish') import transaction; transaction.commit() # Request the image now = stable_now() browser = Browser(self.app) browser.open(self.portal['f1']['i1'].absolute_url()) self.assertEqual('plone.content.file', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # Now visible to anonymous so this should use cacheInProxy self.assertEqual('max-age=0, s-maxage=86400, must-revalidate', browser.headers['Cache-Control']) self.assertFalse(None == browser.headers.get('Last-Modified')) # remove this when the next line works #self.assertEqual('---lastmodified---', browser.headers['Last-Modified']) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the image again -- with an IMS header to test 304 lastmodified = browser.headers['Last-Modified'] browser = Browser(self.app) browser.raiseHttpErrors = False browser.addHeader('If-Modified-Since', lastmodified) browser.open(self.portal['f1']['i1'].absolute_url()) self.assertEqual('plone.content.file', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # This should be a 304 response self.assertEqual('304 Not Modified', browser.headers['Status']) self.assertEqual('', browser.contents) # Request an image scale now = stable_now() browser = Browser(self.app) browser.open(self.portal['f1']['i1'].absolute_url() + '/@@images/image/preview') self.assertEqual('plone.content.file', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # Now visible to anonymous so this should use cacheInProxy self.assertEqual('max-age=0, s-maxage=86400, must-revalidate', browser.headers['Cache-Control']) self.assertFalse(None == browser.headers.get('Last-Modified')) # remove this when the next line works #self.assertEqual('---lastmodified---', browser.headers['Last-Modified']) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires']))
def test_add_to_portal_root_save(self): browser = Browser(self.layer['app']) browser.handleErrors = False # Login browser.open(self.portal.absolute_url() + '/login') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl('Log in').click() # Enter the add screen for a temporary portal_factory-managed object browser.open(self.portal.absolute_url() + '/++add++MyDocument') # We should now have cookies with the drafts information cookies = browser.cookies.forURL(browser.url) self.assertEqual('"/plone"', cookies['plone.app.drafts.path']) self.assertEqual( # noqa '"%2B%2Badd%2B%2BMyDocument"', cookies['plone.app.drafts.targetKey'], ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), ) # Simulate save action for creating a draft storage = queryUtility(IDraftStorage) draft = storage.createDraft(TEST_USER_ID, '++add++MyDocument') target = createContent('MyDocument') draft._draftAddFormTarget = target transaction.commit() browser.cookies.create( DRAFT_NAME_KEY, u'draft', path='/plone', ) # We can now fill in the required fields and save. The cookies should # expire. browser.getControl( name='form.widgets.IDublinCore.title').value = u'New Document' browser.getControl(name='form.buttons.save').click() self.assertNotIn( 'plone.app.drafts.targetKey', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.path', browser.cookies.forURL(browser.url), ) self.assertNotIn( 'plone.app.drafts.draftName', browser.cookies.forURL(browser.url), )
class LinkFunctionalTest(unittest.TestCase): layer = PLONE_APP_CONTENTTYPES_FUNCTIONAL_TESTING def setUp(self): app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic {0}:{1}'.format( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, )) def test_add_link(self): self.browser.open(self.portal_url) self.browser.getLink('Link').click() self.browser.getControl(name='form.widgets.IDublinCore.title')\ .value = 'My link' self.browser.getControl(name='form.widgets.IDublinCore.description')\ .value = 'This is my link.' self.browser.getControl(name='form.widgets.IShortName.id')\ .value = 'my-special-link' self.browser.getControl(name='form.widgets.remoteUrl.external')\ .value = 'https://plone.org' self.browser.getControl('Save').click() self.assertTrue(self.browser.url.endswith('my-special-link/view')) self.assertTrue('My link' in self.browser.contents) self.assertTrue('This is my link' in self.browser.contents)
def test_resources(self): # This is a clone of the same test for 'without-caching-proxy' # Can we just call that test from this context? import transaction; transaction.commit() # Request a skin image now = stable_now() browser = Browser(self.app) browser.open(self.portal.absolute_url() + '/rss.png') self.assertEqual('plone.resource', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowserAndProxy self.assertEqual('max-age=86400, proxy-revalidate, public', browser.headers['Cache-Control']) self.assertFalse(None == browser.headers.get('Last-Modified')) # remove this when the next line works #self.assertEqual('---lastmodified---', browser.headers['Last-Modified']) timedelta = dateutil.parser.parse(browser.headers['Expires']) - now self.assertTrue(timedelta > datetime.timedelta(seconds=86390)) # Request the skin image again -- with an IMS header to test 304 lastmodified = browser.headers['Last-Modified'] browser = Browser(self.app) browser.raiseHttpErrors = False browser.addHeader('If-Modified-Since', lastmodified) browser.open(self.portal.absolute_url() + '/rss.png') self.assertEqual('plone.resource', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) # This should be a 304 response self.assertEqual('304 Not Modified', browser.headers['Status']) self.assertEqual('', browser.contents) # Request a large datafile (over 64K) to test files that use # the "response.write()" function to initiate a streamed response. # This is of type OFS.Image.File but it should also apply to # large OFS.Image.Image, large non-blog ATImages/ATFiles, and # large Resource Registry cooked files, which all use the same # method to initiate a streamed response. s = "a" * (1 << 16) * 3 self.portal.manage_addFile('bigfile', file=StringIO(s), content_type='application/octet-stream') import transaction; transaction.commit() browser = Browser(self.app) browser.open(self.portal['bigfile'].absolute_url()) self.assertEqual('plone.resource', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.strongCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowserAndProxy self.assertEqual('max-age=86400, proxy-revalidate, public', browser.headers['Cache-Control']) self.assertFalse(None == browser.headers.get('Last-Modified')) # remove this when the next line works #self.assertEqual('---lastmodified---', browser.headers['Last-Modified']) timedelta = dateutil.parser.parse(browser.headers['Expires']) - now self.assertTrue(timedelta > datetime.timedelta(seconds=86390))
def test_collection_templates(self): portal = self.layer['portal'] login(portal, 'admin') data = getData('image.png') # add an image that will be listed by the collection portal.invokeFactory("Image", "image", title="Image example", image=data) # add a collection, so we can add a query to it portal.invokeFactory("Collection", "collection", title="New Collection") collection = portal['collection'] # Search for images query = [{ 'i': 'Type', 'o': 'plone.app.querystring.operation.string.is', 'v': 'Image', }] # set the query and publish the collection collection.setQuery(query) workflow = portal.portal_workflow workflow.doActionFor(collection, "publish") commit() logout() # open a browser to see if our image is in the results browser = Browser(self.layer['app']) browser.handleErrors = False browser.open(collection.absolute_url()) self.assertTrue("Image example" in browser.contents) # open summary_view template browser.open('%s/summary_view' % collection.absolute_url()) self.assertTrue("Image example" in browser.contents) # open folder_summary_view template browser.open('%s/folder_summary_view' % collection.absolute_url()) self.assertTrue("Image example" in browser.contents) # open thumbnail_view template browser.open('%s/thumbnail_view' % collection.absolute_url()) self.assertTrue("Image example" in browser.contents)
def test_content_feeds(self): catalog = self.portal['portal_catalog'] skins_tool = self.portal['portal_skins'] # Enable syndication setRoles(self.portal, TEST_USER_ID, ('Manager',)) self.syndication = getToolByName(self.portal, 'portal_syndication') self.syndication.editProperties(isAllowed=True) self.syndication.enableSyndication(self.portal) import transaction; transaction.commit() # Request the rss feed now = stable_now() browser = Browser(self.app) browser.open(self.portal.absolute_url() + '/RSS') self.assertEqual('plone.content.feed', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # This should use cacheInProxy self.assertEqual('max-age=0, s-maxage=86400, must-revalidate', browser.headers['Cache-Control']) self.assertEqual('"||%d|en|%s"' % (catalog.getCounter(), skins_tool.default_skin), browser.headers['ETag']) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the rss feed again -- to test RAM cache now = stable_now() rssText = browser.contents browser = Browser(self.app) browser.open(self.portal.absolute_url() + '/RSS') self.assertEqual('plone.content.feed', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # This should come from the RAM cache self.assertEqual('plone.app.caching.operations.ramcache', browser.headers['X-RAMCache']) self.assertEqual(rssText, browser.contents) self.assertEqual('max-age=0, s-maxage=86400, must-revalidate', browser.headers['Cache-Control']) self.assertEqual('"||%d|en|%s"' % (catalog.getCounter(), skins_tool.default_skin), browser.headers['ETag']) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the rss feed again -- with an INM header to test 304. etag = browser.headers['ETag'] browser = Browser(self.app) browser.raiseHttpErrors = False browser.addHeader('If-None-Match', etag) browser.open(self.portal.absolute_url() + '/RSS') self.assertEqual('plone.content.feed', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # This should be a 304 response self.assertEqual('304 Not Modified', browser.headers['Status']) self.assertEqual('', browser.contents) # Request the authenticated rss feed now = stable_now() browser = Browser(self.app) browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,)) browser.open(self.portal.absolute_url() + '/RSS') self.assertEqual('plone.content.feed', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # This should use cacheInBrowser self.assertEqual('max-age=0, must-revalidate, private', browser.headers['Cache-Control']) self.assertEqual('"|test_user_1_|%d|en|%s"' % (catalog.getCounter(), skins_tool.default_skin), browser.headers['ETag']) self.assertTrue(now > dateutil.parser.parse(browser.headers['Expires'])) # Request the authenticated rss feed again -- to test RAM cache browser = Browser(self.app) browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,)) browser.open(self.portal.absolute_url() + '/RSS') self.assertEqual('plone.content.feed', browser.headers['X-Cache-Rule']) self.assertEqual('plone.app.caching.moderateCaching', browser.headers['X-Cache-Operation']) # Authenticated should NOT be RAM cached self.assertEqual(None, browser.headers.get('X-RAMCache'))
def setUp(self): self.browser = Browser(self.layer['app']) self.browser.handleErrors = False self.portal = self.layer['portal']
class EscondeAutorDataFunctionalTestCase(unittest.TestCase): """Testa a funcionalidade de esconder autor e data em templates que não utilizam a viewlet documentbyline.""" layer = FUNCTIONAL_TESTING def setUp(self): """Configura testes funcionais antes de cada teste.""" self.portal = self.layer['portal'] self.wt = api.portal.get_tool('portal_workflow') self.pas_member = getMultiAdapter((self.portal, self.portal.REQUEST), name='pas_member') self.portal_url = self.portal.absolute_url() esconde_autor() esconde_data() self.browser = Browser(self.layer['app']) transaction.commit() def cria_conteudo(self, container, tipo, id_obj, title): """Cria e publica um conteúdo, retornando o objeto criado.""" with api.env.adopt_roles(['Manager']): obj = api.content.create( type=tipo, container=container, id=id_obj, title=title, ) self.wt.doActionFor(obj, 'publish') effective = DateTime() obj.setEffectiveDate(effective) obj.reindexObject() return obj def cria_pasta(self): """Cria uma pasta com uma página dentro, retornando a página.""" pasta = self.cria_conteudo(self.portal, 'Folder', ID_OBJ, u'Pasta') pagina = self.cria_conteudo(pasta, 'Document', ID_PAGINA, u'Pagina') transaction.commit() return pagina def cria_colecao(self): """Cria uma coleção de páginas. Também cria uma página para alimentar a coleção e retorna essa página.""" colecao = self.cria_conteudo(self.portal, 'Collection', ID_OBJ, u'Coleção') colecao.sort_on = u'effective' colecao.query = [ { 'i': u'portal_type', 'o': u'plone.app.querystring.operation.selection.is', 'v': [u'Document'], }, { 'i': u'review_state', 'o': u'plone.app.querystring.operation.selection.is', 'v': [u'published'], }, ] pagina = self.cria_conteudo(self.portal, 'Document', ID_PAGINA, u'Pagina') transaction.commit() return pagina def base_teste_data(self, obj, contents): """Testa que a data de publicação e a data de modificação não aparecem na página.""" datas = (obj.effective(), obj.modified()) for data in datas: self.assertNotEqual('None', data) self.assertNotIn(data.strftime(LOCAL_TIME_FORMAT), contents) self.assertNotIn('última', contents) self.assertNotIn('Modificado', contents) def base_teste_autor(self, obj, contents): """Testa que o autor não aparece na página.""" creator = obj.Creator() autor = self.pas_member.info(creator) # Testa nome self.assertNotIn('{0}<'.format(autor['name_or_id']), contents) self.assertNotIn('{0},'.format(autor['name_or_id']), contents) # Testa creator self.assertNotIn('{0}<'.format(creator), contents) self.assertNotIn('{0},'.format(creator), contents) def base_teste_esconde_autor_data(self, template, obj): """Teste base para template em pasta ou coleção.""" self.browser.open('{0}/{1}/{2}'.format(self.portal.absolute_url(), ID_OBJ, template)) contents = self.browser.contents self.assertIn('Pagina', contents) # testa esconde autor self.base_teste_autor(obj, contents) # testa esconde data self.base_teste_data(obj, contents) def base_teste_esconde_autor_data_root(self, template, obj): """Teste base para template no root do portal.""" self.browser.open('{0}/{1}'.format(self.portal.absolute_url(), template)) contents = self.browser.contents self.assertIn('Pagina', contents) # testa esconde autor self.base_teste_autor(obj, contents) # testa esconde data self.base_teste_data(obj, contents) def test_collection_summary_view(self): """Testa se o autor e a data são escondidos no summary_view da Coleção.""" obj = self.cria_colecao() self.base_teste_esconde_autor_data('summary_view', obj) def test_pasta_summary_view(self): """Testa se o autor e a data são escondidos no summary_view de Pastas.""" obj = self.cria_pasta() self.base_teste_esconde_autor_data('summary_view', obj) def test_busca(self): """Testa se o autor e a data são escondidos na página resultado de busca.""" obj = self.cria_pasta() self.base_teste_esconde_autor_data('@@busca?SearchableText=Pagina', obj) def test_listing_view(self): """Testa se o autor e a data são escondidos no listing_view.""" obj = self.cria_pasta() self.base_teste_esconde_autor_data('listing_view', obj) def test_collection_listing_view(self): """Testa se o autor e a data são escondidos no listing_view da Coleção.""" obj = self.cria_colecao() self.base_teste_esconde_autor_data('listing_view', obj) def test_pasta_tabular_view(self): """Testa se o autor e a data são escondidos no tabular_view da Pasta.""" obj = self.cria_pasta() self.base_teste_esconde_autor_data('tabular_view', obj) def test_recently_modified(self): """Testa se o autor e a data são escondidos no recently_modified.""" obj = self.cria_pasta() self.base_teste_esconde_autor_data_root('recently_modified', obj) def test_recently_published(self): """Testa se o autor e a data são escondidos no recently_published.""" obj = self.cria_pasta() self.base_teste_esconde_autor_data_root('recently_published', obj)
class TestWatcherPortletAddForm(RequestAwareTestCase): layer = FUNCTIONAL_TESTING def setUp(self): super(RequestAwareTestCase, self).setUp() self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager', 'Member', 'Site Administrator']) transaction.commit() self.browser = Browser(self.layer['app']) self.browser.handleErrors = False self.browser.open('%s/login_form' % self.portal.absolute_url()) self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() self.assertIn('You are now logged in', self.browser.contents) def tearDown(self): super(RequestAwareTestCase, self).tearDown() setRoles(self.portal, TEST_USER_ID, ['Member']) self.browser.open('%s/logout' % self.portal.absolute_url()) transaction.commit() def test_portlet_addable(self): url = os.path.join(self.portal.absolute_url(), '@@manage-portlets') self.browser.open(url) self.assertNotIn('You do not have sufficient privileges', self.browser.contents) self.assertIn('Recently modified', self.browser.contents) self.assertEqual( self.browser.getControl('Recently modified', index=1).optionValue, '/++contextportlets++plone.rightcolumn/+/' + 'ftw.bridge.client.watcher_portlet') def test_portlet_addform(self): self.assertEqual( self.portal.restrictedTraverse( '++contextportlets++plone.rightcolumn').keys(), []) url = os.path.join(self.portal.absolute_url(), '++contextportlets++plone.rightcolumn', '+/ftw.bridge.client.watcher_portlet') self.browser.open(url) self.assertNotIn('You do not have sufficient privileges', self.browser.contents) self.assertIn('Client ID', self.browser.contents) self.browser.getControl('Client ID').value = 'foo' self.browser.getControl('Path').value = '@@bar?baz=1' self.browser.getControl('Save').click() mapping = self.portal.restrictedTraverse( '++contextportlets++plone.rightcolumn') self.assertEqual( mapping.keys(), ['title_watcher_portlet']) assignment = mapping.get('title_watcher_portlet') self.assertEqual(assignment.client_id, u'foo') self.assertEqual(assignment.path, u'@@bar?baz=1')
def getBrowser(portal, loggedIn=True, username=TEST_USER_NAME, password=TEST_USER_PASSWORD): """Instantiate and return a testbrowser for convenience This is done weirdly because I could not figure out how else to pass the browser to the doctests""" browser = Browser(portal) browser.addHeader('Accept-Language', 'en') browser.handleErrors = False if loggedIn: browser.open(portal.absolute_url()) browser.getControl('Login Name').value = username browser.getControl('Password').value = password browser.getControl('Log in').click() assert ('You are now logged in' in browser.contents) return browser
def test_remove_permission_form_group(self): portal = self.layer['portal'] portal_url = portal.absolute_url() browser = Browser(self.layer['app']) TEST_GROUP_ID = 'test_group' # Set up a group - commit change for test browser portal.portal_groups.addGroup(TEST_GROUP_ID) transaction.commit() # Add locale roles to a group portal.folder1.manage_addLocalRoles(TEST_GROUP_ID, ['Contributor',]) portal.folder1.folder2.manage_addLocalRoles(TEST_GROUP_ID, ['Editor',]) # Login as test user browser.open(portal_url + '/login_form') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl(name='submit').click() browser.open(portal_url + '/folder1/remove_user_permissions') # Look for the right form self.assertIn( '<form method="post" action="http://nohost/plone/folder1/@@remove_user_permissions">', browser.contents ) # Search for for the test goup browser.getControl(name="search_term").value = TEST_GROUP_ID browser.getControl(name="form.button.Search").click() self.assertIn( '<a href="http://nohost/plone/folder1/@@remove_user_permissions?user=test_group">test_group</a>', browser.contents ) # Choose group browser.open('http://nohost/plone/folder1/@@remove_user_permissions?user=test_group') # Confirm link self.assertIn( '<a class="context" href="http://nohost/plone/folder1/@@remove_user_permissions?user=test_group&confirmed=1">', browser.contents ) # Abort link self.assertIn( '<a class="standalone" href="http://nohost/plone/folder1/@@remove_user_permissions">', browser.contents ) # Confirm removal of roles for the test group browser.open('http://nohost/plone/folder1/@@remove_user_permissions?user=test_group&confirmed=1') # After removal, redirect to permission manager overview self.assertIn( 'class="template-permission_manager', browser.contents) # Approve if user has no local roles on folder1 and folder2 self.assertFalse( TEST_GROUP_ID in [entry[0] for entry in portal.folder1.get_local_roles()]) self.assertFalse( TEST_GROUP_ID in [entry[0] for entry in portal.folder1.folder2.get_local_roles()])
class TestRedirectAfterLogin(unittest.TestCase): layer = PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING def setUp(self): self.browser = Browser(self.layer['app']) self.browser.handleErrors = False self.portal = self.layer['portal'] def test_redirect_to_portal_if_no_adapter_nor_came_from(self): self.browser.open('http://nohost/plone/login') self.browser.getLink('Log in').click() self.assertEqual(self.browser.url, 'http://nohost/plone/login') self.browser.getControl('Login Name').value = TEST_USER_NAME self.browser.getControl('Password').value = TEST_USER_PASSWORD self.browser.getControl('Log in').click() self.assertIn('You are now logged in.', self.browser.contents) self.assertEqual( self.browser.url, 'http://nohost/plone', 'Successful login did not redirect to the homepage ' 'when came_from was not defined.') # Now log out. self.browser.getLink('Log out').click() self.assertIn('You are now logged out.', self.browser.contents, 'Logout status message not displayed.') def test_redirect_to_came_from_if_no_adapter_found(self): self.browser.open('http://nohost/plone/login') self.browser.getLink('Log in').click() self.assertEqual(self.browser.url, 'http://nohost/plone/login') self.browser.getControl('Login Name').value = TEST_USER_NAME self.browser.getControl('Password').value = TEST_USER_PASSWORD self.browser.getControl(name='came_from').value = \ 'http://nohost/plone/contact-info' self.browser.getControl('Log in').click() self.assertIn('You are now logged in.', self.browser.contents) self.assertEqual( self.browser.url, 'http://nohost/plone/contact-info', 'Successful login did not redirect to the came_from.') # Now log out. self.browser.getLink('Log out').click() self.assertIn('You are now logged out.', self.browser.contents, 'Logout status message not displayed.') def test_redirect_to_adapter_result(self): # Register our redirect adapter from zope.component import getGlobalSiteManager gsm = getGlobalSiteManager() gsm.registerAdapter(AfterLoginAdapter, (Interface, IRequest)) self.browser.open('http://nohost/plone/login') self.browser.getLink('Log in').click() self.assertEqual(self.browser.url, 'http://nohost/plone/login') self.browser.getControl('Login Name').value = TEST_USER_NAME self.browser.getControl('Password').value = TEST_USER_PASSWORD self.browser.getControl(name='came_from').value = \ 'http://nohost/plone/contact-info' self.browser.getControl('Log in').click() gsm.unregisterAdapter(AfterLoginAdapter, (Interface, IRequest)) self.assertIn('You are now logged in.', self.browser.contents) self.assertEqual( self.browser.url, 'http://nohost/plone/sitemap', 'Successful login did not use the adapter for ' 'redirect.') # Now log out. self.browser.getLink('Log out').click() self.assertIn('You are now logged out.', self.browser.contents, 'Logout status message not displayed.') def test_initiallogin_adapter(self): # Register our redirect adapter from zope.component import getGlobalSiteManager gsm = getGlobalSiteManager() gsm.registerAdapter(InitialLoginAdapter, (Interface, IRequest)) self.browser.open('http://nohost/plone/login') self.browser.getLink('Log in').click() self.assertEqual(self.browser.url, 'http://nohost/plone/login') self.browser.getControl('Login Name').value = TEST_USER_NAME self.browser.getControl('Password').value = TEST_USER_PASSWORD self.browser.getControl(name='came_from').value = \ 'http://nohost/plone/contact-info' self.browser.getControl('Log in').click() gsm.unregisterAdapter(InitialLoginAdapter, (Interface, IRequest)) self.assertIn('You are now logged in.', self.browser.contents) self.assertEqual(self.browser.url, 'http://nohost/plone/contact-info') self.assertEqual(self.portal.foo, 'foo') # Now log out. self.browser.getLink('Log out').click() self.assertIn('You are now logged out.', self.browser.contents, 'Logout status message not displayed.')
class TestCopyPermissions(unittest.TestCase): layer = FTW_PERMISSIONMANAGER_INTEGRATION_TESTING def setUp(self): self.browser = Browser(self.layer['app']) self.browser.handleErrors = False def test_copy_permission_view(self): portal = self.layer['portal'] view = getMultiAdapter( (portal.folder1, portal.folder1.REQUEST), name="copy_user_permissions") self.assertTrue(view.__name__ == 'copy_user_permissions') def test_copy_permission_form_user(self): portal = self.layer['portal'] portal_url = portal.absolute_url() # Set local roles for test user portal.portal_membership.setLocalRoles( obj=portal.folder1, member_ids=[TEST_USER_ID], member_role="Contributor", reindex=True) portal.folder1.reindexObjectSecurity() portal.portal_membership.setLocalRoles( obj=portal.folder1.folder2, member_ids=[TEST_USER_ID], member_role="Editor", reindex=True) portal.folder1.folder2.reindexObjectSecurity() transaction.commit() # for test self.browser # Login as test user self.browser.open(portal_url + '/login_form') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() self.browser.open(portal_url + '/folder1/copy_user_permissions') # Look for the right form self.assertIn( '<form method="post" action="http://nohost/plone/folder1/' '@@copy_user_permissions">', self.browser.contents) # Search for the test user self.browser.getControl(name="search_source_user").value = TEST_USER_ID self.browser.getControl(name="submit").click() self.assertIn( '<a href="http://nohost/plone/folder1/@@copy_user_permissions?' 'source_user=test_user_1_">test_user_1_</a>', self.browser.contents) # Choose user self.browser.open('http://nohost/plone/folder1/@@copy_user_' 'permissions?source_user=test_user_1_') self.assertIn( '<input type="hidden" name="source_user" value="test_user_1_" />', self.browser.contents ) # Choose target user self.browser.getControl( name="search_target_user").value = TEST_USER_ID_2 self.browser.getControl(name="submit").click() self.assertIn( '<a href="http://nohost/plone/folder1/@@copy_user_permissions?' 'target_user=_test_user_2_&source_user=test_user_1_">' '_test_user_2_</a>', self.browser.contents ) self.browser.open('http://nohost/plone/folder1/@@copy_user_' 'permissions?target_user=_test_user_2_&' 'source_user=test_user_1_') # Confirm link self.assertIn( '<a class="context" href="http://nohost/plone/folder1/@@copy_' 'user_permissions?source_user=test_user_1_&target_user='******'_test_user_2_&confirm=1">', self.browser.contents) # Abort link self.assertIn( '<a class="standalone" href="http://nohost/plone/folder1/' '@@copy_user_permissions">', self.browser.contents) self.browser.open('http://nohost/plone/folder1/@@copy_user_' 'permissions?source_user=test_user_1_&target_' 'user=_test_user_2_&confirm=1') # After permission copy, redirect to copy permission view again self.assertIn( 'class="template-copy_user_permissions', self.browser.contents) # Approve if test user 2 has the same local roles self.assertTrue( portal.folder1.get_local_roles_for_userid(TEST_USER_ID_2) == ('Owner', 'Contributor')) self.assertFalse( portal.folder1.get_local_roles_for_userid(TEST_USER_ID_2) == ('Owner', 'Editor')) def test_copy_permission_form_group(self): portal = self.layer['portal'] portal_url = portal.absolute_url() # Set up two groups portal.portal_groups.addGroup(TEST_GROUP_ID) portal.portal_groups.addGroup(TEST_GROUP_ID_2) # Add local roles portal.folder1.manage_addLocalRoles(TEST_GROUP_ID, ['Contributor', ]) portal.folder1.reindexObjectSecurity() portal.folder1.folder2.manage_addLocalRoles(TEST_GROUP_ID, ['Editor', ]) portal.folder1.folder2.reindexObjectSecurity() transaction.commit() # for test self.browser # Login as test user self.browser.open(portal_url + '/login_form') self.browser.getControl(name='__ac_name').value = TEST_USER_NAME self.browser.getControl( name='__ac_password').value = TEST_USER_PASSWORD self.browser.getControl(name='submit').click() self.browser.open(portal_url + '/folder1/copy_user_permissions') # Look for the right form self.assertIn( '<form method="post" action="http://nohost/plone/folder1/' '@@copy_user_permissions">', self.browser.contents) # Search for the test group self.browser.getControl( name="search_source_user").value = TEST_GROUP_ID self.browser.getControl(name="submit").click() self.assertIn( '<a href="http://nohost/plone/folder1/@@copy_user_permissions?' 'source_user=test_group">test_group</a>', self.browser.contents) # Choose group self.browser.open('http://nohost/plone/folder1/@@copy_user_' 'permissions?source_user=test_group') self.assertIn( '<input type="hidden" name="source_user" value="test_group" />', self.browser.contents ) # Choose target user self.browser.getControl( name="search_target_user").value = TEST_GROUP_ID_2 self.browser.getControl(name="submit").click() self.assertIn( '<a href="http://nohost/plone/folder1/@@copy_user_permissions?' 'target_user=test_group_2&source_user=test_group">' 'test_group_2</a>', self.browser.contents ) self.browser.open('http://nohost/plone/folder1/@@copy_user_' 'permissions?target_user=test_group_2' '&source_user=test_group') # Confirm link self.assertIn( '<a class="context" href="http://nohost/plone/folder1/@@copy_' 'user_permissions?source_user=test_group&target_user='******'test_group_2&confirm=1">', self.browser.contents) # Abort link self.assertIn( '<a class="standalone" href="http://nohost/plone/folder1/' '@@copy_user_permissions">', self.browser.contents) self.browser.open('http://nohost/plone/folder1/@@copy_user_' 'permissions?source_user=test_group&target_user='******'test_group_2&confirm=1') # After permission copy, redirect to copy permission view again self.assertIn( 'class="template-copy_user_permissions', self.browser.contents) for id_, roles in dict(portal.folder1.get_local_roles()).items(): if id_ == TEST_GROUP_ID_2: break self.assertIn('Contributor', roles) results = dict(portal.folder1.folder2.get_local_roles()).items() for id_, roles in results: if id_ == TEST_GROUP_ID_2: break self.assertIn('Editor', roles)
def test_personalized(self): self.portal.error_log._ignored_exceptions = () browser = Browser(self.app) portal_url = self.portal.absolute_url() # Get an account and login via the login form. browser.open(portal_url + '/login_form') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl(name='submit').click() # Create a blank page for test edits. (front-page is too noisy.) testpage = self.portal.absolute_url( ) + '/' + self.portal.invokeFactory('Document', 'testpage') + '/edit' self.assertEqual(testpage, 'http://nohost/plone/testpage/edit') transaction.commit() # Set up personalize_form personalizer = portal_url + '/personalize_form' self.assertEqual(personalizer, 'http://nohost/plone/personalize_form') browser.open(personalizer) browser.getControl(name='email').value = '*****@*****.**' browser.getControl(name='form.button.Save').click() self.assertIn('<dd>Your personal settings have been saved.</dd>', browser.contents) #Test different editors #---------------------- #Which editor is used is set globally and can be overridden in the personal preferences. #This results in the following matrix: #===== ===== ====== #Global Personal Expected #===== ===== ====== #TinyMCE Use site's default TinyMCE #TinyMCE None Basic textarea #TinyMCE TinyMCE TinyMCE #<empty> Use site's default Basic textarea #<empty> None Basic textarea #<empty> TinyMCE TinyMCE #===== ===== ====== # Set the editor globally to TinyMCE: self.portal.portal_properties.site_properties.default_editor = 'TinyMCE' transaction.commit() # If the user sets 'Use site's default'... browser.open(personalizer) browser.getControl(name='wysiwyg_editor').value = [''] browser.getControl(name='form.button.Save').click() self.assertIn('<dd>Your personal settings have been saved.</dd>', browser.contents) # we should get TinyMCE: browser.open(testpage) self.assertIn('TinyMCEConfig', browser.contents) # If the user sets 'None'... browser.open(personalizer) browser.getControl(name='wysiwyg_editor').value = ['None'] browser.getControl(name='form.button.Save').click() self.assertIn('<dd>Your personal settings have been saved.</dd>', browser.contents) # We should get just a textarea: browser.open(testpage) self.assertIn('<textarea name="text" rows="25" id="text"', browser.contents) # If the user sets 'TinyMCE'... browser.open(personalizer) browser.getControl(name='wysiwyg_editor').value = ['TinyMCE'] browser.getControl(name='form.button.Save').click() self.assertIn('<dd>Your personal settings have been saved.</dd>', browser.contents) # we should get TinyMCE: browser.open(testpage) self.assertIn('TinyMCEConfig', browser.contents) # Set the editor globally to nothing: self.portal.portal_properties.site_properties.default_editor = '' transaction.commit() # If the user sets 'Use site's default'... browser.open(personalizer) browser.getControl(name='wysiwyg_editor').value = [''] browser.getControl(name='form.button.Save').click() self.assertIn('<dd>Your personal settings have been saved.</dd>', browser.contents) # we should get just a textarea: browser.open(testpage) self.assertIn('<textarea name="text" rows="25" id="text"', browser.contents) # If the user sets 'None'... browser.open(personalizer) browser.getControl(name='wysiwyg_editor').value = ['None'] browser.getControl(name='form.button.Save').click() self.assertIn('<dd>Your personal settings have been saved.</dd>', browser.contents) # we should get just a textarea: browser.open(testpage) self.assertIn('<textarea name="text" rows="25" id="text"', browser.contents) # If the user sets 'TinyMCE'... browser.open(personalizer) browser.getControl(name='wysiwyg_editor').value = ['TinyMCE'] browser.getControl(name='form.button.Save').click() self.assertIn('<dd>Your personal settings have been saved.</dd>', browser.contents) # we should get TinyMCE: browser.open(testpage) self.assertIn('TinyMCEConfig', browser.contents)
def test_tinymce_configuration(self): # Let's get the configuration of TinyMCE and see if it returns a json structure. self.assertTrue(self.utility.getConfiguration(self.portal)) # Now let's change some variables and see it still works. self.utility.toolbar_cut = True self.utility.toolbar_copy = True self.utility.toolbar_paste = True self.utility.toolbar_pastetext = True self.utility.toolbar_pasteword = True self.utility.toolbar_undo = True self.utility.toolbar_redo = True self.utility.toolbar_search = True self.utility.toolbar_replace = True self.utility.toolbar_underline = True self.utility.toolbar_strikethrough = True self.utility.toolbar_sub = True self.utility.toolbar_sup = True self.utility.toolbar_forecolor = True self.utility.toolbar_backcolor = True self.utility.toolbar_media = True self.utility.toolbar_charmap = True self.utility.toolbar_hr = True self.utility.toolbar_advhr = True self.utility.toolbar_insertdate = True self.utility.toolbar_inserttime = True self.utility.toolbar_emotions = True self.utility.toolbar_nonbreaking = True self.utility.toolbar_pagebreak = True self.utility.toolbar_print = True self.utility.toolbar_preview = True self.utility.toolbar_spellchecker = True self.utility.toolbar_removeformat = True self.utility.toolbar_cleanup = True self.utility.toolbar_visualaid = True self.utility.toolbar_visualchars = True self.utility.toolbar_attribs = True self.utility.resizing = False # The result should at least contain the new buttons we added. self.assertRegexpMatches(self.utility.getConfiguration(self.portal), '\{.+attribs.+}') # Let's change some more settings. self.utility.toolbar_external = True self.utility.autoresize = True self.utility.editor_width = u'100' self.utility.editor_height = u'abc' self.utility.toolbar_width = u'abc' self.utility.contextmenu = False self.utility.content_css = u'test.css' self.utility.link_using_uids = True self.utility.allow_captioned_images = True self.utility.rooted = True props = getToolByName(self, 'portal_properties') livesearch = props.site_properties.getProperty('enable_livesearch', False) livesearch = False livesearch # pep8 # The result should contain the settings specified. self.assertRegexpMatches(self.utility.getConfiguration(self.portal), '\{.+external.+}') # Let's call the portal_factory of a document and make sure the configuration # doesn't contain the save button: browser = Browser(self.app) self.app.acl_users.userFolderAddUser('root', 'secret', ['Manager'], []) transaction.commit() browser.addHeader('Authorization', 'Basic root:secret') browser.open('http://nohost/plone/createObject?type_name=Document') self.assertNotIn(""save":", browser.contents) # Do some more toolbar tests, specifically testing the spellchecker button. # First, we make sure that no spellchecker is loaded when the toolbar button is # hidden. self.utility.toolbar_spellchecker = False transaction.commit() browser.open('http://nohost/plone/createObject?type_name=Document') # AtD shouldn't be there: self.assertNotIn(""AtD"", browser.contents) # Neither should iespell: self.assertNotIn(""iespell"", browser.contents) # When we have browser as the checker, neither iespell nor AtD should load: self.utility.libraries_spellchecker_choice = u'browser' transaction.commit() browser.open('http://nohost/plone/createObject?type_name=Document') self.assertNotIn(""iespell"", browser.contents) self.assertNotIn(""AtD"", browser.contents)
def test_remove_permission_form_user(self): portal = self.layer['portal'] portal_url = portal.absolute_url() portal.portal_membership.setLocalRoles( obj=portal.folder1, member_ids=[TEST_USER_ID], member_role="Contributor", reindex=True) portal.portal_membership.setLocalRoles( obj=portal.folder1.folder2, member_ids=[TEST_USER_ID], member_role="Editor", reindex=True) browser = Browser(self.layer['app']) # Login as test user browser.open(portal_url + '/login_form') browser.getControl(name='__ac_name').value = TEST_USER_NAME browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD browser.getControl(name='submit').click() browser.open(portal_url + '/folder1/remove_user_permissions') # Look for the right form self.assertIn( '<form method="post" action="http://nohost/plone/folder1/@@remove_user_permissions">', browser.contents ) # Search for a user, there should be the test user browser.getControl(name="search_term").value = TEST_USER_ID browser.getControl(name="form.button.Search").click() self.assertIn( '<a href="http://nohost/plone/folder1/@@remove_user_permissions?user=test_user_1_">test_user_1_</a>', browser.contents ) # Choose user browser.open('http://nohost/plone/folder1/@@remove_user_permissions?user=test_user_1_') # Confirm link self.assertIn( '<a class="context" href="http://nohost/plone/folder1/@@remove_user_permissions?user=test_user_1_&confirmed=1">', browser.contents ) # Abort link self.assertIn( '<a class="standalone" href="http://nohost/plone/folder1/@@remove_user_permissions">', browser.contents ) # Confirm removal of roles for the test user browser.open('http://nohost/plone/folder1/@@remove_user_permissions?user=test_user_1_&confirmed=1') # After removal, redirect to permission manager overview self.assertIn( 'class="template-permission_manager', browser.contents) # Approve if user has no local roles on folder1 and folder2 self.assertFalse( TEST_USER_ID in dict(portal.folder1.get_local_roles())) self.assertFalse( TEST_USER_ID in dict(portal.folder1.folder2.get_local_roles()))