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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
ProjectGroups
=============
A ProjectGroup is a group of Products, making it possible to for
example see all bugs in the ProjectGroup's Product, or make them share a
common external bug tracker.
# Some basic imports
>>> from canonical.launchpad.webapp.testing import verifyObject
>>> from lp.registry.interfaces.projectgroup import (
... IProjectGroup,
... IProjectGroupSet,
... )
>>> projectset = getUtility(IProjectGroupSet)
# Some setup
>>> import transaction
>>> from lp.app.enums import ServiceUsage
>>> from lp.registry.interfaces.product import IProductSet
>>> from zope.component import getUtility
>>> login('admin@canonical.com')
>>> evolution = getUtility(IProductSet).getByName('evolution')
>>> evolution.translations_usage = ServiceUsage.LAUNCHPAD
>>> logout()
>>> login('test@canonical.com')
>>> transaction.commit()
Creating new projects
---------------------
When creating a new project there are a bunch of things we need to provide.
While some of them (homepageurl, icon, logo and mugshot) are optional, others
(name, displayname, title, summary, description and owner) are required).
>>> from lp.registry.interfaces.person import IPersonSet
>>> no_priv = getUtility(IPersonSet).getByName('no-priv')
>>> test_project = projectset.new(
... name='project-test', displayname='Test Project',
... title='Just a test project', homepageurl=None,
... summary='Mandatory summary', description='blah',
... owner=no_priv)
>>> test_project.name
u'project-test'
Looking up existing projects
----------------------------
To fetch a project we use IProjectGroupSet.getByName() or
IProjectGroupSet.__getitem__. The former will, by default, return active and
inactive projects, while the latter returns only active ones. Both can be
used to look up projects by their aliases, though.
>>> gnome = projectset['gnome']
>>> gnome.name
u'gnome'
>>> projectset.getByName('gnome').name
u'gnome'
# Need to login as an LP admin to set a project's aliases.
>>> login('foo.bar@canonical.com')
>>> gnome.setAliases(['dwarf'])
>>> gnome.aliases
[u'dwarf']
>>> login(ANONYMOUS)
>>> projectset['dwarf'].name
u'gnome'
>>> projectset.getByName('dwarf').name
u'gnome'
Make sure that a project provides the IProjectGroup interface.
>>> verifyObject(IProjectGroup, gnome)
True
>>> IProjectGroup.providedBy(gnome)
True
If there is no project with the specified name, a NotFoundError will be
raised.
>>> projectset['non-existant']
Traceback (most recent call last):
...
NotFoundError:...
The same will happen if we set a product to be inactive. This is a good
way of hiding bogus projects, without actually deleting them from the
db, since the __getitem__ method of IProjectGroupSet is used to traverse to
the project.
>>> from canonical.database.sqlbase import flush_database_updates
>>> login("foo.bar@canonical.com")
>>> gnome.active = False
>>> flush_database_updates()
>>> gnome = getUtility(IProjectGroupSet)['gnome']
Traceback (most recent call last):
...
NotFoundError:...
The inactive project will still be accessible using
IProjectGroupSet.getByName(), though.
>>> gnome = getUtility(IProjectGroupSet).getByName('gnome')
>>> gnome.name
u'gnome'
>>> gnome.active
False
getByName() also accepts an argument to ignore inactive projects.
>>> projectgroups = getUtility(IProjectGroupSet)
>>> print projectgroups.getByName('gnome', ignore_inactive=True)
None
Products which are part of a project
------------------------------------
The products which are part of a given project are given by a project's
.products property. Note that only active products are included and they're
ordered by their names.
>>> [product.displayname for product in gnome.products]
[u'Evolution', u'GNOME Terminal', u'Gnome Applets', u'NetApplet',
u'gnomebaker']
>>> netapplet = gnome.getProduct('netapplet')
# Unlink the source packages so the project can be deactivated.
>>> from lp.testing import unlink_source_packages
>>> unlink_source_packages(netapplet)
>>> netapplet.active = False
>>> flush_database_updates()
>>> [product.displayname for product in gnome.products]
[u'Evolution', u'GNOME Terminal', u'Gnome Applets', u'gnomebaker']
# Re-activate netapplet so that we don't interfere in other tests below.
>>> netapplet.active = True
>>> flush_database_updates()
Specification Listings
----------------------
We should be able to generate filtered lists of specs on a project.
>>> mozilla = getUtility(IProjectGroupSet).getByName('mozilla')
>>> from lp.blueprints.enums import SpecificationFilter
First, there should be only one informational spec for mozilla:
>>> filter = [SpecificationFilter.INFORMATIONAL]
>>> for spec in mozilla.specifications(filter=filter):
... print spec.name
extension-manager-upgrades
There are no completed specs for mozilla:
>>> filter = [SpecificationFilter.COMPLETE]
>>> for spec in mozilla.specifications(filter=filter):
... print spec.name
And there are five incomplete specs:
>>> filter = [SpecificationFilter.INCOMPLETE]
>>> mozilla.specifications(filter=filter).count()
5
We can filter for specifications that contain specific text:
>>> for spec in mozilla.specifications(filter=['install']):
... print spec.name
extension-manager-upgrades
Inactive products are excluded from the listings.
>>> filter = [SpecificationFilter.INCOMPLETE]
>>> mozilla.specifications(filter=filter).count()
5
>>> from lp.registry.interfaces.product import IProductSet
>>> firefox = getUtility(IProductSet).getByName('firefox')
# Unlink the source packages so the project can be deactivated.
>>> from lp.testing import unlink_source_packages
>>> unlink_source_packages(firefox)
>>> firefox.active = False
>>> flush_database_updates()
>>> filter = [SpecificationFilter.INCOMPLETE]
>>> mozilla.specifications(filter=filter).count()
0
Reset firefox so we don't mess up later tests.
>>> firefox.active = True
>>> flush_database_updates()
We can get all the specifications via the all_specifications property,
and all valid specifications via the valid_specifications property:
>>> for spec in mozilla.all_specifications:
... print spec.name
svg-support
canvas
extension-manager-upgrades
mergewin
e4x
>>> for spec in mozilla.valid_specifications:
... print spec.name
svg-support
canvas
extension-manager-upgrades
mergewin
e4x
Specification Listings for a ProjectGroupSeries
-----------------------------------------------
An IProjectGroupSeries object can be retrieved by IProjectGroup.getSeries.
>>> from lp.registry.interfaces.projectgroup import IProjectGroupSeries
>>> mozilla_series_1_0 = mozilla.getSeries('1.0')
>>> mozilla_series_1_0
<lp.registry.model.projectgroup.ProjectGroupSeries object at...
>>> IProjectGroupSeries.providedBy(mozilla_series_1_0)
True
If no series with the given name exists, IProjectGroup.getSeries returns None.
>>> print mozilla.getSeries('nonsense')
None
IProjectGroupSeries.all_specifications lists all specifications
assigned to a series. Currently, no specifications are assigned to the
Mozilla series 1.0.
>>> specs = mozilla_series_1_0.all_specifications
>>> specs.count()
0
If a specification is assigned to series 1.0, it appears in
mozilla_1_0_series.all_specifications.
>>> filter = [SpecificationFilter.INFORMATIONAL]
>>> extension_manager_upgrades = mozilla.specifications(filter=filter)[0]
>>> series_1_0 = firefox.getSeries('1.0')
>>> extension_manager_upgrades.proposeGoal(series_1_0, no_priv)
>>> for spec in mozilla_series_1_0.all_specifications:
... print spec.name
extension-manager-upgrades
This specification is not listed for other series.
>>> mozilla_trunk = mozilla.getSeries('trunk')
>>> print mozilla_trunk.all_specifications.count()
0
Filtered lists of project series related specifications are generated
the same way as for project related specifications.
>>> for spec in mozilla_series_1_0.specifications(filter=filter):
... print spec.name
extension-manager-upgrades
If all existing specifications are assigned to the 1.0 series,...
>>> for spec in mozilla.all_specifications:
... spec.proposeGoal(series_1_0, no_priv)
we have the save five incomplete specs in the series 1.0 as we have for the
project itself.
>>> filter = [SpecificationFilter.INCOMPLETE]
>>> for spec in mozilla_series_1_0.specifications(filter=filter):
... print spec.name
svg-support
canvas
extension-manager-upgrades
mergewin
e4x
Searching for text is also possible.
>>> for spec in mozilla_series_1_0.specifications(filter=['install']):
... print spec.name
extension-manager-upgrades
Inactive products are excluded from the series listings.
>>> filter = [SpecificationFilter.INCOMPLETE]
>>> specs = mozilla_series_1_0.specifications(filter=filter)
>>> print specs.count()
5
>>> firefox = getUtility(IProductSet).getByName('firefox')
>>> firefox.active = False
>>> filter = [SpecificationFilter.INCOMPLETE]
>>> mozilla_series_1_0.specifications(filter=filter).count()
0
Reset firefox so we don't mess up later tests.
>>> firefox.active = True
We can get all the specifications via the all_specifications property,
and all valid specifications via the valid_specifications property:
>>> for spec in mozilla_series_1_0.all_specifications:
... print spec.name
svg-support
canvas
extension-manager-upgrades
mergewin
e4x
>>> for spec in mozilla_series_1_0.valid_specifications:
... print spec.name
svg-support
canvas
extension-manager-upgrades
mergewin
e4x
Translatables
-------------
A project would have IProduct objects that have resources to translate. This
method return us the ones that are translatable and officially using Rosetta
to handle translations.
# Revert any change done until now.
>>> import transaction
>>> transaction.abort()
A project group with no translatable products is shown by
'has_translatables' being false.
>>> product = factory.makeProduct()
>>> project_group = factory.makeProject()
>>> product.project = project_group
>>> project_group.has_translatable()
False
GNOME Project is a good example that has translations.
It has one translatable product.
>>> gnome = getUtility(IProjectGroupSet)['gnome']
>>> gnome.has_translatable()
True
>>> translatables = gnome.translatables()
>>> translatables.count()
1
And that translatable product is 'Evolution'.
>>> evolution = translatables[0]
>>> print evolution.title
The Evolution Groupware Application
With its 'trunk' series translatable.
>>> evo_series = evolution.translatable_series
>>> len(evo_series)
1
>>> evo_trunk = evo_series[0]
>>> print evo_trunk.name
trunk
That is using Rosetta officially.
>>> print evolution.translations_usage.name
LAUNCHPAD
GNOME project has also another product, netapplet.
>>> netapplet = gnome.getProduct('netapplet')
>>> print netapplet.title
Network Applet
But it was not returned from 'translatables' method because it's not using
Rosetta officially.
>>> print netapplet.translations_usage.name
UNKNOWN
And thus, it doesn't have any translatable series.
>>> len(netapplet.translatable_series)
0
Even if it has resources to translate.
>>> sum([len(list(series.getTranslationTemplates()))
... for series in netapplet.series])
1
Milestones
----------
A project can have virtual milestones. If any of its products has milestones,
these milestones are also associated with the project.
ProjectGroup.milestones is a list of all active milestones associated with
a project.
>>> from lp.registry.tests.test_project_milestone import (
... ProjectMilestoneTest)
>>> from lp.registry.interfaces.projectgroup import IProjectGroupSet
>>> login('foo.bar@canonical.com')
>>> test_helper = ProjectMilestoneTest(helper_only=True)
>>> test_helper.setUpProjectMilestoneTests()
>>> gnome = getUtility(IProjectGroupSet)['gnome']
>>> milestones = gnome.milestones
>>> for milestone in milestones:
... print milestone.name, 'active:', milestone.active
1.2 active: True
1.1. active: True
1.1 active: True
ProjectGroup.all_milestones is a list of all milestones associated with a
project.
>>> milestones = gnome.all_milestones
>>> for milestone in milestones:
... print milestone.name, 'active:', milestone.active
2.1.6 active: False
1.0 active: False
1.3 active: False
1.2 active: True
1.1. active: True
1.1 active: True
ProjectGroup.getMilestone(name) returns the project milestone with the name
`name' or None, if no milestone with this name exists.
>>> milestone = gnome.getMilestone('1.1')
>>> print milestone.name
1.1
>>> milestone = gnome.getMilestone('invalid')
>>> print milestone
None
For details see doc/milestone.txt and ftests/test_project_milestone.py.
|