l.a.b.t.test_launchpadform_doc : module documentation

Part of lp.app.browser.tests

No module docstring
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 the custom_widget
Function test_suite Undocumented
def doctest_custom_widget_with_setUpFields_override():

As a regression test, it is important to note that the custom_widget class advisor 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, custom_widget)
>>> 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
def test_suite():
Undocumented
API Documentation for Launchpad, generated by pydoctor at 2018-02-24 00:00:04.