Exemplo n.º 1
0
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
    def test_createplugin(self):
        from plone.app.testing import TEST_USER_ID, TEST_USER_NAME, \
            TEST_USER_PASSWORD
        from plone.app.testing import setRoles, login

        login(self.portal, TEST_USER_NAME)
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        transaction.commit()

        from plone.testing.z2 import Browser
        browser = Browser(self.app)
        browser.addHeader('Authorization',
                          'Basic %s:%s' % (TEST_USER_NAME,
                                           TEST_USER_PASSWORD))
        browser.open(self.portal.absolute_url() + '/@@cas_control_panel')

        #The plugin should not yet exist
        self.assertNotIn('cas', self.portal.acl_users)

        browser.getControl('Recreate Plugin').click()

        #The plugin now exists post button press
        self.assertIn('cas', self.portal.acl_users)

        #Ensure plugin can be recreated if broken
        cas = self.portal.acl_users.cas
        cas.login_url = 'dummy'
        browser.getControl('Recreate Plugin').click()

        #Should be the default URL, not dummy
        self.assertEqual(self.portal.acl_users.cas.login_url,
                         'https://your.cas.server:port/cas/login')
class NewsItemFunctionalTest(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_news_item(self):
        self.browser.open(self.portal_url)
        self.browser.getLink('News Item').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 news item"
        self.browser.getControl(name='form.widgets.IDublinCore.description')\
            .value = "This is my news item."
        self.browser.getControl(name='form.widgets.text')\
            .value = "Lorem Ipsum"
        self.browser.getControl('Save').click()
        self.assertTrue(self.browser.url.endswith('my-news-item/view'))
        self.assertTrue('My news item' in self.browser.contents)
        self.assertTrue('This is my news item' in self.browser.contents)
        self.assertTrue('Lorem Ipsum' in self.browser.contents)
    def test_controlpanel(self):

        self._reinstall()

        browser = Browser(self.app)

        # Login as site owner
        browser.open('{0}/login_form'.format(self.portal.absolute_url()))
        browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
        browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD
        browser.getControl(name='submit').click()
  
        browser.open('{0}/@@overridemailrecipients-settings'.format(self.portal.absolute_url()))
        self.assertEqual(
            browser.headers['status'], '200 Ok',
            u'Control panel is not available'
        )

        # Change mail address
        browser.getControl(label='Email address').value = u'*****@*****.**'
        browser.getControl(label='Save').click()

        # Disable override
        browser.open('{0}/@@overridemailrecipients-settings'.format(self.portal.absolute_url()))
        browser.getControl(label='Enabled').selected=False
        browser.getControl(label='Save').click()
        self.assertEqual(get_mail_address(), None)
    def _reinstall(self):
        """ We must uninstall and install the package, it seems generic setup profile
        is not applied coorectly by plone.app.testing in this testing layer.
        """

        browser = Browser(self.app)

        # Login as site owner
        browser.open('{0}/login_form'.format(self.portal.absolute_url()))
        browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
        browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD
        browser.getControl(name='submit').click()

        # We must uninstall and install the package, it seems generic setup profile
        # is not applied coorectly by plone.app.testing in this testing layer.
        browser.open('{0}/prefs_install_products_form'.format(self.portal.absolute_url()))

        form = browser.getForm(index=2)
        self.assertEqual(
            form.action, '{0}/portal_quickinstaller'.format(self.portal.absolute_url()),
            u'Uninstall form not found')
        form.getControl(name='products:list').value = (u"collective.overridemailrecipients",)
        form.getControl(label='Deactivate').click()

        form = browser.getForm(index=1)
        self.assertEqual(
            form.action, '{0}/portal_quickinstaller/installProducts'.format(self.portal.absolute_url()),
            u'Install form not found')
        form.getControl(name='products:list').value = (u"collective.overridemailrecipients",)
        form.getControl(label='Activate').click()
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
class TestBlogEntry(TestCase):

    layer = FTW_BLOG_FUNCTIONAL_TESTING

    def setUp(self):
        super(TestBlogEntry, self).setUp()

        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.browser.addHeader(
            'Authorization', 'Basic %s:%s' % (
                TEST_USER_NAME,
                TEST_USER_PASSWORD,
            ))

        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])

        self.blog = self.portal.get(self.portal.invokeFactory('Blog', 'blog'))
        transaction.commit()

    def test_add_blog_entry(self):
        self.browser.open("%s/createObject?type_name=BlogEntry" %
                          self.blog.absolute_url())
        self.browser.getControl(name='title').value = 'Blog Entry'
        self.browser.getControl(name='form.button.save').click()

        self.assertEquals(len(self.blog.objectIds()), 1,
                          'Expect one blog entry')

        doc = PyQuery(self.browser.contents)
        self.assertEquals(
            doc('.documentFirstHeading').text(), 'Blog Entry',
            'Wrong title found')
Exemplo n.º 8
0
class AutoRotateTests(unittest.TestCase):
    layer = PROTECT_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.browser = Browser(self.layer['app'])
        self.request = self.layer['request']

    def test_keyrings_get_rotated_on_login(self):
        manager = getUtility(IKeyManager)
        ring = manager['_forms']
        keys = ring.data
        ring.last_rotation = 0
        transaction.commit()

        # should be rotated on login
        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()

        self.assertNotEqual(keys, ring.data)
        self.assertNotEqual(ring.last_rotation, 0)
