class DatetimeWidgetTests(unittest.TestCase): def setUp(self): from plone.app.widgets.at import DatetimeWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.context = mock.Mock() self.field = mock.Mock() self.field.getAccessor.return_value = lambda: u'' self.field.getName.return_value = 'fieldname' self.widget = DatetimeWidget() def test_widget(self): self.assertEqual( { 'pattern': 'pickadate', 'value': u'', 'name': 'fieldname', 'pattern_options': { 'date': { 'min': [1913, 1, 1], 'max': [2033, 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': { 'placeholder': u'Enter time...', 'today': u'Today', 'format': 'h:i a' } } }, self.widget._base_args(self.context, self.field, self.request), ) def test_process_form(self): form = { 'fieldname': '2011-11-22 13:30', } self.assertEqual( self.widget.process_form( self.context, self.field, form)[0].asdatetime(), (datetime(2011, 11, 22, 13, 30)) )
def setUp(self): from plone.app.widgets.at import DatetimeWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.context = Mock() self.field = Mock() self.field.getAccessor.return_value = lambda: DateTime( '2013-11-13 10:20 Europe/Amsterdam') self.field.getName.return_value = 'fieldname' self.widget = DatetimeWidget()
def test_localization(self): from plone.app.widgets.base import DatetimeWidget request_en = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) widget_en = DatetimeWidget(request=request_en) self.assertEqual( widget_en.render(), '<input class="pat-pickadate" type="datetime-local" data-pat-pickadate="{"date": {"format": "mmmm d, yyyy", "max": [2033, 1, 1], "clear": "Clear", "min": [1913, 1, 1], "monthsFull": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], "weekdaysShort": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], "weekdaysFull": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], "today": "Today", "selectYears": 200, "formatSubmit": "yyyy-mm-dd", "monthsShort": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]}, "time": {"formatSubmit": "HH:i", "format": "HH:i"}}"/>') # noqa request_de = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'de'}) widget_de = DatetimeWidget(request=request_de) self.assertEqual( widget_de.render(), '<input class="pat-pickadate" type="datetime-local" data-pat-pickadate="{"date": {"format": "mmmm d, yyyy", "max": [2033, 1, 1], "clear": "Clear", "min": [1913, 1, 1], "monthsFull": ["Januar", "Februar", "M\\u00e4rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"], "weekdaysShort": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"], "weekdaysFull": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"], "today": "Today", "selectYears": 200, "formatSubmit": "yyyy-mm-dd", "monthsShort": ["Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]}, "time": {"formatSubmit": "HH:i", "format": "HH:i"}}"/>') # noqa
def setUp(self): from plone.app.widgets.at import DatetimeWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.context = mock.Mock() self.field = mock.Mock() self.field.getAccessor.return_value = lambda: u'' self.field.getName.return_value = 'fieldname' self.widget = DatetimeWidget()
def setUp(self): from plone.app.widgets.at import DatetimeWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.context = Mock() self.field = Mock() self.field.getAccessor.return_value = lambda: DateTime( '2013-11-13 10:20 Europe/Amsterdam' ) self.field.getName.return_value = 'fieldname' self.widget = DatetimeWidget()
def test_defaults(self): from plone.app.widgets.base import DatetimeWidget widget = DatetimeWidget() self.assertEqual( widget.render(), '<input class="pat-pickadate" type="datetime-local" data-pat-pickadate="{"date": {"formatSubmit": "yyyy-mm-dd", "format": "mmmm d, yyyy"}, "time": {"formatSubmit": "HH:i", "format": "HH:i"}}"/>') # noqa
def createWidget(self, lang='en', **kw): from plone.app.widgets.at import DatetimeWidget widget = DatetimeWidget(**kw) widget.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': lang}) return widget
class DatetimeWidgetTests(unittest.TestCase): def setUp(self): from plone.app.widgets.at import DatetimeWidget self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) self.context = Mock() self.field = Mock() self.field.getAccessor.return_value = lambda: DateTime( '2013-11-13 10:20 Europe/Amsterdam') self.field.getName.return_value = 'fieldname' self.widget = DatetimeWidget() def test_widget(self): self.assertEqual( { 'pattern': 'pickadate', 'value': '2013-11-13 10:20', 'name': 'fieldname', 'pattern_options': { 'date': { 'firstDay': 0, 'min': [1914, 1, 1], 'max': [2034, 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': { 'placeholder': u'Enter time...', 'today': u'Today', 'format': 'h:i a' } } }, self.widget._base_args(self.context, self.field, self.request), ) def test_process_form(self): form = { 'fieldname': '2011-11-22 13:30', } self.assertEqual( self.widget.process_form(self.context, self.field, form)[0].asdatetime(), (datetime(2011, 11, 22, 13, 30)))