= Widget for entering a bug id = The BugWidget converts string bug ids to the corresponding bug object. >>> from lp.services.webapp.servers import LaunchpadTestRequest >>> from lp.bugs.browser.widgets.bug import BugWidget >>> from lp.services.fields import BugField >>> bug_field = BugField(__name__='bug', title=u'Bug') >>> request = LaunchpadTestRequest(form={'field.bug': '1'}) >>> bug_widget = BugWidget(bug_field, request) >>> bug_one = bug_widget.getInputValue() >>> from lp.bugs.interfaces.bug import IBug >>> IBug.providedBy(bug_one) True >>> bug_one.id 1 If non-existant bug number is entered, an error is raised. >>> request = LaunchpadTestRequest(form={'field.bug': '1234567'}) >>> bug_widget = BugWidget(bug_field, request) >>> bug_widget.getInputValue() Traceback (most recent call last): ... ConversionError: ('Not a valid bug number or nickname.', None) It's quite common that bug ids are prefixed by '#', so such inputs are accepted as well. >>> request = LaunchpadTestRequest(form={'field.bug': '#2'}) >>> bug_widget = BugWidget(bug_field, request) >>> bug_two = bug_widget.getInputValue() >>> IBug.providedBy(bug_two) True >>> bug_two.id 2 Leading and trailing whitespace is also stripped from the input. >>> request = LaunchpadTestRequest(form={'field.bug': ' #3 '}) >>> bug_widget = BugWidget(bug_field, request) >>> bug_three = bug_widget.getInputValue() >>> IBug.providedBy(bug_three) True >>> bug_three.id 3