class TestNewsletterView(unittest.TestCase):

    layer = COLLECTIVE_MAILCHIMP_INTEGRATION_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_empty_form(self):
        self.browser.open("%s/newsletter" % self.portal_url)
        self.browser.getControl(name="form.buttons.subscribe").click()
        self.assertTrue("Required input is missing." in self.browser.contents)

    def test_form_with_invalid_email_address(self):
        self.browser.open("%s/newsletter" % self.portal_url)
        self.browser.getControl(name="form.widgets.email").value = "Not an email address"
        self.browser.getControl(name="form.buttons.subscribe").click()
        self.assertTrue("Invalid email address" in self.browser.contents)

    def test_form_with_valid_email_address(self):
        # XXX: Not working. We need a mock mailchimp service
        # self.browser.open("%s/newsletter" % self.portal_url)
        # self.browser.getControl(name="form.widgets.email").value = \
        #    "*****@*****.**"
        # self.browser.getControl(name="form.buttons.subscribe").click()
        pass
Exemplo n.º 10
0
class AutoRotateTests(unittest.TestCase):
    layer = PROTECT_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.browser = Browser(self.layer['app'])
        self.request = self.layer['request']

    def test_keyrings_get_rotated_on_login(self):
        manager = getUtility(IKeyManager)
        ring = manager['_forms']
        keys = ring.data
        ring.last_rotation = 0
        transaction.commit()

        # should be rotated on login
        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()

        self.assertNotEqual(keys, ring.data)
        self.assertNotEqual(ring.last_rotation, 0)
Exemplo n.º 11
0
    def testquestion(self):
        app = self.layer['app']        
        portal = self.layer['portal']
        
        browser = Browser(app)
        browser.handleErrors = False
        
        browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))
        import transaction
        transaction.commit()
        
        ques = portal['questionfolder']['question'].absolute_url()
        browser.open(ques)
        
        browser.getControl(name='form.submit').click()
        
        open('/tmp/test.html','w').write(browser.contents)
        
        self.assertTrue("question" in browser.contents)
        self.assertTrue("question description" in browser.contents)
        
        self.assertTrue("4" in browser.contents)

        self.assertTrue("test_user_1_" in browser.contents)
        self.assertTrue("defaultUser.png" in browser.contents)
        
        self.assertTrue("answerone" in browser.contents)
        
        self.assertTrue("answertwo" in browser.contents)
        self.assertTrue("answerthree" in browser.contents)
        self.assertTrue("add an answer" in browser.contents)
Exemplo n.º 12
0
 def test_navigate_save(self):
     from zope.component import getUtility
     from plone.registry.interfaces import IRegistry
     from my315ok.products.interfaces import IMy315okProductsSettings
     
     app = self.layer['app']
     portal = self.layer['portal']
     
     browser = Browser(app)
     browser.handleErrors = False
     
     # Simulate HTTP Basic authentication
     browser.addHeader('Authorization',
             'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)
         )
     
     # Open Plone's site setup
     browser.open("%s/plone_control_panel" % portal.absolute_url())
     
     # Go to the control panel
     browser.getLink('My315okProducts settings').click()
     
     # Edit the DAM codes field
     browser.getControl(name='form.widgets.wordsNum').value = "32"
     browser.getControl('Save').click()
     
     # Verify that this made it into the registry
     registry = getUtility(IRegistry)
     settings = registry.forInterface(IMy315okProductsSettings)
     self.assertEqual(settings.wordsNum,32)
Exemplo n.º 13
0
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_pyfile(self):
        self.browser.open(self.portal_url)

        self.browser.getLink('CodeFile').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__), "temp.py")
        file_ctl = self.browser.getControl(name='form.widgets.file')
        file_ctl.add_file(open(file_path), 'image/png', 'temp.py')
        self.browser.getControl('Save').click()
        self.assertTrue(self.browser.url.endswith('temp.py/view'))
        self.assertTrue('My file' in self.browser.contents)
        self.assertTrue('This is my file' in self.browser.contents)
