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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
= PackageUpload View Classes and Pages =
The QueueItemsView (browser/queue.py) is extended by the default view
for IDistroSeries context (IDistroSeriesView)
Let's instantiate the view for +queue for anonymous access:
>>> from zope.component import queryMultiAdapter
>>> from lp.services.librarian.model import LibraryFileAlias
>>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
>>> from lp.registry.interfaces.distribution import IDistributionSet
>>> fake_chroot = LibraryFileAlias.get(1)
>>> ubuntu = getUtility(IDistributionSet)['ubuntu']
>>> breezy_autotest = ubuntu['breezy-autotest']
>>> breezy_autotest_i386 = breezy_autotest['i386']
>>> unused = breezy_autotest_i386.addOrUpdateChroot(fake_chroot)
>>> request = LaunchpadTestRequest()
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
View parameters need to be set properly before start:
>>> queue_view.setupQueueList()
After setup we have a 'batched' list:
>>> from canonical.launchpad.webapp.interfaces import IBatchNavigator
>>> from canonical.launchpad.webapp.testing import verifyObject
>>> verifyObject(IBatchNavigator, queue_view.batchnav)
True
>>> len(queue_view.batchnav.currentBatch())
6
The local state (PackageUploadStatus, dbschema)
>>> queue_view.state.name
'NEW'
A list of available actions in this queue:
>>> queue_view.availableActions()
[]
Let's instantiate the view for a specific queue:
>>> from lp.soyuz.enums import PackageUploadStatus
>>> request = LaunchpadTestRequest(
... form={'queue_state': PackageUploadStatus.DONE.value})
>>> warty = ubuntu['warty']
>>> queue_view = queryMultiAdapter((warty, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.state.name
'DONE'
>>> len(queue_view.batchnav.currentBatch())
1
Unexpected values for queue_state results in a proper error, anything
that can't be can't fit as an integer is automatically assume as the
default value (NEW queue).
>>> request = LaunchpadTestRequest(
... form={'queue_state': 'foo'})
>>> warty = ubuntu['warty']
>>> queue_view = queryMultiAdapter((warty, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.state.name
'NEW'
>>> len(queue_view.batchnav.currentBatch())
0
If a invalid integer is posted it raises.
>>> request = LaunchpadTestRequest(
... form={'queue_state': '10'})
>>> warty = ubuntu['warty']
>>> queue_view = queryMultiAdapter((warty, request), name="+queue")
>>> queue_view.setupQueueList()
Traceback (most recent call last):
...
UnexpectedFormData: No suitable status found for value "10"
Anonymous users also have access to all queues, including UNAPPROVED
but they are not allowed to perform any action.
>>> request = LaunchpadTestRequest(
... form={'queue_state': PackageUploadStatus.UNAPPROVED.value})
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.state.name
'UNAPPROVED'
>>> len(queue_view.batchnav.currentBatch())
5
>>> queue_view.availableActions()
[]
Now, let's instantiate the view for +queue as a privileged user:
>>> login('foo.bar@canonical.com')
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.availableActions()
['Accept', 'Reject']
Attempt to view and act on UNAPPROVED queue works for administrators.
>>> request = LaunchpadTestRequest(
... form={'queue_state': PackageUploadStatus.UNAPPROVED.value})
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.state.name
'UNAPPROVED'
>>> queue_view.availableActions()
['Accept', 'Reject']
Action on presented queue are controlled and performed by the
'performAction' method, which return a HTML-formatted report text
about the actions performed.
It accepts the 'Accept'/'Reject' and 'QUEUE_ID' arguments via POST.
Accepting an item from NEW queue.
>>> from lp.soyuz.interfaces.queue import IPackageUploadSet
>>> getUtility(IPackageUploadSet).get(1).status.name
'NEW'
>>> getUtility(IPackageUploadSet).get(3).status.name
'NEW'
>>> request = LaunchpadTestRequest(
... form={'queue_state': PackageUploadStatus.NEW.value,
... 'Accept': 'Accept',
... 'QUEUE_ID': ['1', '3']})
>>> request.method = 'POST'
Add fake librarian files so that email notifications work:
>>> from lp.archiveuploader.tests import (
... insertFakeChangesFileForAllPackageUploads)
>>> insertFakeChangesFileForAllPackageUploads()
Anonymous attempts to accept queue items are ignored and an error
message is presented.
>>> login(ANONYMOUS)
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.performQueueAction()
>>> print queue_view.error
You do not have permission to act on queue items.
>>> getUtility(IPackageUploadSet).get(1).status.name
'NEW'
>>> getUtility(IPackageUploadSet).get(3).status.name
'NEW'
Privileged user can accept queue items.
>>> login('foo.bar@canonical.com')
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.performQueueAction()
>>> getUtility(IPackageUploadSet).get(1).status.name
'ACCEPTED'
>>> getUtility(IPackageUploadSet).get(3).status.name
'DONE'
Rejection an item from NEW queue:
>>> target = getUtility(IPackageUploadSet).get(2)
>>> target.status.name
'NEW'
>>> request = LaunchpadTestRequest(
... form={'queue_state': PackageUploadStatus.NEW.value,
... 'Reject': 'Reject',
... 'QUEUE_ID': '2'})
>>> request.method = 'POST'
Anonymous attempts to reject queue items are ignored and an error
message is presented.
>>> login(ANONYMOUS)
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.performQueueAction()
>>> print queue_view.error
You do not have permission to act on queue items.
>>> target.status.name
'NEW'
Privileged user can reject queue items.
>>> login('foo.bar@canonical.com')
>>> queue_view = queryMultiAdapter(
... (breezy_autotest, request), name="+queue")
>>> queue_view.setupQueueList()
>>> queue_view.performQueueAction()
>>> target.status.name
'REJECTED'
== Calculation of "new" binaries ==
The queue page will show the user which binaries in a build upload are
new or not. Since multiple binary package releases can appear in one
build, it's possible that a package that is not already published
can be uploaded alongside incremental versions of existing packages.
In that case, the whole upload is considered new and appears in the
"new" queue.
We can demonstrate this situation by creating a binary publication
for a package "foo" and uploading a new build that has "foo" and
"foo-dev" binaries in it.
>>> from lp.soyuz.tests.test_publishing import (
... SoyuzTestPublisher)
>>> from lp.soyuz.enums import (
... PackagePublishingStatus)
>>> from lp.services.librarian.interfaces import ILibraryFileAliasSet
>>> stp = SoyuzTestPublisher()
>>> hoary = ubuntu['hoary']
>>> stp.prepareBreezyAutotest()
>>> fake_chroot = getUtility(ILibraryFileAliasSet)[1]
>>> trash = hoary['i386'].addOrUpdateChroot(fake_chroot)
>>> foo_source = stp.getPubSource(
... sourcename="foo", distroseries=hoary, version="1.0-1",
... status=PackagePublishingStatus.PUBLISHED)
>>> foo_bin = stp.getPubBinaries(
... binaryname="foo", status=PackagePublishingStatus.PUBLISHED,
... distroseries=hoary, pub_source=foo_source)
Now that "foo" is published in Hoary, we can upload a new build.
# First we'll need to create a source publication for the foo-1.0-2,
# though, as our upload will only include binaries.
>>> foo_source_1_0_2 = stp.getPubSource(
... sourcename="foo", distroseries=hoary, version="1.0-2",
... status=PackagePublishingStatus.PUBLISHED)
>>> from lp.archiveuploader.uploadpolicy import ArchiveUploadType
>>> from lp.archiveuploader.tests import datadir, getPolicy
>>> from lp.archiveuploader.nascentupload import NascentUpload
>>> from lp.soyuz.interfaces.component import IComponentSet
>>> from lp.soyuz.model.component import ComponentSelection
>>> from lp.testing.gpgkeys import import_public_test_keys
>>> import_public_test_keys()
>>> universe = getUtility(IComponentSet)['universe']
>>> trash = ComponentSelection(distroseries=hoary, component=universe)
>>> sync_policy = getPolicy(name='sync', distro='ubuntu',
... distroseries='hoary')
>>> sync_policy.accepted_type = ArchiveUploadType.BINARY_ONLY
>>> from lp.services.log.logger import DevNullLogger
>>> foo_upload = NascentUpload.from_changesfile_path(
... datadir('suite/foo_1.0-2_multi_binary/foo_1.0-2_i386.changes'),
... sync_policy, DevNullLogger())
>>> foo_upload.process()
>>> foo_upload.do_accept()
True
Now we can examine the view, which provides an is_new method:
>>> queue_view = queryMultiAdapter(
... (hoary, request), name="+queue")
>>> queue_view.setupQueueList()
The template calls decoratedQueueBatch() to retrieve the current batch
of uploads to display; this action also calculates data that the
is_new() method requires to work.
>>> discard = queue_view.decoratedQueueBatch()
>>> binary_packages = foo_upload.queue_root.builds[0].build.binarypackages
>>> for binarypackage in binary_packages:
... print binarypackage.name, queue_view.is_new(binarypackage)
foo False
foo-dev True
We created librarian files that need cleaning up before leaving the test.
>>> from canonical.testing.layers import LibrarianLayer
>>> LibrarianLayer.librarian_fixture.clear()
|