def setUp(self): from plone.app.z3cform.widget import DateWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.field = Date(__name__='datefield') self.widget = DateWidget(self.request) self.widget.field = self.field self.widget.pattern_options = {'date': {'firstDay': 0}}
class DateWidgetTests(unittest.TestCase): def setUp(self): from plone.app.z3cform.widget import DateWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.field = Date(__name__='datefield') self.widget = DateWidget(self.request) self.widget.field = self.field self.widget.pattern_options = {'date': {'firstDay': 0}} def test_widget(self): current_year = datetime.today().year self.assertEqual( { 'pattern': 'pickadate', 'value': u'', 'name': None, 'pattern_options': { 'date': { 'firstDay': 0, 'min': [current_year - 100, 1, 1], 'max': [current_year + 20, 1, 1], 'clear': u'Clear', 'format': 'mmmm d, yyyy', 'monthsFull': [u'January', u'February', u'March', u'April', u'May', u'June', u'July', u'August', u'September', u'October', u'November', u'December'], 'weekdaysShort': [u'Sun', u'Mon', u'Tue', u'Wed', u'Thu', u'Fri', u'Sat'], 'weekdaysFull': [u'Sunday', u'Monday', u'Tuesday', u'Wednesday', u'Thursday', u'Friday', u'Saturday'], 'today': u'Today', 'selectYears': 200, 'placeholder': u'Enter date...', 'monthsShort': [u'Jan', u'Feb', u'Mar', u'Apr', u'May', u'Jun', u'Jul', u'Aug', u'Sep', u'Oct', u'Nov', u'Dec'] }, 'time': False } }, self.widget._base_args(), ) def test_data_converter(self): from plone.app.z3cform.widget import DateWidgetConverter converter = DateWidgetConverter(self.field, self.widget) self.assertEqual( converter.field.missing_value, converter.toFieldValue(''), ) self.assertEqual( date(2000, 10, 30), converter.toFieldValue('2000-10-30'), ) self.assertEqual( date(21, 10, 30), converter.toFieldValue('21-10-30'), ) self.assertEqual( '', converter.toWidgetValue(converter.field.missing_value), ) self.assertEqual( '2000-10-30', converter.toWidgetValue(date(2000, 10, 30)), ) self.assertEqual( '21-10-30', converter.toWidgetValue(date(21, 10, 30)), ) def test_fieldwidget(self): from plone.app.z3cform.widget import DateWidget from plone.app.z3cform.widget import DateFieldWidget field = Mock(__name__='field', title=u'', required=True) request = Mock() widget = DateFieldWidget(field, request) self.assertTrue(isinstance(widget, DateWidget)) self.assertIs(widget.field, field) self.assertIs(widget.request, request)
class DateWidgetTests(unittest.TestCase): def setUp(self): from plone.app.z3cform.widget import DateWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.field = Date(__name__='datefield') self.widget = DateWidget(self.request) self.widget.field = self.field self.widget.pattern_options = {'date': {'firstDay': 0}} def test_widget(self): current_year = datetime.today().year self.assertEqual( { 'pattern': 'pickadate', 'value': u'', 'name': None, 'pattern_options': { 'date': { 'firstDay': 0, 'min': [current_year - 100, 1, 1], 'max': [current_year + 20, 1, 1], 'clear': u'Clear', 'format': 'mmmm d, yyyy', 'monthsFull': [ u'January', u'February', u'March', u'April', u'May', u'June', u'July', u'August', u'September', u'October', u'November', u'December' ], 'weekdaysShort': [ u'Sun', u'Mon', u'Tue', u'Wed', u'Thu', u'Fri', u'Sat' ], 'weekdaysFull': [ u'Sunday', u'Monday', u'Tuesday', u'Wednesday', u'Thursday', u'Friday', u'Saturday' ], 'today': u'Today', 'selectYears': 200, 'placeholder': u'Enter date...', 'monthsShort': [ u'Jan', u'Feb', u'Mar', u'Apr', u'May', u'Jun', u'Jul', u'Aug', u'Sep', u'Oct', u'Nov', u'Dec' ] }, 'time': False } }, self.widget._base_args(), ) def test_data_converter(self): from plone.app.z3cform.widget import DateWidgetConverter converter = DateWidgetConverter(self.field, self.widget) self.assertEqual( converter.field.missing_value, converter.toFieldValue(''), ) self.assertEqual( date(2000, 10, 30), converter.toFieldValue('2000-10-30'), ) self.assertEqual( date(21, 10, 30), converter.toFieldValue('21-10-30'), ) self.assertEqual( '', converter.toWidgetValue(converter.field.missing_value), ) self.assertEqual( '2000-10-30', converter.toWidgetValue(date(2000, 10, 30)), ) self.assertEqual( '21-10-30', converter.toWidgetValue(date(21, 10, 30)), ) def test_fieldwidget(self): from plone.app.z3cform.widget import DateWidget from plone.app.z3cform.widget import DateFieldWidget field = Mock(__name__='field', title=u'', required=True) request = Mock() widget = DateFieldWidget(field, request) self.assertTrue(isinstance(widget, DateWidget)) self.assertIs(widget.field, field) self.assertIs(widget.request, request)