You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_widget.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. from django.test import TestCase
  4. from oscar.forms import widgets
  5. class TestWidgetsDatetimeFormat(TestCase):
  6. def test_datetime_to_date_format_conversion(self):
  7. format_testcases = (
  8. ('%Y-%m-%d', 'yyyy-mm-dd'),
  9. ('%Y-%m-%d %H:%M', 'yyyy-mm-dd'),
  10. )
  11. for format_, expected in format_testcases:
  12. self.assertEqual(widgets.datetime_format_to_js_date_format(format_), expected)
  13. def test_datetime_to_time_format_conversion(self):
  14. format_testcases = (
  15. ('%Y-%m-%d %H:%M', 'hh:ii'),
  16. ('%H:%M', 'hh:ii'),
  17. )
  18. for format_, expected in format_testcases:
  19. self.assertEqual(widgets.datetime_format_to_js_time_format(format_), expected)
  20. def test_timepickerinput_format_unicode(self):
  21. # Check that the widget can handle unicode formats
  22. i = widgets.TimePickerInput(format=u'τ-%H:%M')
  23. time = datetime.time(10, 47)
  24. html = i.render('time', time)
  25. self.assertIn(u'value="τ-10:47"', html)
  26. def test_datepickerinput_format_unicode(self):
  27. # Check that the widget can handle unicode formats
  28. i = widgets.DatePickerInput(format=u'δ-%d/%m/%Y')
  29. date = datetime.date(2017, 5, 1)
  30. html = i.render('date', date)
  31. self.assertIn(u'value="δ-01/05/2017"', html)
  32. def test_datetimepickerinput_format_unicode(self):
  33. # Check that the widget can handle unicode formats
  34. i = widgets.DateTimePickerInput(format=u'δ-%d/%m/%Y %H:%M')
  35. date = datetime.datetime(2017, 5, 1, 10, 57)
  36. html = i.render('datetime', date)
  37. self.assertIn(u'value="δ-01/05/2017 10:57"', html)