Class | LaunchpadFormTest | No class docstring; 1/2 methods documented |
Function | doctest_custom_widget_with_setUpFields_override | As a regression test, it is important to note that custom widgets |
Function | test_suite | Undocumented |
As a regression test, it is important to note that custom widgets should still work when setUpFields is overridden. For instance, consider this custom widget and view:
>>> from zope.formlib.interfaces import IDisplayWidget, IInputWidget >>> from zope.interface import directlyProvides, implements >>> from lp.app.browser.launchpadform import LaunchpadFormView >>> from zope.schema import Bool >>> from zope.publisher.browser import TestRequest >>> from zope.formlib import form>>> class CustomStubWidget: ... implements(IInputWidget) ... # The methods below are the minimal necessary for widget ... # initialization. ... def __init__(self, field, request): ... self.field, self.request = field, request ... def setPrefix(self, prefix): ... self.name = '.'.join((prefix, self.field.__name__)) ... def hasInput(self): ... return False ... def setRenderedValue(self, value): ... self.value = value ... >>> class CustomView(LaunchpadFormView): ... custom_widget_my_bool = CustomStubWidget ... def setUpFields(self): ... self.form_fields = form.Fields(Bool(__name__='my_bool')) ...
The custom setUpFields adds a field dynamically. Then setUpWidgets will use the custom widget for the field. We simply call setUpFields and setUpWidgets explicitly here for ease of testing, though normally they are called by LaunchpadFormView.initialize.
>>> view = CustomView(None, TestRequest()) >>> view.setUpFields() >>> view.setUpWidgets() >>> isinstance(view.widgets['my_bool'], CustomStubWidget) True