Ejemplo n.º 1
0
 def portal_messages(self):
     """Returns a dict with lists of portal message elements (dd) grouped
     by type (info, warning, error).
     """
     return {'info': browser().find_by_css('.portalMessage.info dd'),
             'warning': browser().find_by_css('.portalMessage.warning dd'),
             'error': browser().find_by_css('.portalMessage.error dd')}
Ejemplo n.º 2
0
 def get_body_classes(self):
     """Returns the classes of the body node.
     """
     body = browser().find_by_xpath('//body').first
     locals()['__traceback_info__'] = browser().url
     assert body, 'No <body> tag found.'
     return body['class'].strip().split(' ')
Ejemplo n.º 3
0
    def test_redirects_to_details_view_when_i_can_edit(self):
        obj = create(Builder('file'))
        Plone().login('contributor')

        browser().visit(obj.absolute_url())

        self.assertEquals('http://nohost/plone/file/view',
                          browser().url)
Ejemplo n.º 4
0
 def visit_portal(self, *paths):
     """Open the plone site root in the current browser.
     If one or more path partials as passed as positional arguments
     they are appended to the site root url.
     """
     url = self.concat_portal_url(*paths)
     locals()['__traceback_info__'] = (paths, ':', url)
     browser().visit(url)
     return self
Ejemplo n.º 5
0
    def test_redirects_to_download_when_i_cannot_edit(self):
        obj = create(Builder('file')
                     .with_dummy_content())
        Plone().login('reader')

        browser().visit(obj.absolute_url())

        self.assertEquals(
            'http://nohost/plone/file/@@download/file/test.doc',
            browser().url)
Ejemplo n.º 6
0
    def test_login(self):
        Plone().visit_portal()

        self.assertTrue(browser().find_link_by_text('Log in'),
                        'Could not find login link.')

        Plone().login()
        Plone().visit_portal()

        self.assertFalse(browser().find_link_by_text('Log in'),
                         'Found Log in link - assuming not logged in.')
Ejemplo n.º 7
0
    def test_download_method_redirects_to_url_with_filename(self):
        obj = create(Builder('file')
                     .titled('Document')
                     .attach_file_containing('PDF CONTENT', name='doc.pdf'))

        Plone().login().visit(obj, 'download')

        self.assertEquals(
            'http://nohost/plone/document/@@download/file/doc.pdf',
            browser().url)

        self.assertEquals('PDF CONTENT', browser().html)
Ejemplo n.º 8
0
    def visit(self, obj, view=None):
        """Open the default view or a particular `view` of the passed
        `obj` in the browser.
        """

        url = obj.absolute_url()
        if view is not None:
            url = '/'.join((url, view))

        locals()['__traceback_info__'] = ('URL:', url)
        browser().visit(url)
        return self
Ejemplo n.º 9
0
    def do_transition(self, label, assert_success=True):
        locals()["__traceback_info__"] = browser().url
        elements = browser().find_by_xpath('//a[starts-with(@id, "workflow-transition-")]')

        assert elements, "No workflow transitions available."

        links = {}
        for node in elements:
            links[self.normalize_whitespace(node.text)] = node

        assert label in links, 'Could not find transition "%s", got %s' % (label, links.keys())

        links[label].click()
        if assert_success:
            self.assert_portal_message("info", "Item state changed.")
Ejemplo n.º 10
0
    def test_remove_percent_signs_form_filename(self):
        obj = create(
            Builder('file')
            .titled('Document')
            .attach_file_containing(
                'PDF CONTENT',
                name='50%to80%.pdf'.decode('utf-8')))

        Plone().login().visit(obj, 'download')

        self.assertEquals(
            'http://nohost/plone/document/@@download/' + \
                'file/50to80.pdf',
            browser().url)

        self.assertEquals('PDF CONTENT', browser().html)
Ejemplo n.º 11
0
    def test_content_is_properly_linked(self):
        page = create(Builder('content page')
                      .having(subject=['Airport']))

        view = SubjectListingView().visit()
        view.get_links_for('Airport').first.click()
        self.assertEquals(page.absolute_url(), browser().url)
Ejemplo n.º 12
0
    def test_supports_special_characters_and_umlauts_in_filename(self):
        obj = create(
            Builder('file')
            .titled('Document')
            .attach_file_containing(
                'PDF CONTENT',
                name='w\xc3\xb6rter & bilder.pdf'))

        Plone().login().visit(obj, 'download')

        self.assertEquals(
            'http://nohost/plone/document/@@download/' + \
                'file/w%C3%B6rter%20%26%20bilder.pdf',
            browser().url)

        self.assertEquals('PDF CONTENT', browser().html)
