[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/f
Merged r26269 from trunk.
Garrett Smith
garrett at mojave-corp.com
Thu Jul 8 19:17:34 EDT 2004
Log message for revision 26270:
Merged r26269 from trunk.
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/file/interfaces.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/file/interfaces.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/file/interfaces.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -33,6 +33,7 @@
title=_(u'Data'),
description=_(u'The actual content of the object.'),
default='',
+ missing_value='',
required=False,
)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_filewidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_filewidget.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_filewidget.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -114,41 +114,41 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.f1, self.sampleText)
self.assertEqual(object.f2, self.sampleText)
- def XXX_test_invalid_value(self):
+ def test_invalid_value(self):
+ """Invalid input is treated as 'no input' by the file widget.
+
+ To test this, we submit an invalid value for a required field f1.
+ """
self.getRootFolder()['test'] = FileTest()
get_transaction().commit()
# submit an invalid file value
response = self.publish('/test/edit.html', form={
'UPDATE_SUBMIT' : '',
- 'field.f1' : 'not a file' })
+ 'field.f1' : 'not a file - same as missing input' })
self.assertEqual(response.getStatus(), 200)
-
- print response.getBody()
-
self.assert_(validationErrorExists('f1',
- 'Value is not a file object', response.getBody()))
+ 'Form input is not a file object', response.getBody()))
- def XXX_test_required_validation(self):
- self.getRootFolder()['test'] = TextLineTest()
+ def test_required_validation(self):
+ self.getRootFolder()['test'] = FileTest()
get_transaction().commit()
- # submit missing values for required field s1
+ # submit missing value for required field f1
response = self.publish('/test/edit.html', form={
'UPDATE_SUBMIT' : '',
- 'field.f1' : sampleTextFile,
- 'field.f2' : '' })
+ 'field.f1' : '',
+ 'field.f2' : self.sampleTextFile })
self.assertEqual(response.getStatus(), 200)
# confirm error msgs
- self.assert_(missingInputErrorExists('s1', response.getBody()))
- self.assert_(not missingInputErrorExists('s2', response.getBody()))
+ self.assert_(missingInputErrorExists('f1', response.getBody()))
+ self.assert_(not missingInputErrorExists('f2', response.getBody()))
def test_empty_file(self):
@@ -164,7 +164,6 @@
# new value for f1 should be field.missing_value (i.e, None)
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assert_(object.f1 is None)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_floatwidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_floatwidget.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_floatwidget.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -102,7 +102,6 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.f1, 1.123)
self.assertEqual(object.f2, 2.23456789012345)
self.assertEqual(object.f3, 11.1)
@@ -123,7 +122,6 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.f1, 1.1)
self.assertEqual(object.f2, None) # None is default missing_value
self.assertEqual(object.f3, 0) # 0 is from f3.missing_value=0
@@ -200,7 +198,6 @@
# check new value in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assert_(object.f1 is None)
self.assert_(object.f2 is None)
self.assertEqual(object.f3, 2.1)
@@ -215,9 +212,8 @@
'UPDATE_SUBMIT' : '',
'field.f1' : 'foo' })
self.assertEqual(response.getStatus(), 200)
- # XXX - reinstate when widget errors are cleaned up
- # self.assert_(validationErrorExists('f1',
- # 'Invalid floating point data', response.getBody()))
+ self.assert_(validationErrorExists('f1',
+ 'Invalid floating point data', response.getBody()))
def test_suite():
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_intwidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_intwidget.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_intwidget.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -123,7 +123,6 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.i1, 1)
self.assertEqual(object.i2, 2)
self.assertEqual(object.i3, 3)
@@ -144,7 +143,6 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.i1, 1)
self.assertEqual(object.i2, None) # None is default missing_value
self.assertEqual(object.i3, 0) # 0 is from i3.missing_value=0
@@ -181,7 +179,6 @@
# confirm new value is -1 -- i1.missing_value
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.i1, -1)
@@ -256,7 +253,6 @@
# check new value in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assert_(object.i1 is None)
self.assert_(object.i2 is None)
self.assertEqual(object.i3, 2)
@@ -271,9 +267,8 @@
'UPDATE_SUBMIT' : '',
'field.i1' : 'foo' })
self.assertEqual(response.getStatus(), 200)
- # XXX reinstate when widget errors are fixed
- # self.assert_(validationErrorExists('i1', 'Invalid integer data',
- # response.getBody()))
+ self.assert_(validationErrorExists('i1', 'Invalid integer data',
+ response.getBody()))
def test_suite():
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_textareawidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_textareawidget.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_textareawidget.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -98,26 +98,28 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.s1, u'foo')
self.assertEqual(object.s2, u'bar')
self.assertEqual(object.s3, u'baz')
def test_invalid_type(self):
+ """Tests textarea widget's handling of invalid unicode input.
+
+ The text widget will succeed in converting any form input into
+ unicode.
+ """
self.getRootFolder()['test'] = TextTest()
get_transaction().commit()
# submit invalid type for text
response = self.publish('/test/edit.html', form={
'UPDATE_SUBMIT' : '',
- 'field.s1' : 'foo' }) # not unicode
-
+ 'field.s1' : 123 }) # not unicode
self.assertEqual(response.getStatus(), 200)
- # XXX We don't have a invalid field value
- # since we convert the value to unicode
- self.assert_(not validationErrorExists(
- 's1', 'Object is of wrong type.', response.getBody()))
+
+ object = traverse(self.getRootFolder(), 'test')
+ self.assert_(object.s1, '123')
def test_missing_value(self):
@@ -135,7 +137,6 @@
# check new value in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.s1, u'foo')
self.assertEqual(object.s2, u'') # default missing_value
self.assertEqual(object.s3, None) # None is s3's missing_value
@@ -200,7 +201,6 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.s1, '')
self.assertEqual(object.s2, u'bar')
self.assert_(object.s3 is None)
@@ -217,7 +217,6 @@
self.assertEqual(response.getStatus(), 200)
self.assert_(updatedMsgExists(response.getBody()))
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.s2, u'line1\nline2')
# confirm conversion to HTML
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_textwidget.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_textwidget.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/ftests/test_textwidget.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -96,28 +96,29 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.s1, u'foo')
self.assertEqual(object.s2, u'bar')
self.assertEqual(object.s3, u'Uncle')
def test_invalid_type(self):
+ """Tests text widget's handling of invalid unicode input.
+
+ The text widget will succeed in converting any form input into
+ unicode.
+ """
self.getRootFolder()['test'] = TextLineTest()
get_transaction().commit()
# submit invalud type for text line
response = self.publish('/test/edit.html', form={
'UPDATE_SUBMIT' : '',
- 'field.s1' : '' }) # not unicode
-
+ 'field.s1' : 123 }) # not unicode
self.assertEqual(response.getStatus(), 200)
- # XXX We don't have a invalid field value
- #since we convert the value to unicode
- self.assert_(not validationErrorExists(
- 's1', 'Object is of wrong type.', response.getBody()))
+
+ object = traverse(self.getRootFolder(), 'test')
+ self.assert_(object.s1, u'123')
-
def test_missing_value(self):
self.getRootFolder()['test'] = TextLineTest()
get_transaction().commit()
@@ -133,7 +134,6 @@
# check new values in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.s1, u'foo')
self.assertEqual(object.s2, u'') # default missing_value
self.assertEqual(object.s3, None) # None is s3's missing_value
@@ -210,7 +210,6 @@
# check new value in object
object = traverse(self.getRootFolder(), 'test')
- object._p_jar.sync()
self.assertEqual(object.s1, '')
self.assertEqual(object.s2, u'bar')
self.assert_(object.s3 is None)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/textwidgets.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/textwidgets.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/browser/textwidgets.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -133,14 +133,10 @@
if self.convert_missing_value and input == self._missing:
value = self.context.missing_value
else:
- # XXX We convert everything to unicode :-(
- # But I see no other way for to convert the
- # value at the moment.
try:
value = unicode(input)
except ValueError, v:
raise ConversionError("Invalid integer data", v)
-
return decode_html(value)
@@ -257,13 +253,13 @@
def _toFieldValue(self, value):
value = super(TextAreaWidget, self)._toFieldValue(value)
if value:
- value = decode_html(value)
- value = value.replace("\r\n", "\n")
- # Converting the value to unicode.
try:
value = unicode(value)
except ValueError, v:
raise ConversionError("Invalid unicode data", v)
+ else:
+ value = decode_html(value)
+ value = value.replace("\r\n", "\n")
return value
def _toFormValue(self, value):
@@ -358,27 +354,9 @@
size=self.displayWidth,
extra=self.extra)
- def hasInput(self):
- file = self.request.form.get(self.name)
- if file is None:
- return False
-
- if getattr(file, 'filename', ''):
- return True
-
- try:
- seek = file.seek
- read = file.read
- except AttributeError:
- return False
-
- seek(0)
- if read(1):
- return True
-
- return False
-
def _toFieldValue(self, input):
+ if input == '':
+ return self.context.missing_value
try:
seek = input.seek
read = input.read
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/form/tests/test_utility.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/form/tests/test_utility.py 2004-07-08 23:14:11 UTC (rev 26269)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/form/tests/test_utility.py 2004-07-08 23:17:34 UTC (rev 26270)
@@ -852,9 +852,6 @@
def test_widgetsErrorException(self):
"""Documents and tests WidgetsError.
- XXX Move this test into zope.app.interfaces.tests.test_form when
- that module is created.
-
WidgetsError wraps one or more errors, which are specified as a
sequence in the 'errors' argument:
More information about the Zope3-Checkins
mailing list