[Zope3-checkins]
SVN: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/
make the controlFactory use a configurable set of classes
Benji York
benji at zope.com
Sat Aug 19 09:06:07 EDT 2006
Log message for revision 69690:
make the controlFactory use a configurable set of classes
Changed:
U Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py
U Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
-=-
Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py 2006-08-19 13:00:50 UTC (rev 69689)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py 2006-08-19 13:06:04 UTC (rev 69690)
@@ -72,22 +72,6 @@
return disambiguate(matching_forms, '', index)
-def controlFactory(control, form, browser):
- if isinstance(control, ClientForm.Item):
- # it is a subcontrol
- return ItemControl(control, form, browser)
- else:
- t = control.type
- if t in ('checkbox', 'select', 'radio'):
- return ListControl(control, form, browser)
- elif t in ('submit', 'submitbutton'):
- return SubmitControl(control, form, browser)
- elif t=='image':
- return ImageControl(control, form, browser)
- else:
- return Control(control, form, browser)
-
-
class Control(SetattrErrorsMixin):
"""A control of a form."""
interface.implements(interfaces.IControl)
@@ -385,3 +369,30 @@
include_subcontrols=True)
control, form = disambiguate(intermediate, msg, index)
return controlFactory(control, form, self.browser)
+
+
+class ControlFactory(object):
+ def __init__(self, listControlClass, submitControlClass,
+ imageControlClass, controlClass):
+ self.listControlClass = listControlClass
+ self.submitControlClass = submitControlClass
+ self.imageControlClass = imageControlClass
+ self.controlClass = controlClass
+
+ def __call__(self, control, form, browser):
+ if isinstance(control, ClientForm.Item):
+ # it is a subcontrol
+ return ItemControl(control, form, browser)
+ else:
+ t = control.type
+ if t in ('checkbox', 'select', 'radio'):
+ return self.listControlClass(control, form, browser)
+ elif t in ('submit', 'submitbutton'):
+ return self.submitControlClass(control, form, browser)
+ elif t=='image':
+ return self.imageControlClass(control, form, browser)
+ else:
+ return self.controlClass(control, form, browser)
+
+controlFactory = ControlFactory(ListControl, SubmitControl, ImageControl,
+ Control)
Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py 2006-08-19 13:00:50 UTC (rev 69689)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py 2006-08-19 13:06:04 UTC (rev 69690)
@@ -12,15 +12,13 @@
#
##############################################################################
"""Browser-based Functional Doctests
-
-$Id$
"""
__docformat__ = "reStructuredText"
from BeautifulSoup import BeautifulSoup
from StringIO import StringIO
from zope.testbrowser import interfaces
from zope.testbrowser.forms import getControl, getForm, getAllControls, \
- controlFactory
+ ControlFactory, ListControl, SubmitControl, ImageControl, Control
from zope.testbrowser.real.proxy import ServerManager, PROXY_PORT
from zope.testbrowser.utilities import disambiguate, zeroOrOne, \
SetattrErrorsMixin, PystoneTimer
@@ -33,6 +31,22 @@
except ImportError:
from dummymodules import interface
+class RealListControl(ListControl):
+ pass
+
+class RealSubmitControl(SubmitControl):
+ pass
+
+class RealImageControl(ImageControl):
+ pass
+
+class RealControl(Control):
+ pass
+
+controlFactory = ControlFactory(RealListControl, RealSubmitControl,
+ RealImageControl, RealControl)
+
+
class DummyResponse(object):
def __init__(self, contents, url):
self.stringIo = StringIO(contents)
More information about the Zope3-Checkins
mailing list