[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Forms/Views/Browser/tests - SchemaTestObject.py:1.3 testFormView.py:1.7
Stephan Richter
srichter@cbu.edu
Tue, 16 Jul 2002 22:36:38 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv489/lib/python/Zope/App/Forms/Views/Browser/tests
Modified Files:
SchemaTestObject.py testFormView.py
Log Message:
I finished the tests for the FormView now. Next I will make the
SchemaTestObject work in Zope runtime and tehn I will try to work on a
simple Layouter before fixing teh Bug Collector for an initial checkin.
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/SchemaTestObject.py 1.2 => 1.3 ===
$Id$
"""
import Schema
+from Schema.Converter import StrToIntConverter
from Zope.Publisher.HTTP.tests.TestRequest import TestRequest
from Zope.Publisher.Browser.IBrowserView import IBrowserView
@@ -44,7 +45,7 @@
class STestObject(Schema.Schema):
"""A simple Schema."""
- id = Schema.Str(
+ id = Schema.Int(
id="id",
title="Id",
required=1)
@@ -82,7 +83,9 @@
class Edit(FormView):
"""A simple Edit View"""
form = ViewPageTemplateFile('testEditForm.pt')
- custom_widgets = {'creator': CustomWidget(Widget.TextWidget,
+ custom_widgets = {'id': CustomWidget(Widget.TextWidget,
+ converter=StrToIntConverter()),
+ 'creator': CustomWidget(Widget.TextWidget,
displayWidth=30),
'data': CustomWidget(Widget.FileWidget)}
=== Zope3/lib/python/Zope/App/Forms/Views/Browser/tests/testFormView.py 1.6 => 1.7 ===
viewService = self.getViewService()
viewService.provideView(IStr, 'widget', IBrowserView, [TextWidget])
request = SchemaTestObject.TestBrowserRequest(
- {'field_id': 1, 'field_title': 'Test New',
+ {'field_id': '1', 'field_title': 'Test New',
'field_creator': 'srichter@cbu.edu', 'field_data': 'Data'})
self._form = SchemaTestObject.EditFactory(request=request)
@@ -94,6 +94,47 @@
self.assertEqual('<input name="field_creator" type="text" '
'value="srichter@cbu.edu" size="30" />',
self._form.renderField(field))
+
+
+ def testGetAllRawFieldData(self):
+ data = self._form.getAllRawFieldData()
+ result = {'data': 'Data', 'id': '1', 'title': 'Test New',
+ 'creator': 'srichter@cbu.edu'}
+ for field in data.keys():
+ self.assertEqual(result[field.id], data[field])
+
+
+ def testConvertAllFieldData(self):
+ data = self._form.getAllRawFieldData()
+ data = self._form.convertAllFieldData(data)
+ result = {'data': 'Data', 'id': 1, 'title': 'Test New',
+ 'creator': 'srichter@cbu.edu'}
+ for field in data.keys():
+ self.assertEqual(result[field.id], data[field])
+
+
+ def testValidateAllFieldData(self):
+ data = self._form.getAllRawFieldData()
+ data = self._form.convertAllFieldData(data)
+ self.assertEqual(None, self._form.validateAllFieldData(data))
+
+
+ def testStoreAllDataInContext(self):
+ data = self._form.getAllRawFieldData()
+ data = self._form.convertAllFieldData(data)
+ self._form.storeAllDataInContext(data)
+ obj = self._form.context
+ for field in data.keys():
+ self.assertEqual(data[field], getattr(obj, field.id))
+
+
+ def testSaveValuesInContect(self):
+ data = self._form.getAllRawFieldData()
+ data = self._form.convertAllFieldData(data)
+ self._form.saveValuesInContext()
+ obj = self._form.context
+ for field in data.keys():
+ self.assertEqual(data[field], getattr(obj, field.id))
def test_suite():