test_widgets.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """Tests for the utils/widgets.py file."""
  2. from flaskbb.utils.widgets import SelectBirthdayWidget
  3. def test_select_birthday_widget():
  4. """Test the SelectDateWidget."""
  5. assert SelectBirthdayWidget.FORMAT_CHOICES['%d'] == [
  6. (x, str(x)) for x in range(1, 32)
  7. ]
  8. assert SelectBirthdayWidget.FORMAT_CHOICES['%m'] == [
  9. (x, str(x)) for x in range(1, 13)
  10. ]
  11. assert SelectBirthdayWidget.FORMAT_CLASSES == {
  12. '%d': 'select_date_day',
  13. '%m': 'select_date_month',
  14. '%Y': 'select_date_year'
  15. }
  16. select_birthday_widget = SelectBirthdayWidget(years=[0, 1])
  17. assert select_birthday_widget.FORMAT_CHOICES['%Y'] == [(0, '0'), (1, '1')]
  18. class Field(object):
  19. id = 'world'
  20. name = 'helloWorld'
  21. format = '%d %m %Y'
  22. data = None
  23. html = select_birthday_widget(field=Field(), surrounded_div="test-div")
  24. assert 'world' in html
  25. assert 'helloWorld' in html
  26. assert 'class="select_date_day"' in html
  27. assert 'class="select_date_month"' in html
  28. assert 'class="select_date_year"' in html
  29. assert '<div class="test-div">' in html