1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
BugTaskSourcePackageNameWidget
------------------------------
When dealing with bugs and packages, we associate bugs with only source
packages internally, not binary packages. However, sometimes users know
which binary package the bug is in, and they get confused why they
can't file a bug on that package. To allow people to enter a binary
package name, and to convert it to a source package name, we have a
custom widget.
>>> from lp.bugs.browser.widgets.bugtask import (
... BugTaskSourcePackageNameWidget)
If we pass a valid source package name to it, the corresponding
SourcePackageName will be returned by getInputValue(). In order for us
to map the package names, we need a distribution, so we give the widget
a distribution task to work with.
>>> from lp.services.webapp.servers import LaunchpadTestRequest
>>> from lp.bugs.interfaces.bug import IBugSet
>>> from lp.bugs.interfaces.bugtask import IBugTask
>>> bug_one = getUtility(IBugSet).get(1)
>>> ubuntu_task = bug_one.bugtasks[-2]
>>> ubuntu_task.distribution.name
u'ubuntu'
>>> package_field = IBugTask['sourcepackagename'].bind(ubuntu_task)
>>> request = LaunchpadTestRequest(
... form={'field.sourcepackagename': 'evolution'})
>>> widget = BugTaskSourcePackageNameWidget(
... package_field, package_field.vocabulary, request)
>>> widget.getInputValue()
<SourcePackageName ...>
>>> widget.getInputValue().name
u'evolution'
If we pass in a binary package name, which can be mapped to a source
package name, the corresponding SourcePackageName is returned.
>>> request = LaunchpadTestRequest(
... form={'field.sourcepackagename': 'linux-2.6.12'})
>>> widget = BugTaskSourcePackageNameWidget(
... package_field, package_field.vocabulary, request)
>>> widget.getInputValue()
<SourcePackageName ...>
>>> widget.getInputValue().name
u'linux-source-2.6.15'
For some distribution we don't know exactly which source packages it
contains, so IDistribution.guessPublishedSourcePackageName will raise a
NotFoundError.
>>> debian_task = bug_one.bugtasks[-1]
>>> debian_task.distribution.name
u'debian'
>>> debian_task.distribution.guessPublishedSourcePackageName('evolution')
Traceback (most recent call last):
...
NotFoundError...
At that point we'll fallback to the vocabulary, so a SourcePackageName
will still be returned.
>>> package_field = IBugTask['sourcepackagename'].bind(debian_task)
>>> request = LaunchpadTestRequest(
... form={'field.sourcepackagename': 'evolution'})
>>> widget = BugTaskSourcePackageNameWidget(
... package_field, package_field.vocabulary, request)
>>> widget.getInputValue()
<SourcePackageName ...>
>>> widget.getInputValue().name
u'evolution'
If we pass in a package name that doesn't exist in Launchpad, we get a
ConversionError saying that the package name doesn't exist.
>>> request = LaunchpadTestRequest(
... form={'field.sourcepackagename': 'no-package'})
>>> widget = BugTaskSourcePackageNameWidget(
... package_field, package_field.vocabulary, request)
>>> widget.getInputValue()
Traceback (most recent call last):
...
ConversionError...
BugTaskAlsoAffectsSourcePackageNameWidget
-----------------------------------------
The +distrotask page accepts both source and binary package names, but
the distribution can't be obtained from the widget's context. For this
page, BugTaskAlsoAffectsSourcePackageNameWidget exists, which gets the
distribution from the request.
>>> from lp.bugs.browser.widgets.bugtask import (
... BugTaskAlsoAffectsSourcePackageNameWidget)
>>> request = LaunchpadTestRequest(
... form={'field.distribution': 'debian',
... 'field.sourcepackagename': 'linux-2.6.12'})
>>> widget = BugTaskAlsoAffectsSourcePackageNameWidget(
... package_field, package_field.vocabulary, request)
>>> widget.getDistribution().name
u'debian'
+distrotask always supplies a valid distribution name. If the widget
doesn't get a name, or the name isn't the name of a distro,
UnexpectedFormData is raised.
>>> request = LaunchpadTestRequest(
... form={'field.distribution': 'non-existing',
... 'field.sourcepackagename': 'linux-2.6.12'})
>>> widget = BugTaskAlsoAffectsSourcePackageNameWidget(
... package_field, package_field.vocabulary, request)
>>> widget.getDistribution().name
Traceback (most recent call last):
...
UnexpectedFormData: ...
>>> request = LaunchpadTestRequest(
... form={'field.sourcepackagename': 'linux-2.6.12'})
>>> widget = BugTaskAlsoAffectsSourcePackageNameWidget(
... package_field, package_field.vocabulary, request)
>>> widget.getDistribution().name
Traceback (most recent call last):
...
UnexpectedFormData: ...
|