Exemplo n.º 14
0
class TestControlPanel(unittest.TestCase):

    layer = THEMING_FUNCTIONAL_TESTING

    def setUp(self):
        portal = self.layer['portal']
        setRoles(portal, TEST_USER_ID, ['Manager'])
        import transaction
        transaction.commit()

        self.portal = portal
        self.browser = Browser(self.layer['app'])

        handleErrors = self.browser.handleErrors
        try:
            self.browser.handleErrors = False
            self.browser.open(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()
        finally:
            self.browser.handleErrors = handleErrors

    def goto_controlpanel(self):
        self.browser.open(self.portal.absolute_url() + '/@@theming-controlpanel')

    def test_create_theme(self):
        pass
class LeadImageBehaviorFunctionalTest(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, ['Contributor'])
        fti = DexterityFTI('leadimagefolder')
        self.portal.portal_types._setObject('leadimagefolder', fti)
        fti.klass = 'plone.dexterity.content.Container'
        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('leadimagefolder',
                                  id='leadimagefolder',
                                  title=u'Folder with a lead image')
        import transaction
        transaction.commit()
        # Set up browser
        self.browser = Browser(app)
        self.browser.handleErrors = False
        self.browser.addHeader(
            'Authorization', 'Basic {0}:{1}'.format(
                SITE_OWNER_NAME,
                SITE_OWNER_PASSWORD,
            ))

    def test_lead_image_in_edit_form(self):
        self.browser.open(self.portal_url + '/leadimagefolder/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 + '/leadimagefolder/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(io.FileIO(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)

        # But doesn't show up on folder_contents, which is not a default view
        self.browser.open(self.portal_url + '/leadimagefolder/folder_contents')
        self.assertTrue('<div class="leadImage">' not in self.browser.contents)
Exemplo n.º 16
0
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()
        self.browser = Browser(app)
        self.browser.handleErrors = False
        self.browser.addHeader(
            'Authorization',
            'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)
        )

    def test_add_document(self):
        self.browser.open(self.portal_url)
        self.browser.getLink(url='http://nohost/plone/++add++Document').click()
        self.browser.getControl(name='form.widgets.IDublinCore.title')\
            .value = "My document"
        self.browser.getControl(name='form.widgets.IDublinCore.description')\
            .value = "This is my document."
        self.browser.getControl(name='form.widgets.IRichText.text')\
            .value = "Lorem Ipsum"
        # self.browser.getControl(name='form.widgets.IShortName.id')\
        #     .value = "my-special-document"
        self.browser.getControl('Save').click()
        self.assertTrue(self.browser.url.endswith('my-document/view'))
        self.assertTrue('My document' in self.browser.contents)
        self.assertTrue('This is my document' in self.browser.contents)
        self.assertTrue('Lorem Ipsum' in self.browser.contents)
Exemplo n.º 17
0
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
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
class TestNewsletterView(unittest.TestCase):

    layer = COLLECTIVE_MAILCHIMP_INTEGRATION_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_empty_form(self):
        self.browser.open("%s/newsletter" % self.portal_url)
        self.browser.getControl(name="form.buttons.subscribe").click()
        self.assertTrue("Required input is missing." in self.browser.contents)

    def test_form_with_invalid_email_address(self):
        self.browser.open("%s/newsletter" % self.portal_url)
        self.browser.getControl(name="form.widgets.email").value = \
            "Not an email address"
        self.browser.getControl(name="form.buttons.subscribe").click()
        self.assertTrue("Invalid email address" in self.browser.contents)
class TestNewsletterExtender(unittest.TestCase):

    layer = COLLECTIVE_MAILCHIMP_INTEGRATION_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),
        )
        provideAdapter(factory=TestExtender)

    def test_newsletter_extender(self):
        self.browser.open("%s/newsletter" % self.portal_url)
        self.browser.getControl(
            name="form.widgets.email"
        ).value = "*****@*****.**"
        self.browser.getControl(name="form.buttons.subscribe").click()
        self.assertTrue(
            "Required test field not checked" in self.browser.contents
        )
Exemplo n.º 21
0
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
        )
Exemplo n.º 22
0
class ConflictTests(TestCase):

    layer = LEGACY_COLLECTIVE_SOLR_FUNCTIONAL_TESTING

    def setUp(self):
        activateAndReindex(self.layer['portal'])
        commit()
        self.browser = Browser(self.layer['app'])
        self.browser.addHeader(
            'Authorization', 'Basic %s:%s' % (
                SITE_OWNER_NAME,
                SITE_OWNER_PASSWORD,
            ))

    def test_retry_on_conflict(self):
        self.browser.open(self.layer['portal'].absolute_url())
        self.browser.getLink('Page').click()
        self.browser.getControl('Title', index=0).value = 'Foo'
        component.provideHandler(raise_on_first_add, (
            Interface,
            IObjectCreatedEvent,
        ))
        self.browser.getControl('Save').click()
        self.assertEqual(len(UIDS), 2)
        self.assertEqual(len(solrSearchResults(SearchableText='Foo')), 1)

        sm = component.getSiteManager()
        sm.unregisterHandler(raise_on_first_add, (
            Interface,
            IObjectCreatedEvent,
        ))
Exemplo n.º 23
0
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 _install(self):

        browser = Browser(self.app)

        # Login as site owner
        browser.open('{0}/login_form'.format(self.portal.absolute_url()))
        browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
        browser.getControl(name='__ac_password').value = SITE_OWNER_PASSWORD
        browser.getControl(name='submit').click()

        # We must uninstall and install the package, it seems generic setup profile
        # is not applied coorectly by plone.app.testing in this testing layer.
        browser.open('{0}/prefs_install_products_form'.format(self.portal.absolute_url()))

        form = browser.getForm(index=1)
        self.assertEqual(
            form.action, '{0}/portal_quickinstaller/installProducts'.format(self.portal.absolute_url()),
            u'Install form not found')
        products_list = form.getControl(name='products:list')
        install_products = [
            u"redomino.advancedkeyword",
            u"eea.facetednavigation",
            u"eea.facetednavigationtaxonomiccheckbox",
        ]
        for product in install_products:
            if product in products_list.options:
                products_list.value = (product,)
                form.getControl(label='Activate').click()
        browser.open(self.portal.absolute_url() + '/logout')
Exemplo n.º 25
0
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.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('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)
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)
Exemplo n.º 27
0
    def test_send_subscriber(self):
        self.gfolder.invokeFactory('gazette.GazetteIssue', 'issue')
        issue = self.gfolder['issue']
        issue.title = u'Test issue'
        issue.text = RichTextValue('Hello world!')

        request = self.request
        adapter = getMultiAdapter((self.gfolder, request), IGazetteSubscription)
        adapter.subscribe('*****@*****.**', '')

        # activation message
        self.failUnless(len(self.mailhost.messages) == 1)

        # Activate subsriber
        soup = getSoup(self.context, config.SUBSCRIBERS_SOUP_ID)
        s = soup.query(email='*****@*****.**').next()
        s.active = True
        s.key = u''
        soup.reindex([s])

        transaction.commit()
        browser = Browser(self.layer['app'])
        browser.handleErrors = False
        browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))

        browser.open(issue.absolute_url() + '/send')
        self.failUnless('Number of subscribers: 1' in browser.contents)
        browser.getControl(name='submit').click()
        self.failUnless('Gazette has been sent to 1 recipients' in browser.contents)
        # activation + issue
        self.failUnless(len(self.mailhost.messages) == 2)