Ejemplo n.º 13
0
    def login(self, user=TEST_USER_NAME, password=TEST_USER_PASSWORD):
        """Log the current browser in with the passed user / password or with
        the default `plone.app.testing` user if no arguemnts are passed.
        """

        if self.browser_driver == 'zope.testbrowser':
            browser()._browser.addHeader('Authorization',
                                         'Basic %s:%s' % (user, password))

        else:
            browser().visit(self.concat_portal_url('login'))
            browser().fill('__ac_name', user)
            browser().fill('__ac_password', password)
            browser().find_by_xpath(
                '//input[@type="submit" and @value="Log in"]').first.click()

        return self
Ejemplo n.º 14
0
    def assert_no_portal_messages(self):
        """Asserts that there are no portal messages.
        """
        locals()['__traceback_info__'] = browser().url
        messages = self.portal_text_messages()

        assert messages == {'info': [], 'warning': [], 'error': []}, \
            'Expected no portal messages but got: %s' % str(messages)
Ejemplo n.º 15
0
    def test_visit_portal(self):
        with self.assertRaises(BrowserStateError):
            browser().url

        self.assertTrue(
            Plone().visit_portal(),
            'visit_portal call should return the Plone object itself')

        self.assertEquals(browser().url, 'http://nohost/plone')

        Plone().visit_portal('login')
        self.assertIn(browser().url, [
                # Plone <= 4.0
                'http://nohost/plone/login_form?came_from=localhost',
                # Plone >= 4.1
                'http://nohost/plone/login',
                ])
Ejemplo n.º 16
0
    def get_links_for(self, subject, text_only=False):
        links = browser().find_by_xpath(
            '//td[normalize-space(text())="%s"]/..//a' % subject)

        if text_only:
            return map(self._item_to_text, links)
        else:
            return links
Ejemplo n.º 17
0
    def test_redirect_if_there_is_already_a_container(self):
        Plone().create_object('Slider Container', {'Title': 'Container1'})
        Plone().visit_portal()
        Plone().find_one_by_xpath(
            '//a/span[normalize-space(text()) = "%s"]/..' % 'Slider Container').click()

        self.assertEqual(self.portal.container1.absolute_url(),
                         browser().url)
Ejemplo n.º 18
0
    def assert_no_error_messages(self):
        """Asserts that there are no error portal messages.
        """
        locals()['__traceback_info__'] = browser().url
        messages = self.portal_text_messages()

        assert messages['error'] == [], \
            'Expected no error portal messages but got: %s' % str(messages)
Ejemplo n.º 19
0
    def test_control_panel_entry(self):
        Plone().login(SITE_OWNER_NAME, SITE_OWNER_PASSWORD)
        PloneControlPanel().open()
        self.assertIn('Lawgiver',
                      PloneControlPanel().get_control_panel_links())

        PloneControlPanel().get_control_panel_link('Lawgiver').click()
        self.assertEquals(SpecsListing().listing_url,
                          browser().url, 'Lawgiver control panel link wrong')
Ejemplo n.º 20
0
    def test_create_object(self):
        Plone().login(SITE_OWNER_NAME, SITE_OWNER_PASSWORD)
        Plone().visit_portal()

        text = 'Some contents for Foo.'
        Plone().create_object('Page', {
                'Title': 'Foo',
                'Body Text': '<strong>%s</strong>' % text})

        self.assertEquals('%s/foo' % Plone().portal_url, browser().url)
        self.assertEquals('Foo', Plone().get_first_heading(),
                          'Title of newly created page is wrong.')
        self.assertTrue(browser().is_text_present(text),
                        'Body Text of newly create page not visible.')

        bold = browser().find_by_xpath('//strong[text()="%s"]' % text).first
        self.assertEquals(text, bold.text,
                          'Insert HTML strong tag could not be found.')
Ejemplo n.º 21
0
    def get_content_links_per_column(self):
        columns = browser().find_by_css('#content-core div.listing-column')
        result = []

        for column in columns:
            links = column.find_by_css('a')
            result.append(map(lambda item: item.text, links))

        return result
