Commit 04594fc4 authored by Roque's avatar Roque Committed by Klaus Wölfel

testbrowser: refactor in browser due to new version of package zope.testbrowser.

An update in zope.testbrowser dropped the mechanize dependency used by the browser. Now it uses WebTest instead.

Details of the update: https://pypi.python.org/pypi/zope.testbrowser/5.2.1
parent 615cef26
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs # consequences resulting from its eventual inadequacies and bugsc
# End users who are looking for a ready-to-use solution with commercial # End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software # garantees and support are strongly adviced to contract a Free Software
# Service Company # Service Company
...@@ -36,7 +36,7 @@ import urllib ...@@ -36,7 +36,7 @@ import urllib
from urlparse import urljoin from urlparse import urljoin
from z3c.etestbrowser.browser import ExtendedTestBrowser from z3c.etestbrowser.browser import ExtendedTestBrowser
from zope.testbrowser.browser import onlyOne, fix_exception_name from zope.testbrowser.browser import onlyOne
def measurementMetaClass(prefix): def measurementMetaClass(prefix):
""" """
...@@ -234,7 +234,6 @@ class Browser(ExtendedTestBrowser): ...@@ -234,7 +234,6 @@ class Browser(ExtendedTestBrowser):
try: try:
response = self.mech_browser.open_novisit(url_or_path, data) response = self.mech_browser.open_novisit(url_or_path, data)
except Exception, e: except Exception, e:
fix_exception_name(e)
raise raise
except mechanize.HTTPError, e: except mechanize.HTTPError, e:
if e.code >= 200 and e.code <= 299: if e.code >= 200 and e.code <= 299:
...@@ -317,17 +316,10 @@ class Browser(ExtendedTestBrowser): ...@@ -317,17 +316,10 @@ class Browser(ExtendedTestBrowser):
# just return the main_form instance # just return the main_form instance
if self._main_form and self._counter == self._main_form._browser_counter: if self._main_form and self._counter == self._main_form._browser_counter:
return self._main_form return self._main_form
main_form = self.getForm(id='main_form')._form
main_form = None
for form in self.mech_browser.forms():
if form.attrs.get('id') == 'main_form':
main_form = form
if not main_form: if not main_form:
raise LookupError("Could not get 'main_form'") raise LookupError("Could not get 'main_form'")
self._main_form = ContextMainForm(self, main_form)
self.mech_browser.form = form
self._main_form = ContextMainForm(self, form)
return self._main_form return self._main_form
def getLink(self, text=None, url=None, id=None, index=0, def getLink(self, text=None, url=None, id=None, index=0,
...@@ -704,9 +696,9 @@ class MainForm(Form): ...@@ -704,9 +696,9 @@ class MainForm(Form):
else: else:
if index is None: if index is None:
index = 0 index = 0
super(MainForm, self).submit(label=label, name=name, index=index, super(MainForm, self).submit(label=label, name=name, index=index,
*args, **kwargs) *args, **kwargs)
def submitSelect(self, select_name, submit_name, label=None, value=None, def submitSelect(self, select_name, submit_name, label=None, value=None,
select_index=None, control_index=None): select_index=None, control_index=None):
...@@ -747,8 +739,8 @@ class MainForm(Form): ...@@ -747,8 +739,8 @@ class MainForm(Form):
@raise LookupError: The select, option or submit control could not @raise LookupError: The select, option or submit control could not
be found be found
""" """
select_control = self.getControl(name=select_name, index=select_index) select_control = self.getControl(name=select_name, index=select_index)
# zope.testbrowser checks for a whole word but it is also useful # zope.testbrowser checks for a whole word but it is also useful
# to match the end of the option control value string because in # to match the end of the option control value string because in
# ERP5, the value could be URL (such as 'http://foo:81/erp5/logout') # ERP5, the value could be URL (such as 'http://foo:81/erp5/logout')
...@@ -760,13 +752,10 @@ class MainForm(Form): ...@@ -760,13 +752,10 @@ class MainForm(Form):
if item.endswith(value): if item.endswith(value):
value = item value = item
break break
self._logger.debug("select_id='%s', label='%s', value='%s'" % \ self._logger.debug("select_id='%s', label='%s', value='%s'" % \
(select_name, label, value)) (select_name, label, value))
select_control.getControl(label=label, value=value, select_control.getControl(label=label, value=value,
index=control_index).selected = True index=control_index).selected = True
self.submit(name=submit_name) self.submit(name=submit_name)
def submitLogin(self): def submitLogin(self):
...@@ -809,6 +798,12 @@ class MainForm(Form): ...@@ -809,6 +798,12 @@ class MainForm(Form):
(self.browser._erp5_base_url, (self.browser._erp5_base_url,
self.browser._username, self.browser._username,
self.browser._password)) self.browser._password))
import Cookie
cookie = Cookie.SimpleCookie()
cookie.load(self.browser.headers['set-cookie'])
ac_value = cookie['__ac'].value
self.browser.cookies["__ac"] = ac_value
def submitSelectFavourite(self, label=None, value=None, **kw): def submitSelectFavourite(self, label=None, value=None, **kw):
""" """
...@@ -1187,7 +1182,6 @@ class ContextMainForm(MainForm): ...@@ -1187,7 +1182,6 @@ class ContextMainForm(MainForm):
# control), then get the item from its value # control), then get the item from its value
if isinstance(control, ListControl): if isinstance(control, ListControl):
control = control.getControl(value=input_element.get('value')) control = control.getControl(value=input_element.get('value'))
return control return control
from zope.testbrowser.browser import SubmitControl from zope.testbrowser.browser import SubmitControl
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment