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


Python Browser.getForm方法代码示例

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


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

示例1: SendAsPDFTestCase

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

#.........这里部分代码省略.........
        self.addProduct('collective.sendaspdf')

    def create_folder(self, parent, title):
        self.login_as_manager()
        self.browser.open('%s/createObject?type_name=Folder' %
                          parent.absolute_url())
        self.browser.getControl(name='title').value = title
        self.browser.getControl(name='form.button.save').click()
        return self.browser.url

    def create_page(self, language, title=None, parent=None):
        self.login_as_manager()
        if parent is None:
            parent = self.portal

        self.browser.open('%s/createObject?type_name=Document' %
                          parent.absolute_url())
        if title is None:
            title = 'Plone (%s)' % language

        self.browser.getControl(name='title').value = title
        self.browser.getControl(name='text').value = self.data.get(language,
                                                                   'Oups ...')
        self.browser.getControl(name='form.button.save').click()
        return self.browser.url

    def create_image(self, img_file, img_file_type, parent=None):
        self.login_as_manager()
        if parent is None:
            parent = self.portal

        def mydir():
            import sys
            import os.path

            if __name__ == '__main__':
                filename = sys.argv[0]
            else:
                filename = __file__
            return os.path.abspath(os.path.dirname(filename))

        self.browser.open('%s/createObject?type_name=Image' %
                          parent.absolute_url())
        file_control = self.browser.getControl(name='image_file')
        file_control.mech_control.add_file(file('%s/%s' % (mydir(), img_file)),
                                           img_file_type,
                                           img_file)
        self.browser.getControl(name='form.button.save').click()
        return self.browser.url

    def setup_data(self):
        self.install_products()
        for lang in self.data.keys():
            self.create_page(lang)

        # We also add a page for which the title will contain
        # non-ASCII characters.
        # Depending on Plone version, the generated ID is not the same,
        # so we first generate the page with a simple title for which id
        # is safe, then we'll edit the title.
        self.cyrilic_title_page_url = self.create_page(None,
                                                       'Cyrilic title page')
        self.browser.open('%s/edit' % self.cyrilic_title_page_url)
        self.browser.getControl(name='title').value = '3цдса'
        self.browser.getControl(name='form.button.save').click()

    def get_sendaspdf_actions(self):
        """ Finds the links generated by send as pdf in browser contents.
        """
        parser = SendAsPDFHtmlParser()
        parser.feed(self.browser.contents)
        return parser.get_document_actions()

    def list_available_controls(self, form_name, before=None, hidden=[]):
        """
        'before' can be used to print something before the form.
        That can be useful for example when the first line printed
        starts with a non-deterministic value as you cannot
        use an ellipsis.
        """

        if before is not None:
            print before

        # Code from the community manual (page not available anymore,
        # sorry for the source :/ )
        form = self.browser.getForm(name=form_name)
        # get and print all controls
        for ctrl in form.mech_form.controls:
            try:
                control = self.browser.getControl(name=ctrl.name)
                if control.name in hidden:
                    continue

                print "%s: %s (%s)" % (control.name,
                                       control.value,
                                       control.type)
                print control.controls
            except:
                pass
开发者ID:GhitaB,项目名称:collective.sendaspdf,代码行数:104,代码来源:base.py


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