def test_render_assigns_ids_and_labels(self): widget = UswdsDateWidget() content = widget.render('boop', None, {'id': 'blarg'}) self.assertRegexpMatches(content, 'id="blarg_0"') self.assertRegexpMatches(content, 'id="blarg_1"') self.assertRegexpMatches(content, 'id="blarg_2"') self.assertRegexpMatches(content, 'for="blarg_0"') self.assertRegexpMatches(content, 'for="blarg_1"') self.assertRegexpMatches(content, 'for="blarg_2"')
def test_get_field_names_works(self): names = UswdsDateWidget.get_field_names('boop') self.assertEqual(names.year, 'boop_0') self.assertEqual(names.month, 'boop_1') self.assertEqual(names.day, 'boop_2')
def test_decompress_works_with_none(self): widget = UswdsDateWidget() self.assertEqual(widget.decompress(None), [None, None, None])
def test_decompress_works_with_dates(self): widget = UswdsDateWidget() self.assertEqual(widget.decompress(date(2005, 6, 28)), [2005, 6, 28])
def test_render_does_not_raise_exception_on_empty_lists(self): widget = UswdsDateWidget() content = widget.render('boop', [], {'id': 'foo'}) # The <input>s should not have any 'value' attribute whatsoever. self.assertNotRegexpMatches(content, 'value')
def test_render_takes_value_as_date(self): widget = UswdsDateWidget() content = widget.render('boop', date(2005, 6, 28), {'id': 'foo'}) self.assertRegexpMatches(content, 'value="2005"') self.assertRegexpMatches(content, 'value="6"') self.assertRegexpMatches(content, 'value="28"')
def test_render_takes_value_as_list(self): widget = UswdsDateWidget() content = widget.render('boop', [2006, 7, 29], {'id': 'foo'}) self.assertRegexpMatches(content, 'value="2006"') self.assertRegexpMatches(content, 'value="7"') self.assertRegexpMatches(content, 'value="29"')
def test_render_assigns_hint_id_and_aria_describedby(self): widget = UswdsDateWidget() content = widget.render('boop', None, {'id': 'foo'}) self.assertRegexpMatches(content, 'id="foo_hint"') self.assertRegexpMatches(content, 'aria-describedby="foo_hint"')
def test_render_assigns_names(self): widget = UswdsDateWidget() content = widget.render('boop', None, {'id': 'blarg'}) self.assertRegexpMatches(content, 'name="boop_0"') self.assertRegexpMatches(content, 'name="boop_1"') self.assertRegexpMatches(content, 'name="boop_2"')