Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

test_widget.py 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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)
  38. class AdvancedSelectWidgetTestCase(TestCase):
  39. def test_widget_disabled_options(self):
  40. choices = (
  41. ('red', 'Red'),
  42. ('blue', 'Blue'),
  43. ('green', 'Green'),
  44. )
  45. disabled_values = ('red', 'green')
  46. i = widgets.AdvancedSelect(choices=choices, disabled_values=disabled_values)
  47. html = i.render('advselect', [])
  48. self.assertInHTML('<option value="blue">Blue</option>', html, count=1)
  49. self.assertInHTML('<option value="red" disabled>Red</option>', html, count=1)
  50. self.assertInHTML('<option value="green" disabled>Green</option>', html, count=1)