~launchpad-pqm/launchpad/devel

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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
= Setting the status of a bug =

If you have a bug and a target, there's method which makes it easier to
change the bug's status for that specific target. It expects the user
changing the status, the target, and the new status.

    >>> from lp.testing.dbuser import lp_dbuser
    >>> from lp.registry.interfaces.person import IPersonSet
    >>> from lp.bugs.interfaces.bug import CreateBugParams
    >>> from lp.bugs.interfaces.bugtask import BugTaskStatus
    >>> from lp.registry.interfaces.product import IProductSet

    >>> with lp_dbuser():
    ...     login('no-priv@canonical.com')
    ...     no_priv = getUtility(IPersonSet).getByName('no-priv')
    ...     bug_params = CreateBugParams(
    ...         owner=no_priv, title='Sample bug', comment='This is a sample bug.')
    ...     firefox = getUtility(IProductSet).getByName('firefox')
    ...     bug = firefox.createBug(bug_params)
    ...     bug_id = bug.id
    ...     # Set a milestone to ensure that the current db user has enough
    ...     # privileges to access it.
    ...     [firefox_task] = bug.bugtasks
    ...     firefox_task.milestone = firefox.getMilestone('1.0')

    >>> from lp.bugs.interfaces.bug import IBugSet
    >>> bug = getUtility(IBugSet).get(bug_id)
    >>> no_priv = getUtility(IPersonSet).getByName('no-priv')
    >>> firefox = getUtility(IProductSet).getByName('firefox')
    >>> firefox_bugtask = bug.setStatus(
    ...     firefox, BugTaskStatus.CONFIRMED, no_priv)

It returns the edited bugtask.

    >>> firefox_bugtask.target.name
    u'firefox'
    >>> firefox_bugtask.status.name
    'CONFIRMED'

It also emits an ObjectModifiedEvent so that BugNotification and
BugActivity records are created.

    >>> from lp.bugs.model.bugnotification import BugNotification
    >>> latest_notification = BugNotification.selectFirst(orderBy='-id')
    >>> print latest_notification.message.owner.displayname
    No Privileges Person
    >>> print latest_notification.message.text_contents
    ** Changed in: firefox
           Status: New => Confirmed

    >>> from lp.bugs.model.bugactivity import BugActivity
    >>> latest_activity = BugActivity.selectFirst(orderBy='-id')
    >>> latest_activity.whatchanged
    u'firefox: status'
    >>> latest_activity.oldvalue
    u'New'
    >>> latest_activity.newvalue
    u'Confirmed'

The edited bugtask is only returned if it's actually edited. If the
bugtask already has the specified status, None is returned.

    >>> firefox_bugtask.status.name
    'CONFIRMED'
    >>> print bug.setStatus(firefox, BugTaskStatus.CONFIRMED, no_priv)
    None

=== Product series ===

If a product series is specified, but the bug is target only to the
product, not the product series, the product bugtask is edited.

    >>> firefox_trunk = firefox.getSeries('trunk')
    >>> bug.getBugTask(firefox_trunk) is None
    True
    >>> firefox_bugtask = bug.setStatus(
    ...     firefox_trunk, BugTaskStatus.NEW, no_priv)
    >>> firefox_bugtask.target.name
    u'firefox'
    >>> firefox_bugtask.status.name
    'NEW'

If the bug is targeted to the product series, the product series bugtask
is edited.

    >>> from lp.bugs.interfaces.bugtask import IBugTaskSet
    >>> with lp_dbuser():
    ...     bug = getUtility(IBugSet).get(bug_id)
    ...     no_priv = getUtility(IPersonSet).getByName('no-priv')
    ...     firefox = getUtility(IProductSet).getByName('firefox')
    ...     firefox_trunk = firefox.getSeries('trunk')
    ...     ignore = getUtility(IBugTaskSet).createTask(
    ...         bug, productseries=firefox_trunk, owner=no_priv)

    >>> bug = getUtility(IBugSet).get(bug_id)
    >>> no_priv = getUtility(IPersonSet).getByName('no-priv')
    >>> firefox = getUtility(IProductSet).getByName('firefox')
    >>> firefox_trunk = firefox.getSeries('trunk')
    >>> firefox_trunk_bugtask = bug.setStatus(
    ...     firefox_trunk, BugTaskStatus.INCOMPLETE, no_priv)

    >>> firefox_trunk_bugtask.target.name
    u'trunk'
    >>> firefox_trunk_bugtask.status.name
    'INCOMPLETE'

If the target bugtask has a conjoined master bugtask, the conjoined
master will be edited and returned. The conjoined slave is of course
updated automatically.

    >>> firefox_bugtask = firefox_trunk_bugtask.conjoined_slave
    >>> firefox_bugtask.target.name
    u'firefox'
    >>> firefox_bugtask.conjoined_master is not None
    True
    >>> firefox_bugtask.status.name
    'INCOMPLETE'
    >>> firefox_trunk_bugtask = bug.setStatus(
    ...     firefox_bugtask.target, BugTaskStatus.CONFIRMED, no_priv)
    >>> firefox_trunk_bugtask.target.name
    u'trunk'
    >>> firefox_trunk_bugtask.status.name
    'CONFIRMED'
    >>> firefox_bugtask.status.name
    'CONFIRMED'

=== Distributions and packages ===