Exemplo n.º 28
0
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)
Exemplo n.º 29
0
class TestBlogEntry(TestCase):

    layer = FTW_BLOG_FUNCTIONAL_TESTING

    def setUp(self):
        super(TestBlogEntry, self).setUp()

        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.browser.addHeader(
            'Authorization',
            'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))

        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])

        self.blog = self.portal.get(self.portal.invokeFactory('Blog', 'blog'))
        transaction.commit()

    def test_add_blog_entry(self):
        self.browser.open(
            "%s/createObject?type_name=BlogEntry" % self.blog.absolute_url())
        self.browser.getControl(name='title').value = 'Blog Entry'
        self.browser.getControl(name='form.button.save').click()

        self.assertEquals(len(self.blog.objectIds()), 1,
                          'Expect one blog entry')

        doc = PyQuery(self.browser.contents)
        self.assertEquals(doc('.documentFirstHeading').text(), 'Blog Entry',
                          'Wrong title found')
    def test_can_enter_changenote(self):
        browser = Browser(self.layer['app'])
        portal = self.layer['portal']
        setRoles(portal, TEST_USER_ID, ('Member', 'Manager'))
        document = createObject(portal,
                                "Document",
                                "changenote_transition_doc",
                                delete_first=True,
                                title="Workflow note")
        transaction.commit()

        browser_login(portal, browser)
        browser.open(document.absolute_url())
        browser.getLink("Manage page").click()
        browser.getLink("Public draft").click()
        workflow_actions = browser.getControl(
            name="form.widgets.workflow_action:list")
        workflow_actions.getControl(value="publish").click()
        # We set up a comment this time
        browser.getControl(name="form.widgets.comment").value = "wibble fkjwel"
        browser.getControl("Save").click()

        # and it shows up in the workflow history
        self.assertEqual(
            "publish",
            document.workflow_history['plone_workflow'][-1]['action'])
        self.assertEqual(
            "wibble fkjwel",
            document.workflow_history['plone_workflow'][-1]['comments'])
Exemplo n.º 31
0
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)
Exemplo n.º 32
0
class TestYourMessagesView(unittest.TestCase):

    layer = PLONEINTRANET_MESSAGING_FUNCTIONAL_TESTING

    def setUp(self):
        self.app = self.layer["app"]
        self.portal = self.layer["portal"]
        self.portal_url = self.portal.absolute_url()
        self.request = self.layer["request"]
        self.browser = Browser(self.app)
        self.browser.handleErrors = False
        api.user.create(
            username="******", email="*****@*****.**", password="******", properties={"fullname": "Test User 1"}
        )
        api.user.create(
            username="******", email="*****@*****.**", password="******", properties={"fullname": "Test User 2"}
        )
        transaction.commit()

    def _create_message(self, from_, to, text, created=now):
        inboxes = self.portal.ploneintranet_messaging
        inboxes.send_message(from_, to, text, created=created)
        transaction.commit()

    def _login(self, username, password):
        # Go admin
        self.browser.open(self.portal_url + "/login_form")
        self.browser.getControl(name="__ac_name").value = username
        self.browser.getControl(name="__ac_password").value = password
        self.browser.getControl(name="submit").click()

    def _logout(self):
        self.browser.open(self.portal_url + "/logout")

    def test_inbox_in_actions(self):
        # we've added an inbox link to the actions.xml,
        # It should appear once logged in.
        self.browser.open(self.portal_url)
        self.assertNotIn("personaltools-plone_social_menu", self.browser.contents)
        self._login("testuser1", "testuser1")
        self.browser.open(self.portal_url)
        self.assertIn("personaltools-plone_social_menu", self.browser.contents)

    @unittest.expectedFailure
    def test_unread_messages(self):
        # lets return a count to see if there are any unread messages
        self.browser.open(self.portal_url + "/@@your-messages")
        # lets checked when not logged in
        self.assertNotIn('id="your-messages"', self.browser.contents)
        # lets login and create a message
        self._login("testuser1", "testuser1")
        self._create_message("testuser2", "testuser1", "Message Text", created=now)
        self.browser.open(self.portal_url + "/@@your-messages")
        self.assertIn('id="your-messages"', self.browser.contents)
        self.assertIn("1", self.browser.contents)
        self._logout()
        self._login("testuser2", "testuser2")
        self.browser.open(self.portal_url + "/@@your-messages")
        self.assertNotIn('id="your-messages"', self.browser.contents)
        self.assertNotIn("1", self.browser.contents)
Exemplo n.º 33
0
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)
Exemplo n.º 34
0
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_alternative_mime_icon_doc_for_file(self):
        provideAdapter(AssignRoles)
        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)
