[Erp5-report] r44967 arnaud.fontaine - /erp5/trunk/utils/erp5.utils.test_browser/src/erp5/u...
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Apr 1 05:45:18 CEST 2011
Author: arnaud.fontaine
Date: Fri Apr 1 05:45:18 2011
New Revision: 44967
URL: http://svn.erp5.org?rev=44967&view=rev
Log:
Similarly to submit(), add a class_attribute parameter to be able to
get a link from its class attribute, and add getImportExportLink() and
getFastInputLink() using class_attribute as the href is context-dependent
Modified:
erp5/trunk/utils/erp5.utils.test_browser/src/erp5/utils/test_browser/browser.py
Modified: erp5/trunk/utils/erp5.utils.test_browser/src/erp5/utils/test_browser/browser.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.utils.test_browser/src/erp5/utils/test_browser/browser.py?rev=44967&r1=44966&r2=44967&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.utils.test_browser/src/erp5/utils/test_browser/browser.py [utf8] (original)
+++ erp5/trunk/utils/erp5.utils.test_browser/src/erp5/utils/test_browser/browser.py [utf8] Fri Apr 1 05:45:18 2011
@@ -261,23 +261,64 @@ class Browser(ExtendedTestBrowser):
self._main_form = ContextMainForm(self, form)
return self._main_form
- def getLink(self, url=None, *args, **kwargs):
+ def getLink(self, url=None, class_attribute=None, *args, **kwargs):
"""
Override original C{getLink} allowing to not consider the HTTP
query string unless it is explicitly given.
- @param url: URL to look for
- @type url: str
+ Also, allows to select a link by its class attribute, which
+ basically look for the first element whose C{attribute} is
+ C{class_attribute} then call C{getLink} with the element C{href}.
+
+ @param class_attribute: Get the link with this class
+ @type class_attribute: str
@param args: Positional arguments given to original C{getLink}
@type args: list
@param kwargs: Keyword arguments given to original C{getLink}
@type kwargs: dict
"""
- if url and '?' not in url:
+ if class_attribute:
+ element_list = self.etree.xpath('//a[contains(@class, "%s")]' % \
+ class_attribute)
+
+ try:
+ url = element_list[0].get('href')
+ except (IndexError, AttributeError):
+ url = None
+
+ if not url:
+ raise LookupError("Could not find any link whose class is '%s'" % \
+ class_attribute)
+
+ elif url and '?' not in url:
url += '?'
return super(Browser, self).getLink(url=url, *args, **kwargs)
+ def getImportExportLink(self):
+ """
+ Get Import/Export link. Use the class attribute rather than the
+ name as the latter is dependent on the context.
+
+ @return: The link whose class is C{report}
+ @rtype: Link
+
+ @todo: Should perhaps be a ContextBrowser class?
+ """
+ return self.getLink(class_attribute='import_export')
+
+ def getFastInputLink(self):
+ """
+ Get Fast Input link. Use the class attribute rather than the name
+ as the latter is dependent on the context.
+
+ @return: The link whose class is C{fast_input}
+ @rtype: Link
+
+ @todo: Should perhaps be a ContextBrowser class?
+ """
+ return self.getLink(class_attribute='fast_input')
+
def getTransitionMessage(self):
"""
Parses the current page and returns the value of the portal_status
@@ -450,7 +491,8 @@ class MainForm(Form):
name = None
if not name:
- raise LookupError("Could not find any '%s' element" % class_attribute)
+ raise LookupError("Could not find any button whose class is '%s'" % \
+ class_attribute)
if label is None and name is None:
super(MainForm, self).submit(label=label, name=name, *args, **kwargs)
More information about the Erp5-report
mailing list