Setting the status of a distribution or package bugtask work the same as
for product tasks.

    >>> from lp.registry.interfaces.distribution import IDistributionSet
    >>> with lp_dbuser():
    ...     ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
    ...     # Set a milestone to ensure that the current db user has enough
    ...     # privileges to access it.
    ...     ubuntu_hoary = ubuntu.getSeries('hoary')
    ...     # Only owners, experts, or admins can create a milestone.
    ...     login('foo.bar@canonical.com')
    ...     feature_freeze = ubuntu_hoary.newMilestone('feature-freeze')
    ...     login('no-priv@canonical.com')
    ...     bug = ubuntu.createBug(bug_params)
    ...     [ubuntu_bugtask] = bug.bugtasks
    ...     ubuntu_bugtask.milestone = feature_freeze
    ...     bug_id = bug.id

    >>> bug = getUtility(IBugSet).get(bug_id)
    >>> no_priv = getUtility(IPersonSet).getByName('no-priv')
    >>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
    >>> ubuntu_bugtask = bug.setStatus(
    ...     ubuntu, BugTaskStatus.CONFIRMED, no_priv)
    >>> ubuntu_bugtask.target.name
    u'ubuntu'
    >>> ubuntu_bugtask.status.name
    'CONFIRMED'

If a source package is given, but no such package exists, no bugtask
will be edited.

    >>> ubuntu_firefox = ubuntu.getSourcePackage('mozilla-firefox')
    >>> bug.setStatus(ubuntu_firefox, BugTaskStatus.CONFIRMED, no_priv) is None
    True

If the bug is targeted to a source package, that bugtask is of course
edited.

    >>> ubuntu_bugtask.transitionToTarget(ubuntu_firefox)
    >>> ubuntu_firefox_task = bug.setStatus(
    ...     ubuntu_firefox, BugTaskStatus.INCOMPLETE, no_priv)
    >>> ubuntu_firefox_task.target.displayname
    u'mozilla-firefox in Ubuntu'
    >>> ubuntu_firefox_task.status.name
    'INCOMPLETE'

If a distro series is given, but the bug is only targeted to the
distribution and not to the distro series, the distribution task is
edited.

    >>> ubuntu_warty = ubuntu.getSeries('warty')
    >>> warty_firefox = ubuntu_warty.getSourcePackage('mozilla-firefox')
    >>> ubuntu_firefox_task = bug.setStatus(
    ...     warty_firefox, BugTaskStatus.CONFIRMED, no_priv)
    >>> ubuntu_firefox_task.target.displayname
    u'mozilla-firefox in Ubuntu'
    >>> ubuntu_firefox_task.status.name
    'CONFIRMED'

    >>> ubuntu_hoary = ubuntu.getSeries('hoary')
    >>> hoary_firefox = ubuntu_hoary.getSourcePackage('mozilla-firefox')
    >>> ubuntu_firefox_task = bug.setStatus(
    ...     hoary_firefox, BugTaskStatus.NEW, no_priv)
    >>> ubuntu_firefox_task.target.displayname
    u'mozilla-firefox in Ubuntu'
    >>> ubuntu_firefox_task.status.name
    'NEW'

However, if the bug is targeted to the current series, passing a
non-current series won't modify any bugtask, unless the bug is already
targeted to the non-current series of course.

    >>> ubuntu.currentseries.name
    u'hoary'

    # Need to be privileged user to target the bug to a series.
    >>> login('foo.bar@canonical.com')
    >>> with lp_dbuser():
    ...     bug = getUtility(IBugSet).get(bug_id)
    ...     ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
    ...     ubuntu_hoary = ubuntu.getSeries('hoary')
    ...     nomination = bug.addNomination(
    ...         getUtility(ILaunchBag).user, ubuntu_hoary)
    ...     nomination.approve(getUtility(ILaunchBag).user)
    >>> login('no-priv@canonical.com')

    >>> bug = getUtility(IBugSet).get(bug_id)
    >>> no_priv = getUtility(IPersonSet).getByName('no-priv')
    >>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
    >>> ubuntu_warty = ubuntu.getSeries('warty')
    >>> warty_firefox = ubuntu_warty.getSourcePackage('mozilla-firefox')
    >>> bug.setStatus(warty_firefox, BugTaskStatus.INCOMPLETE, no_priv) is None
    True

    >>> login('foo.bar@canonical.com')
    >>> with lp_dbuser():
    ...     bug = getUtility(IBugSet).get(bug_id)
    ...     ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
    ...     ubuntu_warty = ubuntu.getSeries('warty')
    ...     nomination = bug.addNomination(
    ...         getUtility(ILaunchBag).user, ubuntu_warty)
    ...     nomination.approve(getUtility(ILaunchBag).user)
    >>> login('no-priv@canonical.com')

    >>> bug = getUtility(IBugSet).get(bug_id)
    >>> no_priv = getUtility(IPersonSet).getByName('no-priv')
    >>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
    >>> ubuntu_warty = ubuntu.getSeries('warty')
    >>> warty_firefox = ubuntu_warty.getSourcePackage('mozilla-firefox')
    >>> ubuntu_firefox_task = bug.setStatus(
    ...     warty_firefox, BugTaskStatus.INCOMPLETE, no_priv)
    >>> ubuntu_firefox_task.target.displayname
    u'mozilla-firefox in Ubuntu Warty'
    >>> ubuntu_firefox_task.status.name
    'INCOMPLETE'