Changeset 9499 for main/waeup.kofa/trunk/src/waeup/kofa/widgets
- Timestamp:
- 2 Nov 2012, 02:19:06 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_datewidget.py
r8147 r9499 22 22 import doctest 23 23 from zope.schema import Date 24 from zope.interface import Interface, implementer 24 25 from zope.interface.verify import verifyClass 26 from zope.publisher.browser import TestRequest 25 27 26 28 from zope.formlib.tests.test_browserwidget import ( … … 42 44 _FieldFactory = Date 43 45 _WidgetFactory = FormattedDateWidget 46 47 def setUpContent(self, desc=u'', title=u'Foo Title'): 48 # same as in base class but with a min value of date(1910, 1, 1) 49 field = self._FieldFactory( 50 __name__='foo', title=title, description=desc, 51 min=datetime.date(1910, 1, 1)) 52 class ITestContent(Interface): 53 foo = field 54 @implementer(ITestContent) 55 class TestObject: 56 pass 57 self.content = TestObject() 58 field = ITestContent['foo'] 59 self.field = field.bind(self.content) 60 request = TestRequest(HTTP_ACCEPT_LANGUAGE='ru') 61 request.form['field.foo'] = u'Foo Value' 62 self._widget = self._WidgetFactory(field, request) 44 63 45 64 def testRender(self): … … 93 112 self.test_getDefaultInputValue(u'03/26/2004') 94 113 114 def test_minimal_value_respected(self): 115 # we did set up the date field to require dates >= 1900-01-01 116 request = TestRequest() 117 # setting a date > 1900-01-01 is okay 118 request.form['field.foo'] = '1912-03-27' 119 widget = FormattedDateWidget(self.field, request) 120 self.assertEqual( 121 widget.getInputValue(), datetime.date(1912, 3, 27)) 122 123 # setting a date < 1900-01-01 will fail 124 request.form['field.foo'] = '1812-03-27' 125 widget = FormattedDateWidget(self.field, request) 126 self.assertRaises( 127 WidgetInputError, 128 widget.getInputValue) 129 # check the correct exception message 130 try: 131 widget.getInputValue() 132 except WidgetInputError as exc: 133 # just catch the exception 134 pass 135 exc = '%r' % exc # turn exception into string 136 self.assertEqual( 137 exc, 138 "WidgetInputError('foo', u'Foo Title', " 139 "TooSmall(datetime.date(1812, 3, 27), datetime.date(1910, 1, 1)))" 140 ) 141 return 142 95 143 class FormattedDateDisplayWidgetTest(BrowserWidgetTest): 96 144 """The FormatterdDisplayDateWidget complies with IDisplayWidget.
Note: See TracChangeset for help on using the changeset viewer.