Exemplo n.º 35
0
    def test_create_new_template(self):
        portal = self.layer['portal']
    
        browser = Browser(portal)
        browser.handleErrors = False
        browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))
        browser.open('http://nohost/plone/test-repository/++add++collective.chimpdrill.template')
    
        browser.getControl(name='form.widgets.upload_title').value = "Test Template 3"
        browser.getControl(name='form.widgets.template_code').value = MC_TEMPLATE_HTML
        browser.getControl(name='form.widgets.description').value = u"Test Upload Description"
        browser.getControl(name='form.widgets.email_subject').value = u"Test Template 3 Subject"
        browser.getControl(name='form.widgets.from_email').value = u"*****@*****.**"
        browser.getControl(name='form.widgets.from_name').value = u"Jack Black"
        browser.getControl(name='form.buttons.save').click()
    
        self.assertEqual("http://nohost/plone/test-repository/test-template-3/view", browser.url)
        self.assertTrue('Test Template 3' in browser.contents)
        self.assertTrue('Test Upload Description' in browser.contents)

        template = portal.unrestrictedTraverse('test-repository/test-template-3')
        self.assertEqual(template.mandrill_template, 'mailchimp-3')
        self.assertEqual(template.mandrill_template_info['name'], 'mailchimp-3')
        self.assertEqual(template.mailchimp_template_info['name'], 'Test Template 3')

        browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))
        browser.open('http://nohost/plone/test-repository/test-template-3/preview')

        browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))
        browser.open('http://nohost/plone/test-repository/test-template-3/send_email')
        browser.getControl(name='form.widgets.send_to')
Exemplo n.º 36
0
class ConflictTests(TestCase):

    layer = LEGACY_COLLECTIVE_SOLR_FUNCTIONAL_TESTING

    def setUp(self):
        activateAndReindex(self.layer['portal'])
        commit()
        self.browser = Browser(self.layer['app'])
        self.browser.addHeader(
            'Authorization',
            'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)
        )

    def test_retry_on_conflict(self):
        self.browser.open(self.layer['portal'].absolute_url())
        self.browser.getLink('Page').click()
        self.browser.getControl('Title', index=0).value = 'Foo'
        component.provideHandler(
            raise_on_first_add, (Interface, IObjectCreatedEvent,))
        self.browser.getControl('Save').click()
        self.assertEqual(len(UIDS), 2)
        self.assertEqual(len(solrSearchResults(SearchableText='Foo')), 1)

        sm = component.getSiteManager()
        sm.unregisterHandler(
            raise_on_first_add, (Interface, IObjectCreatedEvent,))
Exemplo n.º 37
0
class TestCSRF(unittest.TestCase):
    layer = PROTECT_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.browser = Browser(self.layer['app'])
        self.request = self.layer['request']
        self.browser.addHeader(
            'Authorization', 'Basic %s:%s' % (
                SITE_OWNER_NAME,
                SITE_OWNER_PASSWORD,
            ))

    def test_change_password_on_root_does_not_throw_other_csrf_protection(
            self):
        self.browser.open(
            '%s/acl_users/users/manage_users?user_id=%s&passwd=1' %
            (self.layer['app'].absolute_url(), SITE_OWNER_NAME))
        self.browser.getControl(name='password').value = SITE_OWNER_PASSWORD
        self.browser.getControl(name='confirm').value = SITE_OWNER_PASSWORD
        self.browser.getForm().submit()
        self.assertEquals(
            self.browser.url,
            '%s/acl_users/users/manage_users?manage_tabs_message=password+updated'
            % (self.layer['app'].absolute_url()))
 def test_login_portlet(self):
     browser = Browser(self.layer['portal'])
     # access the login screen and submit the login form
     browser.open('http://nohost/plone/login')
     browser.getControl('Log in').click()
     # make sure we were redirected to login_form with a failed message.
     self.assertEqual('http://nohost/plone/login_form', browser.url)
     self.assertTrue('Login failed' in browser.contents)
Exemplo n.º 39
0
class TestUserFunctional(FunctionalTestCase):
    """Testing user registration and fields."""
    def setUp(self):
        """Custom shared utility setup for tests."""
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.browser = Browser(self.portal)

        # prepare request values for the new LC
        self.request.form['form.widgets.city'] = u'Niš'
        self.request.form['form.widgets.cp_username'] = '******'
        self.request.form['form.widgets.cp_fullname'] = u'Jöhn Smith'
        self.request.form['form.widgets.cp_email'] = '*****@*****.**'

        # call the @@add-lc form to create us a new LC
        self.layer['portal'].restrictedTraverse('@@add-lc').create()

        # set CPs password
        cp = api.user.get(username='******')
        self.portal.acl_users._doChangeUser(cp.id, TEST_USER_PASSWORD,
                                            cp.getRoles())
        ### ARGH!!!! I hope the line above can be written with plone.api soon!

        # commit what we've done so testbrowser sees it
        import transaction
        transaction.commit()

    @unittest.expectedFailure
    def test_add_new_cp_member(self):
        """Test the LC Board can add a new member to their LC."""

        # Login as LC Boardie to add a new member
        self.login(username='******')

        # Go to form to add new member
        self.browser.open('http://nohost/plone/@@register')
        open('/tmp/testbrowser.html', 'w').write(self.browser.contents)

        # Fill out the form
        self.browser.getControl(name='form.username').value = 'jane'
        self.browser.getControl(name='form.email').value = '*****@*****.**'
        self.browser.getControl(name='form.mobile').value = '+386 666'
        self.browser.getControl(name='form.study_field').value = [
            'ece',
        ]
        self.browser.getControl(name='form.birthdate').value = '1985/01/01'
        self.browser.getControl(name='form.sex').value = [
            'female',
        ]
        self.browser.getControl(name='form.nationality').value = [
            'greece',
        ]
        self.browser.getControl(name='form.tshirt_size').value = [
            'Medium',
        ]

        # Submit!
        self.browser.getControl(name='form.actions.register').click()
