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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
This file lists all the karma events that Malone produces. First let's
import some stuff and define a function to help us make the
documentation cleaner:
>>> from lp.bugs.interfaces.bug import IBugSet
>>> from lp.registry.interfaces.distribution import IDistributionSet
>>> from lp.registry.interfaces.karma import IKarmaActionSet
>>> from lp.registry.interfaces.person import IPersonSet
>>> foo_bar = getUtility(IPersonSet).getByEmail('foo.bar@canonical.com')
Setup an event listener to help ensure karma is assigned when it should.
>>> from zope.event import notify
>>> from lp.testing.karma import KarmaAssignedEventListener
>>> karma_helper = KarmaAssignedEventListener()
>>> karma_helper.register_listener()
Foo Bar is the one that will get all the karma:
>>> login('foo.bar@canonical.com')
Karma Actions
-------------
Create a bug:
>>> from lazr.lifecycle.event import (
... ObjectCreatedEvent, ObjectModifiedEvent)
>>> from lp.bugs.interfaces.bug import CreateBugParams
>>> debian = getUtility(IDistributionSet).getByName('debian')
>>> params = CreateBugParams(
... comment=u"Give me some karma!", title=u"New Bug", owner=foo_bar)
>>> bug = debian.createBug(params)
Karma added: action=bugcreated, distribution=debian
Change the title of a bug:
>>> from lazr.lifecycle.snapshot import Snapshot
>>> from lp.bugs.interfaces.bug import IBug
>>> old_bug = Snapshot(bug, providing=IBug)
>>> bug.title = "Better Title"
>>> notify(ObjectModifiedEvent(bug, old_bug, ['title']))
Karma added: action=bugtitlechanged, distribution=debian
Change the description of a bug:
>>> old_bug = Snapshot(bug, providing=IBug)
>>> bug.description = "Description of bug"
>>> notify(ObjectModifiedEvent(bug, old_bug, ['description']))
Karma added: action=bugdescriptionchanged, distribution=debian
Add a CVE reference to a bug:
>>> from lp.bugs.interfaces.cve import CveStatus, ICveSet
>>> from lp.bugs.model.cve import BugCve
>>> cve = getUtility(ICveSet).new('2003-1234', description="Blah blah",
... status=CveStatus.CANDIDATE)
>>> bugcve = BugCve(cve=cve, bug=bug)
>>> notify(ObjectCreatedEvent(bugcve))
Karma added: action=bugcverefadded, distribution=debian
Add watch for external bug to the bug:
>>> from lp.bugs.interfaces.bugtracker import IBugTrackerSet
>>> from lp.bugs.model.bugwatch import BugWatch
>>> debbugs = getUtility(IBugTrackerSet)['debbugs']
>>> bugwatch = BugWatch(
... bug=bug,bugtracker=debbugs, remotebug=u'42', owner=foo_bar)
>>> notify(ObjectCreatedEvent(bugwatch))
Karma added: action=bugwatchadded, distribution=debian
Mark a bug task as fixed:
>>> from lp.bugs.interfaces.bugtask import (
... BugTaskStatus,
... IBugTask,
... )
>>> bugtask = bug.bugtasks[0]
>>> old_bugtask = Snapshot(bugtask, providing=IBugTask)
>>> bugtask.transitionToStatus(
... BugTaskStatus.FIXRELEASED, getUtility(ILaunchBag).user)
>>> notify(ObjectModifiedEvent(bugtask, old_bugtask, ['status']))
Karma added: action=bugfixed, distribution=debian
Mark a bug task as fixed when it is assigned awards the karma to the assignee:
>>> ufo_product = factory.makeProduct(name='ufo')
>>> assignee = factory.makePerson(name='assignee')
>>> assigned_bugtask = factory.makeBugTask(bug=bug, target=ufo_product)
>>> assigned_bugtask.transitionToAssignee(assignee)
>>> old_bugtask = Snapshot(assigned_bugtask, providing=IBugTask)
>>> assigned_bugtask.transitionToStatus(
... BugTaskStatus.FIXRELEASED, getUtility(ILaunchBag).user)
>>> notify(ObjectModifiedEvent(assigned_bugtask, old_bugtask, ['status']))
Karma added: action=bugfixed, product=ufo
>>> for karma in assignee.latestKarma():
... print karma.action.name
bugfixed
Reject a bug task:
>>> old_bugtask = Snapshot(bugtask, providing=IBugTask)
>>> bugtask.transitionToStatus(
... BugTaskStatus.INVALID, bugtask.target.owner)
>>> notify(ObjectModifiedEvent(bugtask, old_bugtask, ['status']))
Karma added: action=bugrejected, distribution=debian
User accept a bug task:
>>> old_bugtask = Snapshot(bugtask, providing=IBugTask)
>>> bugtask.transitionToStatus(
... BugTaskStatus.CONFIRMED, getUtility(ILaunchBag).user)
>>> notify(ObjectModifiedEvent(bugtask, old_bugtask, ['status']))
Karma added: action=bugaccepted, distribution=debian
Driver accept a bug task:
>>> login_person(bugtask.target.owner)
>>> old_bugtask = Snapshot(bugtask, providing=IBugTask)
>>> bugtask.transitionToStatus(
... BugTaskStatus.TRIAGED, getUtility(ILaunchBag).user)
>>> notify(ObjectModifiedEvent(bugtask, old_bugtask, ['status']))
Karma added: action=bugaccepted, distribution=debian
>>> login('admin@canonical.com')
Change a bug task's importance:
>>> from lp.bugs.interfaces.bugtask import BugTaskImportance
>>> bugtask.transitionToImportance(
... BugTaskImportance.HIGH, getUtility(ILaunchBag).user)
>>> for importance in BugTaskImportance.items:
... old_bugtask = Snapshot(bugtask, providing=IBugTask)
... bugtask.transitionToImportance(
... importance, getUtility(ILaunchBag).user)
... print importance.name
... notify(ObjectModifiedEvent(bugtask, old_bugtask, ['importance']))
UNKNOWN
Karma added: action=bugtaskimportancechanged, distribution=debian
CRITICAL
Karma added: action=bugtaskimportancechanged, distribution=debian
HIGH
Karma added: action=bugtaskimportancechanged, distribution=debian
MEDIUM
Karma added: action=bugtaskimportancechanged, distribution=debian
LOW
Karma added: action=bugtaskimportancechanged, distribution=debian
WISHLIST
Karma added: action=bugtaskimportancechanged, distribution=debian
UNDECIDED
Karma added: action=bugtaskimportancechanged, distribution=debian
Create a new bug task on a product:
>>> from lp.bugs.interfaces.bugtask import IBugTaskSet
>>> from lp.registry.interfaces.product import IProductSet
>>> evolution = getUtility(IProductSet)['evolution']
>>> evolution_task = getUtility(IBugTaskSet).createTask(
... bug, foo_bar, evolution)
>>> notify(ObjectCreatedEvent(evolution_task))
Karma added: action=bugtaskcreated, product=evolution
Create a new bug task on a product series:
>>> evolution_trunk = evolution.getSeries('trunk')
>>> evolution_trunk_task = getUtility(IBugTaskSet).createTask(
... bug, foo_bar, evolution_trunk)
>>> notify(ObjectCreatedEvent(evolution_trunk_task))
Karma added: action=bugtaskcreated, product=evolution
Create a new bug task on a distroseries:
>>> debian_woody = debian.getSeries("woody")
>>> debian_woody_task = getUtility(IBugTaskSet).createTask(
... bug, foo_bar, debian_woody)
>>> notify(ObjectCreatedEvent(debian_woody_task))
Karma added: action=bugtaskcreated, distribution=debian
Accept a distro series task.
>>> debian_woody_task.transitionToStatus(
... BugTaskStatus.NEW, getUtility(ILaunchBag).user)
>>> old_bugtask = Snapshot(
... debian_woody_task, providing=IBugTask)
>>> debian_woody_task.transitionToStatus(
... BugTaskStatus.CONFIRMED, getUtility(ILaunchBag).user)
>>> notify(ObjectModifiedEvent(debian_woody_task, old_bugtask, ['status']))
Karma added: action=bugaccepted, distribution=debian
Accept a productseries task.
>>> evolution_trunk_task.transitionToStatus(
... BugTaskStatus.NEW, getUtility(ILaunchBag).user)
>>> old_bugtask = Snapshot(
... evolution_trunk_task, providing=IBugTask)
>>> evolution_trunk_task.transitionToStatus(
... BugTaskStatus.CONFIRMED, getUtility(ILaunchBag).user)
>>> notify(ObjectModifiedEvent(
... evolution_trunk_task, old_bugtask, ['status']))
Karma added: action=bugaccepted, product=evolution
Mark a bug as a duplicate:
>>> bug_one = getUtility(IBugSet).get(1)
>>> old_bug = Snapshot(bug, providing=IBug)
>>> bug.markAsDuplicate(bug_one)
(Notice how changing a bug with multiple bugtasks will assign karma to you
once for each bugtask. This is so because we consider changes in a bug to
be actual contributions to all bugtasks of that bug)
>>> notify(ObjectModifiedEvent(bug, old_bug, ['duplicateof']))
Karma added: action=bugmarkedasduplicate, product=evolution
Karma added: action=bugmarkedasduplicate, product=evolution
Karma added: action=bugmarkedasduplicate, product=ufo
Karma added: action=bugmarkedasduplicate, distribution=debian
Karma added: action=bugmarkedasduplicate, distribution=debian
Adding a comment generates a karma event, but gives no points:
>>> from lp.bugs.interfaces.bugmessage import IBugMessageSet
>>> comment = getUtility(IBugMessageSet).createMessage(
... subject="foo", bug=bug, owner=foo_bar, content="bar")
>>> notify(ObjectCreatedEvent(comment))
Karma added: action=bugcommentadded, product=evolution
Karma added: action=bugcommentadded, product=evolution
Karma added: action=bugcommentadded, product=ufo
Karma added: action=bugcommentadded, distribution=debian
Karma added: action=bugcommentadded, distribution=debian
Now, let's check that we've covered all of Launchpad's bug-related karma
actions, except for updating the obsolete "summary", "priority", and "Web
links":
>>> from lp.registry.model.karma import KarmaCategory
>>> bugs_category = KarmaCategory.byName('bugs')
>>> bugs_karma_actions = bugs_category.karmaactions
>>> summary_change = getUtility(
... IKarmaActionSet).getByName('bugsummarychanged')
>>> karma_helper.added_karma_actions.add(summary_change)
>>> priority_change = getUtility(
... IKarmaActionSet).getByName('bugtaskprioritychanged')
>>> karma_helper.added_karma_actions.add(priority_change)
>>> link_change = getUtility(
... IKarmaActionSet).getByName('bugextrefadded')
>>> karma_helper.added_karma_actions.add(link_change)
>>> karma_helper.added_karma_actions == set(bugs_karma_actions)
True
Unregister the event listener to make sure we won't interfere in other tests.
>>> karma_helper.unregister_listener()
XXX Matthew Paul Thomas 2006-03-22: On 2007-03-23, a year after bug summaries
were removed, all the karma gained from updating bug summaries will have
expired. Then the 'bugsummarychanged' row should be removed from the database,
and summary_change can be removed from this test. The same applies to the
'bugtaskprioritychanged' row after about 2007-05-15, and the 'bugextrefadded'
row after about 2008-09-25.
|