当前位置: 首页>>代码示例>>Python>>正文


Python Browser.getLink方法代码示例

本文整理汇总了Python中Testing.testbrowser.Browser.getLink方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.getLink方法的具体用法?Python Browser.getLink怎么用?Python Browser.getLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Testing.testbrowser.Browser的用法示例。


在下文中一共展示了Browser.getLink方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestIDFromTitle

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getLink [as 别名]
class TestIDFromTitle(FunctionalTestCase):
    """Browsertests to make sure ATImages derive their default IDs from their titles"""
    # TODO: Merge into TestATImageFunctional, below.
    
    def afterSetUp(self):
        self.userId = 'fred'
        self.password = 'secret'
        self.portal.acl_users.userFolderAddUser(self.userId, self.password, ['Manager'], [])
        self.browser = Browser()
        self._log_in()

    def _log_in(self):
        """Log in as someone who can add new Images."""
        self.browser.open(self.portal.absolute_url())
        self.browser.getLink('Log in').click()
        self.browser.getControl('Login Name').value = self.userId
        self.browser.getControl('Password').value = self.password
        self.browser.getControl('Log in').click()

    def _make_image(self, title, filename='canoneye.jpg'):
        """Add a new Image at the root of the Plone site."""
        self.browser.open(self.portal.absolute_url() + '/createObject?type_name=Image')
        self.browser.getControl('Title').value = title
        image = self.browser.getControl(name='image_file')
        image.filename = filename
        TEST_JPEG_FILE.seek(0)
        image.value = TEST_JPEG_FILE
        self.browser.getControl('Save').click()

    def test_image_id_from_filename_and_title(self):
        # Get ID from filename:
        self._make_image('')
        self.failUnless('canoneye.jpg' in self.browser.url)

        # Get ID from title.
        # As a side effect, make sure the ID validator doesn't overzealously
        # deny our upload of something else called canoneye.jpg, even though
        # we're not going to compute its ID from its filename.
        self._make_image('Wonderful Image')
        self.failUnless('/wonderful-image' in self.browser.url)

    def test_image_id_from_unicode_title(self):
        self._make_image('', filename=u'Pictüre 1.png'.encode('utf-8'))
        normalized = 'Picture%201.png'
        self.failUnless(normalized in self.browser.url)
开发者ID:nacho22martin,项目名称:tesis,代码行数:47,代码来源:test_atimage.py

示例2: FunctionalTestCase

# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getLink [as 别名]

#.........这里部分代码省略.........
        self.portal._original_MailHost = self.portal.MailHost
        self.portal.MailHost = mailhost = MockMailHost('MailHost')
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(mailhost, provided=IMailHost)
        # Make sure our mock mailhost does not give a mailhost_warning
        # in the overview-controlpanel.
        self.configure_mail_host(u'mock', '[email protected]')

    def _clear(self, call_close_hook=0):
        self.portal.MailHost = self.portal._original_MailHost
        sm = getSiteManager(context=self.portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(aq_base(self.portal._original_MailHost),
                           provided=IMailHost)
        ptc.PloneTestCase._clear(self)

    def get_smtp_host(self):
        if IMailSchema is None:
            # Plone 4
            return self.portal.MailHost.smtp_host
        else:
            # Plone 5.0 and higher
            registry = getUtility(IRegistry)
            mail_settings = registry.forInterface(
                IMailSchema, prefix='plone', check=False)
            return mail_settings.smtp_host

    def configure_mail_host(self, smtp_host, address=None):
        if IMailSchema is None:
            # Plone 4
            self.portal.MailHost.smtp_host = smtp_host
            if address is not None:
                self.portal.email_from_address = address
        else:
            # Plone 5.0 and higher
            registry = getUtility(IRegistry)
            mail_settings = registry.forInterface(
                IMailSchema, prefix='plone', check=False)
            if not isinstance(smtp_host, unicode):
                # must be unicode
                smtp_host = smtp_host.decode('utf-8')
            mail_settings.smtp_host = smtp_host
            if address is not None:
                if isinstance(address, unicode):
                    # must be ascii
                    address = address.encode('utf-8')
                mail_settings.email_from_address = address

    def afterSetUp(self):
        """Add some extra content and do some setup.
        """
        # We need to do this as Manager:
        self.setRoles(['Manager'])

        # Add some news items:
        sample_text = "<p>Have I got news for <em>you</em>!</p>"
        self.portal.news.invokeFactory(
            'News Item', 'first', title="First News", text=sample_text)
        self.portal.news.invokeFactory(
            'News Item', 'second', title="Second News", text=sample_text)

        # Set fullname and email address of test user:
        member = self.portal.portal_membership.getAuthenticatedMember()
        member.setMemberProperties({'fullname': 'Test User',
                                    'email': '[email protected]'})

        # Add extra members:
        self.addMember('maurits', 'Maurits van Rees', '[email protected]')
        self.addMember('reinout', 'Reinout van Rees', '[email protected]')

        # Setup test browser:
        try:
            from Testing.testbrowser import Browser
            Browser  # pyflakes
        except ImportError:
            from Products.Five.testbrowser import Browser
        self.browser = Browser()
        self.browser.handleErrors = False
        self.browser.addHeader('Accept-Language', 'en-US')
        self.portal.error_log._ignored_exceptions = ()

        # No more Manager:
        self.setRoles([])

    def addMember(self, username, fullname, email):
        self.portal.portal_membership.addMember(
            username, ptc.default_password, [], [])
        member = self.portal.portal_membership.getMemberById(username)
        member.setMemberProperties({'fullname': fullname, 'email': email})

    def browser_login(self, user=None):
        if not user:
            user = ptc.default_user
        self.browser.open(self.portal.absolute_url() + '/login_form')
        self.browser.getLink('Log in').click()
        self.browser.getControl(name='__ac_name').value = user
        self.browser.getControl(name='__ac_password').value = \
            ptc.default_password
        self.browser.getControl(name='submit').click()
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:104,代码来源:test_integration.py


注:本文中的Testing.testbrowser.Browser.getLink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。