Exemplo n.º 40
0
class TestContentPageCreation(TestCase):

    layer = FTW_CONTENTPAGE_FUNCTIONAL_TESTING

    def setUp(self):
        super(TestContentPageCreation, self).setUp()
        self.portal = self.layer["portal"]
        self.portal_url = self.portal.portal_url()

        # Browser setup
        self.browser = Browser(self.layer["app"])
        self.browser.handleErrors = False

    def _auth(self):
        self.browser.addHeader("Authorization", "Basic %s:%s" % (TEST_USER_NAME, TEST_USER_PASSWORD))

    def test_fti(self):
        self.assertIn("ContentPage", self.portal.portal_types.objectIds())

    def test_creation(self):
        _id = self.portal.invokeFactory("ContentPage", "contentpage")
        self.assertIn(_id, self.portal.objectIds())

        self._auth()
        self.browser.open("%s/createObject?type_name=ContentPage" % self.portal_url)
        self.browser.getControl("Title").value = "New ContentPage"
        self.browser.getControl("Save").click()
        self.assertIn("New ContentPage", self.browser.contents)

    def test_getavailablelayouts(self):
        contentpage = self.portal.get(self.portal.invokeFactory("ContentPage", "contentpage"))
        mid = "authorities_view"
        self.assertIn((mid, mid), contentpage.getAvailableLayouts())

        subpage = contentpage.get(contentpage.invokeFactory("ContentPage", "subpage"))

        # authorities_view should no be available, check comment on
        # ftw.contentpage.content.contentpage -> getAvailableLayouts
        self.assertNotIn((mid, mid), subpage.getAvailableLayouts())

    def test_simplelayout_integration(self):
        contentpage = self.portal.get(self.portal.invokeFactory("ContentPage", "contentpage"))
        ISimpleLayoutCapable.providedBy(contentpage)
        IAdditionalListingEnabled.providedBy(contentpage)

    def test_simplelayout_view(self):
        _id = self.portal.invokeFactory("ContentPage", "contentpage")
        transaction.commit()
        self._auth()
        self.browser.open(self.portal_url + "/" + _id)
        self.assertIn("template-simplelayout", self.browser.contents)
        self.assertIn("simplelayout-content", self.browser.contents)

    def tearDown(self):
        super(TestContentPageCreation, self).tearDown()
        portal = self.layer["portal"]
        if "contentpage" in portal.objectIds():
            portal.manage_delObjects(["contentpage"])
Exemplo n.º 41
0
class VideoFunctionalTest(unittest.TestCase):

    layer = MEDIA_FUNCTIONAL_TESTING

    def setUp(self):
        app = self.layer['app']
        self.portal = self.layer['portal']
        settings = GlobalSettings(self.portal)
        settings.additional_video_formats = []
        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_video(self):
        self.browser.open(self.portal_url)
        self.browser.getLink('Video').click()
        self.browser.getControl(
            name='form.widgets.IDublinCore.title').value = "My video"
        self.browser.getControl(
            name='form.widgets.IDublinCore.description')\
            .value = "This is my video."
        file_path = os.path.join(test_file_dir, "test.mp4")
        file_ctl = self.browser.getControl(
            name='form.widgets.IVideo.video_file')
        file_ctl.add_file(open(file_path, 'rb'), 'video/mp4', 'test.mp4')
        self.browser.getControl('Save').click()
        self.assertTrue('My video' in self.browser.contents)
        self.assertTrue('This is my video' in self.browser.contents)
        self.assertTrue('<video' in self.browser.contents)
        self.assertIn('++widget++form.widgets.IVideo.video_file/@@stream',
                      self.browser.contents)

    @unittest.skip('Async conversion does not work in py3 yet')
    def test_add_video_creates_three_sources(self):
        self.browser.open(self.portal_url)
        self.browser.getLink('Video').click()
        self.browser.getControl(
            name='form.widgets.IDublinCore.title').value = "My video"
        self.browser.getControl(
            name='form.widgets.IDublinCore.description')\
            .value = "This is my video."
        file_path = os.path.join(test_file_dir, "test.mp4")
        file_ctl = self.browser.getControl(
            name='form.widgets.IVideo.video_file')
        file_ctl.add_file(open(file_path, 'rb'), 'video/mp4', 'test.mp4')
        self.browser.getControl('Save').click()
        self.assertTrue('My video' in self.browser.contents)
        self.assertTrue('This is my video' in self.browser.contents)
        self.assertTrue('<video' in self.browser.contents)
        self.assertEqual(self.browser.contents.count('<source'), 3)
        self.assertIn('++widget++form.widgets.IVideo.video_file/@@stream',
                      self.browser.contents)
