本文整理汇总了Python中Testing.testbrowser.Browser.getControl方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.getControl方法的具体用法?Python Browser.getControl怎么用?Python Browser.getControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Testing.testbrowser.Browser
的用法示例。
在下文中一共展示了Browser.getControl方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
def setUp(self):
"""\
Sets up the environment that the workspace doctest needs.
"""
DocTestCase.setUp(self)
from Testing.testbrowser import Browser
from Products.PloneTestCase.setup import default_user, default_password
from pmr2.app.settings.interfaces import IPMR2GlobalSettings
# point the physical root for repo_root to the tmpdir.
self.pmr2 = zope.component.getUtility(IPMR2GlobalSettings)
self.pmr2.repo_root = self.tmpdir
# user workspace
_createObjectByType('Folder', self.portal, id='w')
self.pmr2.user_workspace_subpath = u'w'
self.pmr2.create_user_workspace = True
# set up test browser with default user logged in.
b = Browser()
portal_url = self.portal.absolute_url()
b.open(portal_url + '/login')
b.getControl(name='__ac_name').value = default_user
b.getControl(name='__ac_password').value = default_password
b.getControl(name='submit').click()
self.testbrowser = b
示例2: getBrowser
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
def getBrowser(self, loggedIn=False, admin=False):
""" instantiate and return a testbrowser for convenience """
browser = Browser()
if loggedIn:
u = PloneTestCase.default_user
p = PloneTestCase.default_password
browser.open(self.portal.absolute_url() + "/login_form")
browser.getControl(name='__ac_name').value = u
browser.getControl(name='__ac_password').value = p
browser.getControl(name='submit').click()
return browser
示例3: check_shown_in_digibib
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
def check_shown_in_digibib(self, user_id, object_ids, container):
browser = Browser()
browser.open('%s/logout/' % self.portal.absolute_url())
browser.open('%s/login_form/' % self.portal.absolute_url())
browser.getControl(name='__ac_name').value = user_id
browser.getControl(name='__ac_password').value = self.default_password
browser.getControl(name='submit').click()
browser.open(self.portal.digibib.absolute_url())
parser = DigiBibHtmlParser()
parser.feed(browser.contents)
# We have to check that the project is displayed in the main
# content of the page and not simply in the menu on the left.
return [obj_id for obj_id in object_ids
if container[obj_id].absolute_url()
in parser.links]
示例4: ZPTBrowserTests
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
class ZPTBrowserTests(FunctionalTestCase):
"""Browser testing ZopePageTemplate"""
def setUp(self):
from Products.PageTemplates.ZopePageTemplate import \
manage_addPageTemplate
super(ZPTBrowserTests, self).setUp()
Zope2.App.zcml.load_site(force=True)
uf = self.app.acl_users
uf.userFolderAddUser('manager', 'manager_pass', ['Manager'], [])
manage_addPageTemplate(self.app, 'page_template')
self.browser = Browser()
self.browser.login('manager', 'manager_pass')
self.browser.open('http://localhost/page_template/manage_main')
def test_pt_upload__no_file(self):
"""It renders an error message if no file is uploaded."""
self.browser.getControl('Upload File').click()
self.assertIn('No file specified', self.browser.contents)
示例5: afterSetUp
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
def afterSetUp(self):
super(JsonClientTestCase, self).afterSetUp()
register_layer(IPMR2JsonClientTestLayer, "pmr2.jsonclient.tests")
request = TestRequest()
# Ensure that the most basic scope managers are being used.
cmf = factory(ConsumerManager)
tmf = factory(TokenManager)
smf = factory(MockScopeManager)
zope.component.provideAdapter(cmf, (IAnnotatable, IPMR2JsonClientTestLayer), IConsumerManager)
zope.component.provideAdapter(tmf, (IAnnotatable, IPMR2JsonClientTestLayer), ITokenManager)
zope.component.provideAdapter(smf, (IAnnotatable, IPMR2JsonClientTestLayer), IScopeManager)
# assuming none of these are overridden.
self.consumer = Consumer("test.example.com", "consumer-secret", u"PMR2 Test JSON Client", None)
cm = zope.component.getMultiAdapter((self.portal, request), IConsumerManager)
cm.add(self.consumer)
token = Token("pmr2token", "token-secret")
token.access = True
token.consumer_key = self.consumer.key
token.user = default_user
self.token = token
tm = zope.component.getMultiAdapter((self.portal, request), ITokenManager)
tm.add(self.token)
# XXX especially this one.
sm = zope.component.getMultiAdapter((self.portal, request), IScopeManager)
sm.permitted = "^.*$" # permit everything.
b = Browser()
portal_url = self.portal.absolute_url()
b.open(portal_url + "/login")
b.getControl(name="__ac_name").value = default_user
b.getControl(name="__ac_password").value = default_password
b.getControl(name="submit").click()
self.user_browser = b
示例6: PythonScriptBrowserTests
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
class PythonScriptBrowserTests(FunctionalTestCase):
"""Browser testing Python Scripts"""
def setUp(self):
from Products.PythonScripts.PythonScript import manage_addPythonScript
super(PythonScriptBrowserTests, self).setUp()
Zope2.App.zcml.load_site(force=True)
uf = self.app.acl_users
uf.userFolderAddUser('manager', 'manager_pass', ['Manager'], [])
manage_addPythonScript(self.app, 'py_script')
self.browser = Browser()
self.browser.addHeader(
'Authorization',
'basic {}'.format(codecs.encode( # NOQA: flake8: P101
b'manager:manager_pass', 'base64').decode()))
self.browser.open('http://localhost/py_script/manage_main')
def test_ZPythonScriptHTML_upload__no_file(self):
"""It renders an error message if no file is uploaded."""
self.browser.getControl('Upload File').click()
self.assertIn('No file specified', self.browser.contents)
示例7: TestIDFromTitle
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [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)
示例8: TestControlPanel
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
class TestControlPanel(base.FunctionalTestCase):
def afterSetUp(self):
super(TestControlPanel, self).afterSetUp()
self.browser = Browser()
def test_extended_form(self):
portal_url = self.portal.absolute_url()
self.browser.addHeader('Authorization',
'Basic %s:%s' % (portal_owner, default_password))
self.browser.open('%s/@@collectivegeo-controlpanel' % portal_url)
widget = None
try:
widget = self.browser.getControl(
name='form.widgets.geo_content_types.to') or False
except:
self.fail(
'geo_content_types widget not Found in controlpanel form')
if widget:
geo_content_types = geo_settings(self.portal).geo_content_types
self.assertEqual(widget.options, geo_content_types)
示例9: SendAsPDFTestCase
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
class SendAsPDFTestCase(ptc.FunctionalTestCase):
is_plone_3 = is_plone_3
# We'll use those pages taken from Wikipedia pages about Plone
# to create some pages in the system.
# We chose English for its lack of accented characters, French
# because it mixes normal and accented characters and Japanese
# for the use of non-Latin characters.
# (my apologies to Japanese people if I make the text sound weird
# by cutting it at 80 characters, I don't really have a clue about
# what the text means).
data = {'en': """
<p>Plone is a free and open source content management system
built on top of the Zope application server. In principle,
Plone can be used for any kind of website, including blogs,
internet sites, webshops and internal websites. It is also well
positioned to be used as a document publishing system and groupware
collaboration tool. The strengths of Plone are its flexible and
adaptable workflow, very good security, extensibility, high
usability and flexibility.</p>
<p>Plone is released under the GNU General Public License (GPL) and
is designed to be extensible. Major development is conducted
periodically during special meetings called Plone Sprints.
Additional functionality is added to Plone with Products,
which may be distributed through the Plone website or otherwise.
The Plone Foundation holds and enforces all copyrights and
trademarks.
Plone also has legal backing from the council of the Software
Freedom Law Center.</p>
<p>MediaWiki's "Monobook" layout is based partially on the
Plone style sheets. High-profile public sector users include
the Federal Bureau of Investigation, Brazilian Government, United
Nations, City of Bern (Switzerland), New South Wales Government
(Australia), and European Environment Agency.""",
'fr': """
<p>Plone est un système de gestion de contenu Web libre publié
selon les termes de la GNU GPL. Il est construit au-dessus du
serveur d'applications Zope et de son extension CMF
(Content Management Framework).</p>
<p>Plone est entièrement objet et modulaire. Il permet de
créer et gérer les aspects d'un site web, comme les utilisateurs,
les « workflows » ou les documents attachables.</p>
<p>Le fait que Plone soit programmé sur Zope fait qu'il est
moins utilisé que d'autres systèmes de gestion de contenu,
Zope étant connu pour sa courbe d'apprentissage assez lente
(le fameux ZopeZen). Toutefois, Plone est considéré comme étant
l'un des meilleurs CMS open-source existants, et est utilisé entre
autres par le site web de la FSF, la Fondation pour le logiciel
libre.</p>
""",
'jp': """
<p>PloneはZopeアプリケーションサーバ上に構築されたフリーかつオープンなコ
ンテンツマネジメントシステムである。基本的にPloneは、ブログ、インターネットサイト
、ウェブショップや組織内のWebサイトといったどのような用途にも利用できる。さらに文
書管理システムやグループウェアといった共有ツールとしても利用できるようになっている
。Ploneの強みは、その柔軟で適応性のあるワークフロー、非常に優れたセキュリティ、拡張性
、高いユーザビリティと柔軟性である</p>
<p>PloneはGNU General Public License(GPL)ライセンスでリリースされており
、拡張し易いように設計されている。主な開発は、定期的に開催される Plone スプリン
トと呼ばれる特別なミーティング(ハッカソン)で行われる。Ploneに対する追加機能はプ
ロダクトで追加する。それはPloneのウェブサイトかその他のサイトで配布されている。
Plone財団は全ての著作権と商標を保持している。さらにPloneはSoftware Freedom
Law Centerの評議会からの法的な後ろ盾も持っている。</p>
<p>MediaWikiの"Monobook [JP]"レイアウトは部分的にPloneのスタイルシートをベー
スにしている。</p>
"""}
def afterSetUp(self):
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)
# his hack allows us to get the traceback when the getting a
# 500 error when using the browser.
self.portal.error_log._ignored_exceptions = ()
def raising(self, info):
import traceback
traceback.print_tb(info[2])
print info[1]
from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog
SiteErrorLog.raising = raising
transaction.commit()
def beforeTearDown(self):
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)
def login_as_user(self, username, password):
self.browser.open('http://nohost/plone/logout')
self.browser.open('http://nohost/plone/login_form')
self.browser.getControl(name='__ac_name').value = username
#.........这里部分代码省略.........
示例10: FunctionalTestCase
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [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()
示例11: testSkinSwitchUsingFallbackForm
# 需要导入模块: from Testing.testbrowser import Browser [as 别名]
# 或者: from Testing.testbrowser.Browser import getControl [as 别名]
def testSkinSwitchUsingFallbackForm(self):
self.loginAsPortalOwner()
folder_url = self.folder.absolute_url()
portal_url = self.portal.absolute_url()
# Add a second folder:
self.portal.invokeFactory('Folder', id='folder2')
folder2 = self.portal.folder2
wf_tool = getToolByName(self.portal, 'portal_workflow')
wf_tool.doActionFor(folder2, 'publish')
folder2_url = folder2.absolute_url()
# Add a sub folder:
folder2.invokeFactory('Folder', id='sub_folder')
sub_folder = folder2.sub_folder
wf_tool.doActionFor(sub_folder, 'publish')
sub_folder_url = sub_folder.absolute_url()
# Create a new default skin.
new_default_skin(self.portal)
# Set the default skin for the first folder.
browser = Browser()
browser.handleErrors = False
self._login(browser)
browser.open(folder_url + "/select_skin")
control = browser.getControl(name="skin_name")
self.assertEqual([], control.value)
control.value = ["Monty Python Skin"]
# Saving the form redirects back to the folder.
browser.getControl(name="form.button.Save").click()
self.assertEqual(folder_url, browser.url)
# Going back to the form has the skin selected.
browser.open(folder_url + "/select_skin")
control = browser.getControl(name="skin_name")
self.assertEqual(["Monty Python Skin"], control.value)
# Set the default skin for the second folder. We have to do
# this as portal owner.
self._login(browser, login_name=ptc.portal_owner)
browser.open(folder2_url + "/select_skin")
control = browser.getControl(name="skin_name")
self.assertEqual([], control.value)
control.value = ["Sunburst Theme"]
browser.getControl(name="form.button.Save").click()
browser.open(folder2_url + "/select_skin")
control = browser.getControl(name="skin_name")
self.assertEqual(["Sunburst Theme"], control.value)
# Set a different default skin for the sub folder.
browser.open(sub_folder_url + "/select_skin")
control = browser.getControl(name="skin_name")
self.assertEqual([], control.value)
control.value = ["Monty Python Skin"]
browser.getControl(name="form.button.Save").click()
browser.open(sub_folder_url + "/select_skin")
control = browser.getControl(name="skin_name")
self.assertEqual(["Monty Python Skin"], control.value)
# What is the current skin name in a few contexts?
self._login(browser)
browser.open(portal_url + '/getCurrentSkinName')
self.assertEqual(browser.contents, 'Monty Python Skin')
browser.open(folder_url + '/getCurrentSkinName')
self.assertEqual(browser.contents, 'Monty Python Skin')
browser.open(folder2_url + '/getCurrentSkinName')
self.assertEqual(browser.contents, 'Sunburst Theme')
browser.open(sub_folder_url + '/getCurrentSkinName')
self.assertEqual(browser.contents, 'Monty Python Skin')
# Check the effect this has when visiting these contexts. We
# do this with an almost empty browser view that shows a
# viewlet that is specifically registered for the Monty Python
# theme and not the Sunburst Theme theme. Plus a viewlet that
# shows which marker interfaces the request provides.
# First the portal root:
browser.open(portal_url + '/@@viewlet-test')
self.assertTrue('We want a shrubbery!' in browser.contents)
self.assertTrue('interfaces.IMyTheme' in browser.contents)
# Then the first folder:
browser.open(folder_url + '/@@viewlet-test')
self.assertTrue('We want a shrubbery!' in browser.contents)
self.assertTrue('interfaces.IMyTheme' in browser.contents)
# Then the second folder:
browser.open(folder2_url + '/@@viewlet-test')
self.assertFalse('We want a shrubbery!' in browser.contents)
self.assertFalse('interfaces.IMyTheme' in browser.contents)
# Then the sub folder:
browser.open(sub_folder_url + '/@@viewlet-test')
self.assertTrue('We want a shrubbery!' in browser.contents)
self.assertTrue('interfaces.IMyTheme' in browser.contents)