Ejemplo n.º 22
0
    def test_DEXTERITY_create_object_ZOPE_TESTBROWSER(self):
        Plone().login(SITE_OWNER_NAME, SITE_OWNER_PASSWORD)
        Plone().visit_portal()

        Plone().create_object('DXType', {'Title': 'Bar'})

        self.assertEquals('%s/bar/view' % Plone().portal_url, browser().url)
        self.assertEquals('Bar', Plone().get_first_heading(),
                          'Title of newly created page is wrong.')
Ejemplo n.º 23
0
    def link_url(self, label):
        links = browser().find_by_xpath(
            '//*[@id="authorities"]//a[normalize-space(text())="%s"]' % label.strip())

        assert len(links) > 0, 'Link with text "%s" not found' % label.strip()
        assert len(links) == 1, 'More than one link with text "%s" found' % (
            label.strip())

        return links[0]['href']
Ejemplo n.º 24
0
 def get_control_panel_links(self):
     """Return a dict with the links on the plone control panel.
     Expects that the control panel is already opened.
     The keys of the dict are the text labels of the links, the values
     are the link object.
     """
     self.assert_on_control_panel()
     links = browser().find_by_css('ul.configlets li a')
     return dict(map(lambda link: (link.text.strip(), link), links))
Ejemplo n.º 25
0
    def test_control_panel_entry(self):
        Plone().login(SITE_OWNER_NAME, SITE_OWNER_PASSWORD)
        PloneControlPanel().open()
        self.assertIn('Lawgiver',
                      PloneControlPanel().get_control_panel_links())

        PloneControlPanel().get_control_panel_link('Lawgiver').click()
        self.assertEquals(SpecsListing().listing_url, browser().url,
                          'Lawgiver control panel link wrong')
Ejemplo n.º 26
0
    def get_specifications(self):
        result = []

        for dtnode in browser().find_by_xpath(
            '//dl[@class="specifications"]/dt'):

            ddnode = dtnode.find_by_xpath('following-sibling::*[self::dd]')
            result.append(SpecItem(dtnode, ddnode))

        return result
Ejemplo n.º 27
0
    def get_spec_metadata_table(self):
        data = []

        for row in browser().find_by_css('table.spec-metadata tr'):
            th = row.find_by_xpath('th').first
            td = row.find_by_xpath('td').first
            data.append((self.normalize_whitespace(th.text),
                         self.normalize_whitespace(td.text)))

        return data
Ejemplo n.º 28
0
    def test_not_break_if_filtered_subject_have_no_additional_subjects(self):
        create(Builder('content page')
               .titled('A page')
               .having(subject=['budget']))

        SubjectListingView().visit_with_subject_filter('budget')

        self.assertEquals(
            'There is no content to list.',
            browser().find_by_css('#content .no-contents').text.strip())
Ejemplo n.º 29
0
 def assert_body_class(self, cssclass):
     """Assert that the <body>-Tag of the current page has a class.
     This is useful for asserting that we are on a certain browser
     view (template-folder_contents) or on an object of a certain
     content type (portaltype-folder).
     """
     locals()['__traceback_info__'] = browser().url
     assert cssclass in self.get_body_classes(), \
         'Missing body class "%s" on this page. Body classes are: %s' % (
         cssclass,
         self.get_body_classes())
Ejemplo n.º 30
0
    def browser_driver(self):
        """Returns the name (string) of the browser driver currently in use.
        Known splinter drivers:
        - firefox
        - remote
        - chrome
        - phantomjs
        - zope.testbrowser
        """

        return next((name for name, klass in _DRIVERS.items()
                     if type(browser()) is klass))
Ejemplo n.º 31
0
    def fill_field(self, label, value):
        """Fill the field with the text-`label` with the passed `value`.
        For TinyMCE fields bare HTML is expected.
        """
        locals()['__traceback_info__'] = browser().url
        fields = browser().find_by_xpath(
            '//*[@*[name()="id" or name()="name"]'
            '=//label[normalize-space(text())="%s"]/@for]' % label)

        assert len(fields) != 0, \
            'No field with label-content "%s" found.' % label

        assert len(fields) < 2, \
            'Ambiguous matches for fields with labels "%s": %s' % (
            label, str(map(lambda item: item.outer_html, fields)))

        if 'mce_editable' in fields.first['class'].split(' ') and \
                self.javascript_supported:

            # Typing in the iframe does not work with PhantomJS.
            # Because of this and because we need to have a consistent input
            # value (=HTML) we just set the HTML content in TinyMCE by
            # using JavaScript.
            jscode = 'tinyMCE.getInstanceById("%s").setContent("%s");' % (
                fields.first['name'], value.replace('"', '\"'))
            browser().execute_script(jscode)

        else:
            browser().fill_form({fields.first['name']: value})
