3
0
Fork 0

fix: add way to set field widgets using pseudo-type

more to come on this idea hopefully..i think it's a good pattern?
This commit is contained in:
Lance Edgar 2024-12-11 23:05:25 -06:00
parent bf8397ba23
commit eda2326a97
3 changed files with 63 additions and 5 deletions

View file

@ -142,6 +142,26 @@ class TestForm(TestCase):
self.assertIs(form.widgets['foo'], new_widget)
self.assertIs(schema['foo'].widget, new_widget)
# can also just specify widget pseudo-type (invalid)
self.assertNotIn('bar', form.widgets)
self.assertRaises(ValueError, form.set_widget, 'bar', 'ldjfadjfadj')
# can also just specify widget pseudo-type (valid)
self.assertNotIn('bar', form.widgets)
form.set_widget('bar', 'notes')
self.assertIsInstance(form.widgets['bar'], widgets.NotesWidget)
def test_make_widget(self):
form = self.make_form(fields=['foo', 'bar'])
# notes
widget = form.make_widget('notes')
self.assertIsInstance(widget, widgets.NotesWidget)
# invalid
widget = form.make_widget('fdajvdafjjf')
self.assertIsNone(widget)
def test_set_grid(self):
form = self.make_form(fields=['foo', 'bar'])
self.assertNotIn('foo', form.widgets)