[Zope3-checkins] SVN: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/ checkpoint control that can set value in real browser

Benji York benji at zope.com
Sat Aug 19 10:12:14 EDT 2006


Log message for revision 69693:
  checkpoint control that can set value in real browser
  

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/__resources__/commands.js
  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 14:04:40 UTC (rev 69692)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py	2006-08-19 14:12:13 UTC (rev 69693)
@@ -1,4 +1,5 @@
 from cStringIO import StringIO
+from rwproperty import getproperty, setproperty
 from zope import interface
 from zope.testbrowser import interfaces
 from zope.testbrowser.utilities import disambiguate, any, onlyOne, zeroOrOne, \
@@ -112,30 +113,28 @@
     def multiple(self):
         return bool(getattr(self.mech_control, 'multiple', False))
 
-    @apply
-    def value():
+    @getproperty
+    def value(self):
         """See zope.testbrowser.interfaces.IControl"""
+        if (self.type == 'checkbox' and
+            len(self.mech_control.items) == 1 and
+            self.mech_control.items[0].name == 'on'):
+            return self.mech_control.items[0].selected
+        return self.mech_control.value
 
-        def fget(self):
-            if (self.type == 'checkbox' and
-                len(self.mech_control.items) == 1 and
-                self.mech_control.items[0].name == 'on'):
-                return self.mech_control.items[0].selected
-            return self.mech_control.value
+    @setproperty
+    def value(self, value):
+        if self._browser_counter != self.browser._counter:
+            raise interfaces.ExpiredError
+        if self.mech_control.type == 'file':
+            self.mech_control.add_file(value,
+                                       content_type=self.content_type,
+                                       filename=self.filename)
+        elif self.type == 'checkbox' and len(self.mech_control.items) == 1:
+            self.mech_control.items[0].selected = bool(value)
+        else:
+            self.mech_control.value = value
 
-        def fset(self, value):
-            if self._browser_counter != self.browser._counter:
-                raise interfaces.ExpiredError
-            if self.mech_control.type == 'file':
-                self.mech_control.add_file(value,
-                                           content_type=self.content_type,
-                                           filename=self.filename)
-            elif self.type == 'checkbox' and len(self.mech_control.items) == 1:
-                self.mech_control.items[0].selected = bool(value)
-            else:
-                self.mech_control.value = value
-        return property(fget, fset)
-
     def add_file(self, file, content_type, filename):
         if not self.mech_control.type == 'file':
             raise TypeError("Can't call add_file on %s controls"

Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/commands.js
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/commands.js	2006-08-19 14:04:40 UTC (rev 69692)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/__resources__/commands.js	2006-08-19 14:12:13 UTC (rev 69693)
@@ -60,7 +60,7 @@
             });
         }
         return resultArray;
-}
+    }
 //    function getElementsByTagNames(names, node) {
 //        var results = [];
 //        for (var i in names) {
@@ -94,6 +94,32 @@
     return id;
 }
 
+function getElementByUniquifier(u) {
+    var split = u.split(' ');
+    var kind = split[0];
+    var value = split[1];
+    var doc = top.frames[0].document;
+
+    if (kind == 'id') {
+        return doc.getElementById(value);
+    } else if (kind == 'form/control') {
+        split = value.split('/');
+        var form_number = Number(split[0]);
+        var control_number = Number(split[1]);
+        return doc.forms[form_number][control_number];
+    } else {
+        return undefined;
+    }
+}
+
+function _tb_setControlValue(info) {
+    log(info);
+    var uniquifier = info[0];
+    var value = info[1];
+    var element = getElementByUniquifier(uniquifier);
+    element.value = value; // XXX need to handle different ways of setting value
+}
+
 function _tb_clickRememberedLink(info) {
     log(info);
     var n = info[0];

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 14:04:40 UTC (rev 69692)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py	2006-08-19 14:12:13 UTC (rev 69693)
@@ -16,6 +16,7 @@
 __docformat__ = "reStructuredText"
 from BeautifulSoup import BeautifulSoup
 from StringIO import StringIO
+from zope.testbrowser.rwproperty import getproperty, setproperty
 from zope.testbrowser import interfaces
 from zope.testbrowser.forms import getControl, getForm, getAllControls, \
     ControlFactory, ListControl, SubmitControl, ImageControl, Control
@@ -31,6 +32,10 @@
 except ImportError:
     from dummymodules import interface
 
+
+def getControlUniquifier(control):
+    return 'form/control 0/0'
+
 class RealListControl(ListControl):
     pass
 
@@ -41,8 +46,18 @@
     pass
 
 class RealControl(Control):
-    pass
+    @setproperty
+    def value(self, value):
+        self.browser._clear()
+        self.browser.executeCommand(
+            'setControlValue', getControlUniquifier(self), value)
+        Control.value.fset(self, value)
 
+    @getproperty
+    def value(self):
+        return Control.value.fget(self)
+
+
 controlFactory = ControlFactory(RealListControl, RealSubmitControl,
                                 RealImageControl, RealControl)
 
@@ -225,6 +240,9 @@
 
     def _changed(self):
         self._counter += 1
+        self._clear()
+
+    def _clear(self):
         self._contents = None
         self._soup = None
         self._forms = None



More information about the Zope3-Checkins mailing list