Ejemplo n.º 32
0
    def open_add_form(self, type_name):
        """Opens the add form for adding an object of type `type_name` by
        opening the add menu and clicking on the link.
        A ATFormPage or a DXFormPage object is returned, depending on the
        type of object which is added.
        """
        locals()['__traceback_info__'] = browser().url
        if self.javascript_supported:
            browser().find_by_xpath(
                "//span[text() = 'Add new\xe2\x80\xa6']").click()

        factories = [
            self.normalize_whitespace(item.text) for item
            in browser().find_by_css(
                '#plone-contentmenu-factories li a span')]

        assert self.normalize_whitespace(type_name) in factories, \
            'The type "%s" is not addable. Addable types: %s' % (
            type_name, str(factories))

        self.find_one_by_xpath(
            '//a/span[normalize-space(text()) = "%s"]/..' % type_name).click()

        if 'portal_factory' in browser().url:
            return ATFormPage()
        elif '++add++' in browser().url:
            return DXFormPage()
        else:
            raise NotImplementedError()
Ejemplo n.º 33
0
    def schematas(self):
        schematas = []

        for fieldset in browser().find_by_css('form fieldset'):
            legend = fieldset.find_by_css('legend').first
            label = legend.text.strip()
            schematas.append(
                (label,
                 {'label': label,
                  'legend': legend,
                  'fieldset': fieldset}))

        return schematas
Ejemplo n.º 34
0
    def get_specification_mapping(self):
        mapping = {}

        groups = browser().find_by_css('dl.permission-mapping dd dl dt')
        for actiongroup in groups:
            groupname = actiongroup.text

            permissionlist = actiongroup.find_by_xpath(
                'following-sibling::*[self::dd]').first

            permissions = map(attrgetter('text'),
                              permissionlist.find_by_css('li'))
            mapping[groupname] = permissions

        return mapping
Ejemplo n.º 35
0
 def addable_types_links(self):
     nodes = browser().find_by_css('#plone-contentmenu-factories li a')
     return dict([(node.text.strip(), node) for node in nodes])
Ejemplo n.º 36
0
 def open(self):
     browser().visit(self.listing_url)
     assert self.get_template_class() == 'template-lawgiver-list-specs', \
         'Not on @@lawgiver-list-specs view!?: %s' % browser().url
Ejemplo n.º 37
0
 def test_theme_is_rendered_logged_in(self):
     Plone().login().visit_portal()
     self.assertTrue(
         browser().find_by_css('#page-wrapper'),
         'Could not find #page-wrapper - was the theme rendered?')
Ejemplo n.º 38
0
 def click(self):
     browser().find_link_by_text(self.link_text()).click()
Ejemplo n.º 39
0
 def get_unmanaged_permissions(self):
     return map(attrgetter('text'),
                browser().find_by_css('dl.unmanaged-permissions dd li'))
Ejemplo n.º 40
0
 def no_solr(self):
     xpr = '#portal-searchbox form.no-solr'
     return len(browser().find_by_css(xpr)) > 0
Ejemplo n.º 41
0
 def search_field_placeholder(self):
     xpr = '#portal-searchbox input[name=SearchableText]'
     return browser().find_by_css(xpr).first['placeholder']
Ejemplo n.º 42
0
 def get_translations_po(self):
     return browser().find_by_css('dl.translations dd pre.po').first.text
Ejemplo n.º 43
0
 def form_action(self):
     xpr = '#portal-searchbox form'
     return browser().find_by_css(xpr).first['action']
Ejemplo n.º 44
0
 def get_confirmation_dialog_text(self):
     return self.normalize_whitespace(
         browser().find_by_css('.confirmation-message').first.text)
Ejemplo n.º 45
0
 def content_actions_labels(self):
     items = browser().find_by_css('#plone-contentmenu-actions dd a')
     return map(lambda link: link.text.strip(), items)
Ejemplo n.º 46
0
 def is_confirmation_dialog_opened(self):
     return len(browser().find_by_css('.confirmation-message')) > 0
Ejemplo n.º 47
0
 def get_specification_text(self):
     return browser().find_by_css('dl.specification dd pre').first.text
Ejemplo n.º 48
0
 def content_views_links(self):
     return browser().find_by_css('#content-views a')