class TestControlpanelFunctionalities(BaseTestCase):

    layer = CONTENTRULESSUBSCRIPTION_FUNCTIONAL_TESTING

    def setUp(self):
        """
        """
        app = self.layer['app']
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.tool = getToolByName(self.portal, SUBSCRIPTION_TOOL, None)
        self.markRequestWithLayer()
        self.portal_url = self.portal.absolute_url()
        self.browser = Browser(app)
        self.browser.addHeader('Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,))
        #Create some rules
        for x in ["first", "second", "third"]:
            #set some rules
            rule = Rule()
            rule.event = IObjectAddedEvent
            rule.title = "%s rule" % x
            #add the rules to rule's storage
            storage = getUtility(IRuleStorage)
            chooser = INameChooser(storage)
            storage[chooser.chooseName(None, rule)] = rule
            #set the action and add it to the rule
            action = MailSubscriptionsAction()
            action.subject = "Test %s action subject" % x
            rule.actions.append(action)
            email1 = "*****@*****.**"
            email2 = "*****@*****.**"
            self.tool.registerUser(action.actionUID, email1)
            self.tool.registerUser(action.actionUID, email2)
        transaction.commit()

    def test_check_right_list(self):
        """
        """
        self.browser.open("%s/@@contentrules-subscription-controlpanel" % self.portal_url)
        self.assertTrue(u"first rule" in self.browser.contents)
        self.assertTrue(u"second rule" in self.browser.contents)
        self.assertTrue(u"third rule" in self.browser.contents)

    def test_remove_subscription(self):
        """
        """
        self.browser.open("%s/@@contentrules-subscription-controlpanel" % self.portal_url)
        action_id = self.tool.getActionUIDS()[0]
        action_subscriptions = self.browser.getControl(name="%s:list" % action_id)
        self.assertEquals(len(action_subscriptions.value), 2)
        self.assertEquals(action_subscriptions.value, self.tool.getRegisteredList(action_id))
        subscription = action_subscriptions.getControl(value='*****@*****.**')
        subscription.selected = False
        self.browser.getControl(name='form.button.Update').click()
        self.assertTrue(u"Subscriptions updated" in self.browser.contents)
        action_subscriptions = self.browser.getControl(name="%s:list" % action_id)
        self.assertEquals(len(action_subscriptions.value), 1)
        self.assertEquals(action_subscriptions.value, self.tool.getRegisteredList(action_id))
 def test_register_portlet(self):
     browser = Browser(self.layer['portal'])
     # access the login screen and submit the registration form
     browser.open('http://nohost/plone/login')
     browser.handleErrors = False
     browser.getControl('Register').click()
     # make sure we were redirected to @@register with a failed message.
     self.assertEqual('http://nohost/plone/@@register', browser.url)
     self.assertTrue('There were errors' in browser.contents)
Exemplo n.º 44
0
 def getBrowser(self):
     """Create an instance of zope.testbrowser."""
     browser = Browser(self.layer['app'])
     browser.open(self.layer['portal'].absolute_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()
     self.assertIn('You are now logged in', browser.contents)
     return browser
Exemplo n.º 45
0
 def getBrowser(self):
     """Create an instance of zope.testbrowser."""
     browser = Browser(self.layer['app'])
     browser.open(self.layer['portal'].absolute_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()
     self.assertIn('You are now logged in', browser.contents)
     return browser
Exemplo n.º 46
0
class TestEventhandlersFunctional(TestCase):

    layer = FTW_BOOK_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.portal.invokeFactory('Folder', 'folder-1')
        self.portal.invokeFactory('Folder', 'folder-2')
        transaction.commit()

    def create_book(self):
        self.browser.open(self.portal.absolute_url()+'/folder-1/createObject?type_name=Book')
        self.browser.getControl(name="title").value = "Hans Peter"
        self.browser.getControl(name="form.button.save").click()


    def _auth(self):
        self.browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD,))


    def get_portlet(self, obj):
        manager = getUtility(IPortletManager, name='plone.leftcolumn')
        mapping = getMultiAdapter((obj, manager),
                              IPortletAssignmentMapping).__of__(obj)
        return mapping['navigation']

    def test_move_book(self):
        self._auth()
        self.create_book()
        self.browser.getLink("Cut").click()
        self.browser.open(self.portal.absolute_url()+'/folder-2')
        self.browser.getLink("Paste").click()
        self.browser.open(self.browser.url+'/hans-peter')
        obj = self.portal['folder-2']['hans-peter']
        portlet = self.get_portlet(obj)
        self.assertEqual(portlet.root, '/folder-2/hans-peter')

    def test_copy_book(self):
        self._auth()
        self.create_book()
        self.browser.getLink("Copy").click()
        self.browser.open(self.portal.absolute_url()+'/folder-2')
        self.browser.getLink("Paste").click()
        self.browser.open(self.browser.url+'/hans-peter')
        obj = self.portal['folder-2']['hans-peter']
        portlet = self.get_portlet(obj)
        self.assertEqual(portlet.root, '/folder-2/hans-peter')

    def test_after_creation(self):
        self._auth()
        self.create_book()
        obj = self.portal['folder-1']['hans-peter']
        portlet = self.get_portlet(obj)
        self.assertEqual(portlet.root, '/folder-1/hans-peter')
Exemplo n.º 47
0
 def browserLogin(self):
     baseurl = self.portal.absolute_url()
     browser = Browser(self.portal)
     browser.handleErrors = False
     browser.open(baseurl)
     browser.getControl(name='__ac_name').value = TEST_USER_NAME
     browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD
     browser.getControl(name='submit').click()
     self.assertEqual(browser.url, baseurl, "Error, unable to authenticate")
     return browser
Exemplo n.º 48
0
    def test_controlpanel(self):
        browser = Browser(self.app)
        browser.handleErrors = False
        browser.addHeader(
            'Authorization',
            'Basic {0}:{1}'.format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD, ),
        )

        browser.open("{}/@@caching-controlpanel".format(self.portal.absolute_url()))  # noqa
        browser.getControl(name='enabled:boolean').value = 'checked'
        browser.getControl('Save').click()
Exemplo n.º 49
0
 def getBrowser(self, loggedIn=True):
     """ instantiate and return a testbrowser for convenience """
     browser = Browser(self.portal)
     browser.handleErrors = False
     if loggedIn:
         browser.open(self.portal.absolute_url())
         browser.getControl('Login Name').value = TEST_USER_NAME
         browser.getControl('Password').value = TEST_USER_PASSWORD
         browser.getControl('Log in').click()
         self.assertTrue('You are now logged in' in browser.contents)
     return browser
Exemplo n.º 50
0
class TestManageUpgrades(TestCase):

    layer = FTW_UPGRADE_FUNCTIONAL_TESTING

    def setUp(self):
        super(TestManageUpgrades, self).setUp()

        self.portal_url = self.layer['portal'].portal_url()

        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.browser.addHeader(
            'Authorization', 'Basic %s:%s' % (
                TEST_USER_NAME,
                TEST_USER_PASSWORD,
            ))

    def test_registered_in_controlpanel(self):
        self.browser.open(self.portal_url + '/@@overview-controlpanel')
        link = self.browser.getLink('Upgrades')
        self.assertEqual(link.url, self.portal_url + '/@@manage-upgrades')

    def test_manage_view_renders(self):
        self.browser.open(self.portal_url + '/@@manage-upgrades')

        link = self.browser.getLink('Up to Site Setup')
        self.assertEqual(link.url,
                         self.portal_url + '/@@overview-controlpanel')

        self.assertIn('plone.app.discussion:default', self.browser.contents)

    def test_install(self):
        profileid = 'ftw.upgrade.tests.profiles:navigation-index'
        portal_setup = getToolByName(self.layer['portal'], 'portal_setup')
        portal_setup.runAllImportStepsFromProfile('profile-%s' % profileid,
                                                  purge_old=False)
        transaction.commit()

        catalog = getToolByName(self.layer['portal'], 'portal_catalog')
        self.assertEqual(
            type(catalog.Indexes.get('excludeFromNav')).__name__,
            'KeywordIndex')

        self.browser.open(self.portal_url + '/@@manage-upgrades')
        self.assertIn('ftw.upgrade.tests.profiles:navigation-index',
                      self.browser.contents)

        # This upgrade changes KeywordIndex -> FieldIndex

        self.browser.getControl(name='submitted').click()

        self.assertEqual(
            type(catalog.Indexes.get('excludeFromNav')).__name__, 'FieldIndex')
Exemplo n.º 51
0
    def login(self, user_name=TEST_USER_NAME, password=TEST_USER_PASSWORD):
        """Helper method for login."""
        browser = Browser(self.portal)

        # Get an account and login via the login form.
        browser.open(self.portal_url + '/login_form')

        browser.getControl(name='__ac_name', index=0).value = user_name
        browser.getControl(name='__ac_password',
                           index=0).value = TEST_USER_PASSWORD
        browser.getControl(name='submit', index=0).click()

        return browser
class TableOfContentsBehaviorFunctionalTest(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, ['Contributor'])
        fti = DexterityFTI('tocdocument')
        self.portal.portal_types._setObject('tocdocument', fti)
        fti.klass = 'plone.dexterity.content.Item'
        fti.behaviors = (
            'plone.app.contenttypes.behaviors.tableofcontents.'
            'ITableOfContents',
        )
        self.fti = fti
        alsoProvides(self.portal.REQUEST, IPloneAppContenttypesLayer)
        alsoProvides(self.request, IPloneAppContenttypesLayer)
        from plone.app.contenttypes.behaviors.tableofcontents \
            import ITableOfContents
        alsoProvides(self.request, ITableOfContents)
        self.portal.invokeFactory(
            'tocdocument',
            id='tocdoc',
            title=u'Document with a table of contents'
        )
        import transaction
        transaction.commit()
        # Set up browser
        self.browser = Browser(app)
        self.browser.handleErrors = False
        self.browser.addHeader(
            'Authorization',
            'Basic {0}:{1}'.format(SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)
        )

    def test_toc_in_edit_form(self):
        self.browser.open(self.portal_url + '/tocdoc/edit')
        self.assertTrue('Table of contents' in self.browser.contents)

    def test_toc_viewlet_shows_up(self):
        self.browser.open(self.portal_url + '/tocdoc/edit')
        toc_ctl = self.browser.getControl(
            name='form.widgets.ITableOfContents.table_of_contents:list'
        )
        toc_ctl.value = [u'selected', ]
        # Submit form
        self.browser.getControl('Save').click()
        self.assertTrue('<section id="document-toc"' in self.browser.contents)
Exemplo n.º 53
0
    def test_edit_multiple_existing_drafts(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'])

        # 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')

        # 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),
        )
Exemplo n.º 54
0
 def getBrowser(self,
                username=TEST_USER_NAME,
                password=TEST_USER_PASSWORD,
                loggedIn=True):
     """ instantiate and return a testbrowser for convenience """
     browser = Browser(self.portal)
     browser.addHeader('Accept-Language', 'en-US')
     browser.handleErrors = False
     if loggedIn:
         browser.open(self.portal.absolute_url())
         browser.getControl('Login Name').value = username
         browser.getControl('Password').value = password
         browser.getControl('Log in').click()
         self.assertTrue('You are now logged in' in browser.contents)
     return browser
Exemplo n.º 55
0
class FunctionalBaseTestCase(BaseTestCase):

    layer = PLONEINTRANET_WORKSPACE_FUNCTIONAL_TESTING

    def setUp(self):
        super(FunctionalBaseTestCase, self).setUp()
        self.browser = Browser(self.app)
        self.browser.handleErrors = False

    def browser_login_as_site_administrator(self):
        self.browser.open(self.portal.absolute_url() + '/login_form')
        self.browser.getControl(name='__ac_name').value = SITE_OWNER_NAME
        self.browser.getControl(name='__ac_password').value = \
            SITE_OWNER_PASSWORD
        self.browser.getForm(id='login-panel').submit()
Exemplo n.º 56
0
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