Merge lp:~james-w/launchpad/no-more-sampledata-1 into lp:launchpad

Proposed by James Westby
Status: Merged
Approved by: Jonathan Lange
Approved revision: no longer in the source branch.
Merged at revision: 11295
Proposed branch: lp:~james-w/launchpad/no-more-sampledata-1
Merge into: lp:launchpad
Prerequisite: lp:~james-w/launchpad/no-more-sampledata-0
Diff against target: 1552 lines (+599/-557)
11 files modified
lib/lp/archiveuploader/tests/nascentupload-packageset.txt (+2/-2)
lib/lp/archiveuploader/tests/nascentupload.txt (+2/-2)
lib/lp/archiveuploader/tests/test_permission.py (+0/-242)
lib/lp/buildmaster/interfaces/packagebuild.py (+2/-2)
lib/lp/soyuz/model/archive.py (+19/-17)
lib/lp/soyuz/model/buildpackagejob.py (+2/-3)
lib/lp/soyuz/stories/webservice/xx-archive.txt (+2/-2)
lib/lp/soyuz/tests/test_archive.py (+505/-283)
lib/lp/soyuz/tests/test_buildpackagejob.py (+20/-1)
lib/lp/testing/factory.py (+11/-3)
lib/lp/testing/tests/test_factory.py (+34/-0)
To merge this branch: bzr merge lp:~james-w/launchpad/no-more-sampledata-1
Reviewer Review Type Date Requested Status
Jonathan Lange (community) Approve
Review via email: mp+31493@code.launchpad.net

Description of the change

Hi,

Here's some more cleanup of test_archive to remove reliance on
sampledata (or at least SoyuzTestPublisher.setup_breezy_autotest()).

There are a couple of fixes here too, one for bug 612351, and one
where the build scoring code assumed it new the complete list of
components, but they are stored in the db, not in an enum or similar.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :
Download full text (46.1 KiB)

On Sun, Aug 1, 2010 at 9:55 PM, James Westby <email address hidden> wrote:
> James Westby has proposed merging lp:~james-w/launchpad/no-more-sampledata-1 into lp:launchpad/devel with lp:~james-w/launchpad/no-more-sampledata-0 as a prerequisite.
>
> Requested reviews:
>  Launchpad code reviewers (launchpad-reviewers)
>
>
> Hi,
>
> Here's some more cleanup of test_archive to remove reliance on
> sampledata (or at least SoyuzTestPublisher.setup_breezy_autotest()).
>
> There are a couple of fixes here too, one for bug 612351, and one
> where the build scoring code assumed it new the complete list of
> components, but they are stored in the db, not in an enum or similar.
>

Sweet, thanks.

I've got a few trivial suggestions, and would like to see some tests
for the changes made to the factory. Other than that, looks good.

I look forward to hearing back from you.

jml

> === modified file 'lib/lp/soyuz/model/buildpackagejob.py'
> --- lib/lp/soyuz/model/buildpackagejob.py       2010-06-10 12:18:10 +0000
> +++ lib/lp/soyuz/model/buildpackagejob.py       2010-08-01 20:54:49 +0000
> @@ -115,9 +115,10 @@
>             score += score_pocket
>
>             # Calculates the component-related part of the score.
> -            score_component = score_componentname[
> -                self.build.current_component.name]
> -            score += score_component
> +            if self.build.current_component.name in score_componentname:
> +                score_component = score_componentname[
> +                    self.build.current_component.name]
> +                score += score_component
>

FWIW, this can also be written as:
  score_component =
score_componentname.get(self.build.current_component.name, 0)
  score += score_component

Which I *think* might be a little faster. Whether it's clearer or not
is subjective. Your call as to whether you make the change.

>             # Calculates the build queue time component of the score.
>             right_now = datetime.now(pytz.timezone('UTC'))
>
> === modified file 'lib/lp/soyuz/tests/test_archive.py'
> --- lib/lp/soyuz/tests/test_archive.py  2010-08-01 20:54:47 +0000
> +++ lib/lp/soyuz/tests/test_archive.py  2010-08-01 20:54:49 +0000
> @@ -1,9 +1,11 @@
>  # Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
>  # GNU Affero General Public License version 3 (see the file LICENSE).
>
> +from __future__ import with_statement
> +
>  """Test Archive features."""
>
> -from datetime import date, timedelta
> +from datetime import date
>
>  import transaction
>
> @@ -12,18 +14,21 @@
>  from zope.security.proxy import removeSecurityProxy
>
>  from canonical.database.sqlbase import sqlvalues
> +from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
>  from canonical.launchpad.webapp.interfaces import (
>     IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)
>  from canonical.testing import DatabaseFunctionalLayer, LaunchpadZopelessLayer
>
>  from lp.buildmaster.interfaces.buildbase import BuildStatus
> -from lp.registry.interfaces.distribution import IDistributionSet
> -from lp.registry.interfaces.person import IPersonSet
>  from lp.registry.interfaces.pocket import PackagePubli...

Revision history for this message
Jonathan Lange (jml) wrote :

As per my email comments.

review: Needs Fixing
Revision history for this message
James Westby (james-w) wrote :

Hi,

All suggested changes made.

Thanks,

James

Revision history for this message
Jonathan Lange (jml) wrote :

Perfect. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/tests/nascentupload-packageset.txt'
2--- lib/lp/archiveuploader/tests/nascentupload-packageset.txt 2010-05-11 14:09:44 +0000
3+++ lib/lp/archiveuploader/tests/nascentupload-packageset.txt 2010-08-04 22:02:48 +0000
4@@ -39,8 +39,8 @@
5 >>> bar_failed.is_rejected
6 True
7 >>> print bar_failed.rejection_message
8- The signer of this package is lacking the upload rights for the source
9- package, component or package set in question.
10+ The signer of this package has no upload rights to this distribution's
11+ primary archive. Did you mean to upload to a PPA?
12
13
14 We can grant selective, package set based upload permissions to the user
15
16=== modified file 'lib/lp/archiveuploader/tests/nascentupload.txt'
17--- lib/lp/archiveuploader/tests/nascentupload.txt 2010-07-24 09:12:37 +0000
18+++ lib/lp/archiveuploader/tests/nascentupload.txt 2010-08-04 22:02:48 +0000
19@@ -879,8 +879,8 @@
20 >>> bar_failed.is_rejected
21 True
22 >>> print bar_failed.rejection_message
23- The signer of this package is lacking the upload rights for the source
24- package, component or package set in question.
25+ The signer of this package has no upload rights to this distribution's
26+ primary archive. Did you mean to upload to a PPA?
27
28 Even in a rejected upload using 'insecure' policy, the DSC signing key
29 and the changesfile sigining key are stored in NascentUpload instance
30
31=== removed file 'lib/lp/archiveuploader/tests/test_permission.py'
32--- lib/lp/archiveuploader/tests/test_permission.py 2010-07-18 00:26:33 +0000
33+++ lib/lp/archiveuploader/tests/test_permission.py 1970-01-01 00:00:00 +0000
34@@ -1,242 +0,0 @@
35-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
36-# GNU Affero General Public License version 3 (see the file LICENSE).
37-
38-"""Tests for the permissions for uploading to an archive."""
39-
40-__metaclass__ = type
41-
42-from zope.component import getUtility
43-from zope.security.proxy import removeSecurityProxy
44-
45-from canonical.testing import DatabaseFunctionalLayer
46-
47-from lp.registry.interfaces.series import SeriesStatus
48-from lp.registry.interfaces.pocket import PackagePublishingPocket
49-from lp.soyuz.interfaces.archive import ArchivePurpose
50-from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
51-from lp.testing import TestCaseWithFactory
52-
53-
54-class TestComponents(TestCaseWithFactory):
55-
56- layer = DatabaseFunctionalLayer
57-
58- def test_no_components_for_arbitrary_person(self):
59- # By default, a person cannot upload to any component of an archive.
60- archive = self.factory.makeArchive()
61- person = self.factory.makePerson()
62- self.assertEqual(set(),
63- set(archive.getComponentsForUploader(person)))
64-
65- def test_components_for_person_with_permissions(self):
66- # If a person has been explicitly granted upload permissions to a
67- # particular component, then those components are included in
68- # IArchive.getComponentsForUploader.
69- archive = self.factory.makeArchive()
70- component = self.factory.makeComponent()
71- person = self.factory.makePerson()
72- # Only admins or techboard members can add permissions normally. That
73- # restriction isn't relevant to this test.
74- ap_set = removeSecurityProxy(getUtility(IArchivePermissionSet))
75- ap = ap_set.newComponentUploader(archive, person, component)
76- self.assertEqual(set([ap]),
77- set(archive.getComponentsForUploader(person)))
78-
79-
80-class TestPermission(TestCaseWithFactory):
81-
82- layer = DatabaseFunctionalLayer
83-
84- def setUp(self):
85- TestCaseWithFactory.setUp(self)
86- permission_set = getUtility(IArchivePermissionSet)
87- # Only admins or techboard members can add permissions normally. That
88- # restriction isn't relevant to these tests.
89- self.permission_set = removeSecurityProxy(permission_set)
90-
91- def assertCanUpload(self, person, spn, archive, component,
92- strict_component=True, distroseries=None):
93- """Assert that 'person' can upload 'spn' to 'archive'."""
94- # For now, just check that doesn't raise an exception.
95- if distroseries is None:
96- distroseries = self.factory.makeDistroSeries(
97- distribution=archive.distribution)
98- pocket = PackagePublishingPocket.RELEASE
99- self.assertIs(
100- None,
101- archive.checkUpload(
102- person, distroseries, spn, component, pocket,
103- strict_component))
104-
105- def assertCannotUpload(self, reason, person, spn, archive, component,
106- distroseries=None):
107- """Assert that 'person' cannot upload to the archive.
108-
109- :param reason: The expected reason for not being able to upload. A
110- string.
111- :param person: The person trying to upload.
112- :param spn: The `ISourcePackageName` being uploaded to. None if the
113- package does not yet exist.
114- :param archive: The `IArchive` being uploaded to.
115- :param component: The IComponent to which the package belongs.
116- :param distroseries: The upload's target distro series.
117- """
118- if distroseries is None:
119- distroseries = self.factory.makeDistroSeries()
120- pocket = PackagePublishingPocket.RELEASE
121- exception = archive.checkUpload(
122- person, distroseries, spn, component, pocket)
123- self.assertEqual(reason, str(exception))
124-
125- def test_random_person_cannot_upload_to_ppa(self):
126- # Arbitrary people cannot upload to a PPA.
127- person = self.factory.makePerson()
128- ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
129- spn = self.factory.makeSourcePackageName()
130- self.assertCannotUpload(
131- 'Signer has no upload rights to this PPA.',
132- person, spn, ppa, None)
133-
134- def test_owner_can_upload_to_ppa(self):
135- # If the archive is a PPA, and you own it, then you can upload pretty
136- # much anything to it.
137- team = self.factory.makeTeam()
138- ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA, owner=team)
139- person = self.factory.makePerson()
140- removeSecurityProxy(team).addMember(person, team.teamowner)
141- spn = self.factory.makeSourcePackageName()
142- self.assertCanUpload(person, spn, ppa, None)
143-
144- def test_owner_can_upload_to_ppa_no_sourcepackage(self):
145- # The owner can upload to PPAs even if the source package doesn't
146- # exist yet.
147- team = self.factory.makeTeam()
148- ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA, owner=team)
149- person = self.factory.makePerson()
150- removeSecurityProxy(team).addMember(person, team.teamowner)
151- self.assertCanUpload(person, None, ppa, None)
152-
153- def test_can_upload_to_ppa_for_old_series(self):
154- # You can upload whatever you want to a PPA, regardless of the upload
155- # policy.
156- person = self.factory.makePerson()
157- ppa = self.factory.makeArchive(
158- purpose=ArchivePurpose.PPA, owner=person)
159- spn = self.factory.makeSourcePackageName()
160- distroseries = self.factory.makeDistroSeries(
161- status=SeriesStatus.CURRENT)
162- self.assertCanUpload(
163- person, spn, ppa, None, distroseries=distroseries)
164-
165- def test_arbitrary_person_cannot_upload_to_primary_archive(self):
166- # By default, you can't upload to the primary archive.
167- person = self.factory.makePerson()
168- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
169- spn = self.factory.makeSourcePackageName()
170- self.assertCannotUpload(
171- ("The signer of this package is lacking the upload rights for "
172- "the source package, component or package set in question."),
173- person, spn, archive, None)
174-
175- def test_package_specific_rights(self):
176- # A person can be granted specific rights for uploading a package,
177- # based only on the source package name. If they have these rights,
178- # they can upload to the package.
179- person = self.factory.makePerson()
180- spn = self.factory.makeSourcePackageName()
181- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
182- # We can't use a PPA, because they have a different logic for
183- # permissions. We can't create an arbitrary archive, because there's
184- # only one primary archive per distro.
185- self.permission_set.newPackageUploader(archive, person, spn)
186- self.assertCanUpload(person, spn, archive, None)
187-
188- def test_packageset_specific_rights(self):
189- # A person with rights to upload to the package set can upload the
190- # package set to the archive.
191- person = self.factory.makePerson()
192- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
193- spn = self.factory.makeSourcePackageName()
194- distroseries = self.factory.makeDistroSeries()
195- package_set = self.factory.makePackageset(
196- packages=[spn], distroseries=distroseries)
197- self.permission_set.newPackagesetUploader(
198- archive, person, package_set)
199- self.assertCanUpload(
200- person, spn, archive, None, distroseries=distroseries)
201-
202- def test_packageset_wrong_distroseries(self):
203- # A person with rights to upload to the package set in distro
204- # series K may not upload with these same rights to a different
205- # distro series L.
206- distroseries_K = self.factory.makeDistroRelease()
207- distroseries_L = self.factory.makeDistroRelease()
208- person = self.factory.makePerson()
209- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
210- spn = self.factory.makeSourcePackageName()
211- package_set = self.factory.makePackageset(
212- packages=[spn], distroseries=distroseries_K)
213- self.permission_set.newPackagesetUploader(
214- archive, person, package_set)
215- self.assertCanUpload(
216- person, spn, archive, None, distroseries=distroseries_K)
217- self.assertCannotUpload(
218- ("The signer of this package is lacking the upload rights for "
219- "the source package, component or package set in question."),
220- person, spn, archive, None, distroseries=distroseries_L)
221-
222- def test_component_rights(self):
223- # A person allowed to upload to a particular component of an archive
224- # can upload basically whatever they want to that component.
225- person = self.factory.makePerson()
226- spn = self.factory.makeSourcePackageName()
227- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
228- component = self.factory.makeComponent()
229- self.permission_set.newComponentUploader(archive, person, component)
230- self.assertCanUpload(person, spn, archive, component)
231-
232- def test_incorrect_component_rights(self):
233- # Even if a person has upload rights for a particular component in an
234- # archive, it doesn't mean they have upload rights for everything in
235- # that archive.
236- person = self.factory.makePerson()
237- spn = self.factory.makeSourcePackageName()
238- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
239- permitted_component = self.factory.makeComponent()
240- forbidden_component = self.factory.makeComponent()
241- self.permission_set.newComponentUploader(
242- archive, person, permitted_component)
243- self.assertCannotUpload(
244- u"Signer is not permitted to upload to the component '%s'." % (
245- forbidden_component.name),
246- person, spn, archive, forbidden_component)
247-
248- def test_component_rights_no_package(self):
249- # A person allowed to upload to a particular component of an archive
250- # can upload basically whatever they want to that component, even if
251- # the package doesn't exist yet.
252- person = self.factory.makePerson()
253- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
254- component = self.factory.makeComponent()
255- self.permission_set.newComponentUploader(archive, person, component)
256- self.assertCanUpload(person, None, archive, component)
257-
258- def test_non_strict_component_rights(self):
259- # If we aren't testing strict component access, then we only need to
260- # have access to an arbitrary component.
261- person = self.factory.makePerson()
262- spn = self.factory.makeSourcePackageName()
263- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
264- component_a = self.factory.makeComponent()
265- component_b = self.factory.makeComponent()
266- self.permission_set.newComponentUploader(archive, person, component_b)
267- self.assertCanUpload(
268- person, spn, archive, component_a, strict_component=False)
269-
270- def test_cannot_upload_to_disabled_archive(self):
271- spn = self.factory.makeSourcePackageName()
272- archive = self.factory.makeArchive()
273- removeSecurityProxy(archive).disable()
274- component = self.factory.makeComponent()
275- self.assertCannotUpload(u"%s is disabled." % (archive.displayname),
276- archive.owner, spn, archive, component)
277
278=== modified file 'lib/lp/buildmaster/interfaces/packagebuild.py'
279--- lib/lp/buildmaster/interfaces/packagebuild.py 2010-06-14 08:11:33 +0000
280+++ lib/lp/buildmaster/interfaces/packagebuild.py 2010-08-04 22:02:48 +0000
281@@ -106,7 +106,7 @@
282 stored.
283 """
284
285- def getLogFromSlave():
286+ def getLogFromSlave(build):
287 """Get last buildlog from slave. """
288
289 def getUploadLogContent(root, leaf):
290@@ -120,7 +120,7 @@
291 def estimateDuration():
292 """Estimate the build duration."""
293
294- def storeBuildInfo(librarian, slave_status):
295+ def storeBuildInfo(build, librarian, slave_status):
296 """Store available information for the build job.
297
298 Derived classes can override this as needed, and call it from
299
300=== modified file 'lib/lp/soyuz/model/archive.py'
301--- lib/lp/soyuz/model/archive.py 2010-08-03 14:59:22 +0000
302+++ lib/lp/soyuz/model/archive.py 2010-08-04 22:02:48 +0000
303@@ -336,9 +336,9 @@
304 def archive_url(self):
305 """See `IArchive`."""
306 archive_postfixes = {
307- ArchivePurpose.PRIMARY : '',
308- ArchivePurpose.PARTNER : '-partner',
309- ArchivePurpose.DEBUG : '-debug',
310+ ArchivePurpose.PRIMARY: '',
311+ ArchivePurpose.PARTNER: '-partner',
312+ ArchivePurpose.DEBUG: '-debug',
313 }
314
315 if self.is_ppa:
316@@ -568,7 +568,7 @@
317 # the result is empty, so instead:
318 return sum(result.values(LibraryFileContent.filesize))
319
320- def _getBinaryPublishingBaseClauses (
321+ def _getBinaryPublishingBaseClauses(
322 self, name=None, version=None, status=None, distroarchseries=None,
323 pocket=None, exact_match=False):
324 """Base clauses and clauseTables for binary publishing queries.
325@@ -648,7 +648,7 @@
326 distroarchseries=distroarchseries, exact_match=exact_match)
327
328 all_binaries = BinaryPackagePublishingHistory.select(
329- ' AND '.join(clauses) , clauseTables=clauseTables,
330+ ' AND '.join(clauses), clauseTables=clauseTables,
331 orderBy=orderBy)
332
333 return all_binaries
334@@ -720,7 +720,7 @@
335 BinaryPackagePublishingHistory.binarypackagereleaseID ==
336 BinaryPackageFile.binarypackagereleaseID,
337 BinaryPackageFile.libraryfileID == LibraryFileAlias.id,
338- LibraryFileAlias.contentID == LibraryFileContent.id
339+ LibraryFileAlias.contentID == LibraryFileContent.id,
340 ]
341
342 # Exclude DDEBs from the repository size, they are not published
343@@ -750,10 +750,10 @@
344 def allowUpdatesToReleasePocket(self):
345 """See `IArchive`."""
346 purposeToPermissionMap = {
347- ArchivePurpose.COPY : True,
348- ArchivePurpose.PARTNER : True,
349- ArchivePurpose.PPA : True,
350- ArchivePurpose.PRIMARY : False,
351+ ArchivePurpose.COPY: True,
352+ ArchivePurpose.PARTNER: True,
353+ ArchivePurpose.PPA: True,
354+ ArchivePurpose.PRIMARY: False,
355 }
356
357 try:
358@@ -775,6 +775,7 @@
359 # gets fixed we should probably change it to a normal list and
360 # benefit of the FTI rank for ordering.
361 cache_contents = set()
362+
363 def add_cache_content(content):
364 """Sanitise and add contents to the cache."""
365 content = clean_text.sub(' ', content)
366@@ -914,7 +915,7 @@
367
368 find_spec = (
369 BuildFarmJob.status,
370- Count(BinaryPackageBuild.id)
371+ Count(BinaryPackageBuild.id),
372 )
373 result = store.using(
374 BinaryPackageBuild, PackageBuild, BuildFarmJob).find(
375@@ -922,8 +923,7 @@
376 BinaryPackageBuild.package_build == PackageBuild.id,
377 PackageBuild.archive == self,
378 PackageBuild.build_farm_job == BuildFarmJob.id,
379- *extra_exprs
380- ).group_by(BuildFarmJob.status).order_by(
381+ *extra_exprs).group_by(BuildFarmJob.status).order_by(
382 BuildFarmJob.status)
383
384 # Create a map for each count summary to a number of buildstates:
385@@ -955,7 +955,7 @@
386 BuildStatus.BUILDING,
387 BuildStatus.FULLYBUILT,
388 BuildStatus.SUPERSEDED,
389- ]
390+ ],
391 }
392
393 # If we were asked to include builds with the state NEEDSBUILD,
394@@ -1097,7 +1097,11 @@
395 return None
396
397 if not self.getComponentsForUploader(person):
398- if not self.getPackagesetsForUploader(person):
399+ # XXX: JamesWestby 2010-08-01 bug=612351: We have to use
400+ # is_empty() as we don't get an SQLObjectResultSet back, and
401+ # so __nonzero__ isn't defined on it, and a straight bool
402+ # check wouldn't do the right thing.
403+ if self.getPackagesetsForUploader(person).is_empty():
404 return NoRightsForArchive()
405 else:
406 return InsufficientUploadRights()
407@@ -1668,7 +1672,6 @@
408
409 return default_name_by_purpose[purpose]
410
411-
412 def getByDistroPurpose(self, distribution, purpose, name=None):
413 """See `IArchiveSet`."""
414 if purpose == ArchivePurpose.PPA:
415@@ -1777,7 +1780,6 @@
416
417 return new_archive
418
419-
420 def __iter__(self):
421 """See `IArchiveSet`."""
422 return iter(Archive.select())
423
424=== modified file 'lib/lp/soyuz/model/buildpackagejob.py'
425--- lib/lp/soyuz/model/buildpackagejob.py 2010-06-10 12:18:10 +0000
426+++ lib/lp/soyuz/model/buildpackagejob.py 2010-08-04 22:02:48 +0000
427@@ -115,9 +115,8 @@
428 score += score_pocket
429
430 # Calculates the component-related part of the score.
431- score_component = score_componentname[
432- self.build.current_component.name]
433- score += score_component
434+ score += score_componentname.get(
435+ self.build.current_component.name, 0)
436
437 # Calculates the build queue time component of the score.
438 right_now = datetime.now(pytz.timezone('UTC'))
439
440=== modified file 'lib/lp/soyuz/stories/webservice/xx-archive.txt'
441--- lib/lp/soyuz/stories/webservice/xx-archive.txt 2010-07-27 12:33:02 +0000
442+++ lib/lp/soyuz/stories/webservice/xx-archive.txt 2010-08-04 22:02:48 +0000
443@@ -377,8 +377,8 @@
444 >>> print(response)
445 HTTP/1.1 403 Forbidden
446 ...
447- InsufficientUploadRights: The signer of this package is lacking the upload rights for the source package, component or package set in question.
448-
449+ NoRightsForArchive: The signer of this package has no upload rights to
450+ this distribution's primary archive. Did you mean to upload to a PPA?
451
452
453 Only the archive owners can add or remove component-uploaders.
454
455=== modified file 'lib/lp/soyuz/tests/test_archive.py'
456--- lib/lp/soyuz/tests/test_archive.py 2010-08-03 19:10:42 +0000
457+++ lib/lp/soyuz/tests/test_archive.py 2010-08-04 22:02:48 +0000
458@@ -1,9 +1,11 @@
459 # Copyright 2009-2010 Canonical Ltd. This software is licensed under the
460 # GNU Affero General Public License version 3 (see the file LICENSE).
461
462+from __future__ import with_statement
463+
464 """Test Archive features."""
465
466-from datetime import date, timedelta
467+from datetime import date
468
469 import transaction
470
471@@ -12,31 +14,35 @@
472 from zope.security.proxy import removeSecurityProxy
473
474 from canonical.database.sqlbase import sqlvalues
475+from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
476 from canonical.launchpad.webapp.interfaces import (
477 IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)
478 from canonical.testing import DatabaseFunctionalLayer, LaunchpadZopelessLayer
479
480 from lp.buildmaster.interfaces.buildbase import BuildStatus
481-from lp.registry.interfaces.distribution import IDistributionSet
482-from lp.registry.interfaces.person import IPersonSet
483 from lp.registry.interfaces.pocket import PackagePublishingPocket
484+from lp.registry.interfaces.series import SeriesStatus
485 from lp.services.job.interfaces.job import JobStatus
486-from lp.soyuz.interfaces.archive import (IArchiveSet, ArchivePurpose,
487- ArchiveStatus, CannotRestrictArchitectures, CannotSwitchPrivacy,
488- InvalidPocketForPartnerArchive, InvalidPocketForPPA)
489+from lp.soyuz.interfaces.archive import (
490+ ArchiveDisabled, ArchivePurpose, ArchiveStatus,
491+ CannotRestrictArchitectures, CannotSwitchPrivacy, CannotUploadToPocket,
492+ CannotUploadToPPA, IArchiveSet, InsufficientUploadRights,
493+ InvalidPocketForPartnerArchive, InvalidPocketForPPA, NoRightsForArchive,
494+ NoRightsForComponent)
495 from lp.services.worlddata.interfaces.country import ICountrySet
496 from lp.soyuz.interfaces.archivearch import IArchiveArchSet
497+from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
498 from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
499 from lp.soyuz.interfaces.binarypackagerelease import (
500 BinaryPackageFileType, BinaryPackageFormat)
501 from lp.soyuz.interfaces.component import IComponentSet
502 from lp.soyuz.interfaces.processor import IProcessorFamilySet
503 from lp.soyuz.interfaces.publishing import PackagePublishingStatus
504-from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
505 from lp.soyuz.model.binarypackagerelease import (
506 BinaryPackageReleaseDownloadCount)
507 from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
508-from lp.testing import login, login_person, TestCaseWithFactory
509+from lp.testing import (
510+ login, login_person, person_logged_in, TestCaseWithFactory)
511
512
513 class TestGetPublicationsInArchive(TestCaseWithFactory):
514@@ -207,247 +213,128 @@
515 class TestSeriesWithSources(TestCaseWithFactory):
516 """Create some sources in different series."""
517
518- layer = LaunchpadZopelessLayer
519-
520- def setUp(self):
521- super(TestSeriesWithSources, self).setUp()
522- self.publisher = SoyuzTestPublisher()
523- self.publisher.prepareBreezyAutotest()
524-
525- # Create three sources for the two different distroseries.
526- breezy_autotest = self.publisher.distroseries
527- ubuntu_test = breezy_autotest.distribution
528- self.series = [breezy_autotest]
529- self.series.append(self.factory.makeDistroRelease(
530- distribution=ubuntu_test, name="foo-series", version='1.0'))
531-
532- self.sources = []
533- gedit_src_hist = self.publisher.getPubSource(
534- sourcename="gedit", status=PackagePublishingStatus.PUBLISHED)
535- self.sources.append(gedit_src_hist)
536-
537- firefox_src_hist = self.publisher.getPubSource(
538- sourcename="firefox", status=PackagePublishingStatus.PUBLISHED,
539- distroseries=self.series[1])
540- self.sources.append(firefox_src_hist)
541-
542- gtg_src_hist = self.publisher.getPubSource(
543- sourcename="getting-things-gnome",
544- status=PackagePublishingStatus.PUBLISHED,
545- distroseries=self.series[1])
546- self.sources.append(gtg_src_hist)
547-
548- # Shortcuts for test readability.
549- self.archive = self.series[0].main_archive
550+ layer = DatabaseFunctionalLayer
551
552 def test_series_with_sources_returns_all_series(self):
553 # Calling series_with_sources returns all series with publishings.
554- series = self.archive.series_with_sources
555- series_names = [s.displayname for s in series]
556-
557- self.assertContentEqual(
558- [u'Breezy Badger Autotest', u'Foo-series'],
559- series_names)
560+ distribution = self.factory.makeDistribution()
561+ archive = self.factory.makeArchive(distribution=distribution)
562+ series_with_no_sources = self.factory.makeDistroSeries(
563+ distribution=distribution, version="0.5")
564+ series_with_sources1 = self.factory.makeDistroSeries(
565+ distribution=distribution, version="1")
566+ self.factory.makeSourcePackagePublishingHistory(
567+ distroseries=series_with_sources1, archive=archive,
568+ status=PackagePublishingStatus.PUBLISHED)
569+ series_with_sources2 = self.factory.makeDistroSeries(
570+ distribution=distribution, version="2")
571+ self.factory.makeSourcePackagePublishingHistory(
572+ distroseries=series_with_sources2, archive=archive,
573+ status=PackagePublishingStatus.PENDING)
574+ self.assertEqual(
575+ [series_with_sources2, series_with_sources1],
576+ archive.series_with_sources)
577
578 def test_series_with_sources_ignore_non_published_records(self):
579 # If all publishings in a series are deleted or superseded
580 # the series will not be returned.
581- self.sources[0].status = (
582- PackagePublishingStatus.DELETED)
583-
584- series = self.archive.series_with_sources
585- series_names = [s.displayname for s in series]
586-
587- self.assertContentEqual([u'Foo-series'], series_names)
588+ series = self.factory.makeDistroSeries()
589+ archive = self.factory.makeArchive(distribution=series.distribution)
590+ self.factory.makeSourcePackagePublishingHistory(
591+ distroseries=series, archive=archive,
592+ status=PackagePublishingStatus.DELETED)
593+ self.assertEqual([], archive.series_with_sources)
594
595 def test_series_with_sources_ordered_by_version(self):
596 # The returned series are ordered by the distroseries version.
597- series = self.archive.series_with_sources
598- versions = [s.version for s in series]
599-
600- # Latest version should be first
601- self.assertEqual(
602- [u'6.6.6', u'1.0'], versions,
603- "The latest version was not first.")
604-
605- # Update the version of breezyautotest and ensure that the
606- # latest version is still first.
607- self.series[0].version = u'0.5'
608- series = self.archive.series_with_sources
609- versions = [s.version for s in series]
610- self.assertEqual(
611- [u'1.0', u'0.5'], versions,
612- "The latest version was not first.")
613+ distribution = self.factory.makeDistribution()
614+ archive = self.factory.makeArchive(distribution=distribution)
615+ series1 = self.factory.makeDistroSeries(
616+ version="1", distribution=distribution)
617+ series2 = self.factory.makeDistroSeries(
618+ version="2", distribution=distribution)
619+ self.factory.makeSourcePackagePublishingHistory(
620+ distroseries=series1, archive=archive,
621+ status=PackagePublishingStatus.PUBLISHED)
622+ self.factory.makeSourcePackagePublishingHistory(
623+ distroseries=series2, archive=archive,
624+ status=PackagePublishingStatus.PUBLISHED)
625+ self.assertEqual([series2, series1], archive.series_with_sources)
626+ # Change the version such that they should order differently
627+ removeSecurityProxy(series2).version = "0.5"
628+ # ... and check that they do
629+ self.assertEqual([series1, series2], archive.series_with_sources)
630
631
632 class TestGetSourcePackageReleases(TestCaseWithFactory):
633
634- layer = LaunchpadZopelessLayer
635-
636- def setUp(self):
637- super(TestGetSourcePackageReleases, self).setUp()
638- self.publisher = SoyuzTestPublisher()
639- self.publisher.prepareBreezyAutotest()
640-
641- # Create an archive with some published binaries.
642- self.archive = self.factory.makeArchive()
643- binaries_foo = self.publisher.getPubBinaries(
644- archive=self.archive, binaryname="foo-bin")
645- binaries_bar = self.publisher.getPubBinaries(
646- archive=self.archive, binaryname="bar-bin")
647-
648- # Collect the builds for reference.
649- self.builds_foo = [
650- binary.binarypackagerelease.build for binary in binaries_foo]
651- self.builds_bar = [
652- binary.binarypackagerelease.build for binary in binaries_bar]
653-
654- # Collect the source package releases for reference.
655- self.sourcepackagereleases = [
656- self.builds_foo[0].source_package_release,
657- self.builds_bar[0].source_package_release,
658- ]
659+ layer = DatabaseFunctionalLayer
660+
661+ def createArchiveWithBuilds(self, statuses):
662+ archive = self.factory.makeArchive()
663+ sprs = []
664+ for status in statuses:
665+ sourcepackagerelease = self.factory.makeSourcePackageRelease()
666+ self.factory.makeBinaryPackageBuild(
667+ source_package_release=sourcepackagerelease,
668+ archive=archive, status=status)
669+ sprs.append(sourcepackagerelease)
670+ unlinked_spr = self.factory.makeSourcePackageRelease()
671+ return archive, sprs
672
673 def test_getSourcePackageReleases_with_no_params(self):
674 # With no params all source package releases are returned.
675- sprs = self.archive.getSourcePackageReleases()
676-
677- self.assertContentEqual(self.sourcepackagereleases, sprs)
678+ archive, sprs = self.createArchiveWithBuilds(
679+ [BuildStatus.NEEDSBUILD, BuildStatus.FULLYBUILT])
680+ self.assertContentEqual(
681+ sprs, archive.getSourcePackageReleases())
682
683 def test_getSourcePackageReleases_with_buildstatus(self):
684 # Results are filtered by the specified buildstatus.
685-
686- # Set the builds for one of the sprs to needs build.
687- for build in self.builds_foo:
688- removeSecurityProxy(build).status = BuildStatus.NEEDSBUILD
689-
690- result = self.archive.getSourcePackageReleases(
691- build_status=BuildStatus.NEEDSBUILD)
692-
693- self.failUnlessEqual(1, result.count())
694- self.failUnlessEqual(
695- self.sourcepackagereleases[0], result[0])
696+ archive, sprs = self.createArchiveWithBuilds(
697+ [BuildStatus.NEEDSBUILD, BuildStatus.FULLYBUILT])
698+ self.assertContentEqual(
699+ [sprs[0]], archive.getSourcePackageReleases(
700+ build_status=BuildStatus.NEEDSBUILD))
701
702
703 class TestCorrespondingDebugArchive(TestCaseWithFactory):
704
705- layer = LaunchpadZopelessLayer
706-
707- def setUp(self):
708- super(TestCorrespondingDebugArchive, self).setUp()
709-
710- self.ubuntutest = getUtility(IDistributionSet)['ubuntutest']
711-
712- # Create a debug archive, as there isn't one in the sample data.
713- self.debug_archive = getUtility(IArchiveSet).new(
714- purpose=ArchivePurpose.DEBUG,
715- distribution=self.ubuntutest,
716- owner=self.ubuntutest.owner)
717-
718- # Retrieve sample data archives of each type.
719- self.primary_archive = getUtility(IArchiveSet).getByDistroPurpose(
720- self.ubuntutest, ArchivePurpose.PRIMARY)
721- self.partner_archive = getUtility(IArchiveSet).getByDistroPurpose(
722- self.ubuntutest, ArchivePurpose.PARTNER)
723- self.copy_archive = getUtility(IArchiveSet).getByDistroPurpose(
724- self.ubuntutest, ArchivePurpose.PARTNER)
725- self.ppa = getUtility(IPersonSet).getByName('cprov').archive
726+ layer = DatabaseFunctionalLayer
727
728 def testPrimaryDebugArchiveIsDebug(self):
729- self.assertEquals(
730- self.primary_archive.debug_archive, self.debug_archive)
731+ distribution = self.factory.makeDistribution()
732+ primary = self.factory.makeArchive(
733+ distribution=distribution, purpose=ArchivePurpose.PRIMARY)
734+ debug = self.factory.makeArchive(
735+ distribution=distribution, purpose=ArchivePurpose.DEBUG)
736+ self.assertEquals(primary.debug_archive, debug)
737
738 def testPartnerDebugArchiveIsSelf(self):
739- self.assertEquals(
740- self.partner_archive.debug_archive, self.partner_archive)
741+ partner = self.factory.makeArchive(purpose=ArchivePurpose.PARTNER)
742+ self.assertEquals(partner.debug_archive, partner)
743
744 def testCopyDebugArchiveIsSelf(self):
745- self.assertEquals(
746- self.copy_archive.debug_archive, self.copy_archive)
747+ copy = self.factory.makeArchive(purpose=ArchivePurpose.COPY)
748+ self.assertEquals(copy.debug_archive, copy)
749
750 def testDebugDebugArchiveIsSelf(self):
751- self.assertEquals(
752- self.debug_archive.debug_archive, self.debug_archive)
753+ debug = self.factory.makeArchive(purpose=ArchivePurpose.DEBUG)
754+ self.assertEquals(debug.debug_archive, debug)
755
756 def testPPADebugArchiveIsSelf(self):
757- self.assertEquals(self.ppa.debug_archive, self.ppa)
758+ ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
759+ self.assertEquals(ppa.debug_archive, ppa)
760
761 def testMissingPrimaryDebugArchiveIsNone(self):
762- # Turn the DEBUG archive into a COPY archive to hide it.
763- removeSecurityProxy(self.debug_archive).purpose = ArchivePurpose.COPY
764-
765- self.assertIs(
766- self.primary_archive.debug_archive, None)
767+ primary = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
768+ self.assertIs(primary.debug_archive, None)
769
770
771 class TestArchiveEnableDisable(TestCaseWithFactory):
772 """Test the enable and disable methods of Archive."""
773
774- layer = LaunchpadZopelessLayer
775-
776- def setUp(self):
777- #XXX: rockstar - 12 Jan 2010 - Bug #506255 - Tidy up these tests!
778- super(TestArchiveEnableDisable, self).setUp()
779-
780- self.publisher = SoyuzTestPublisher()
781- self.publisher.prepareBreezyAutotest()
782-
783- self.ubuntutest = getUtility(IDistributionSet)['ubuntutest']
784- self.archive = getUtility(IArchiveSet).getByDistroPurpose(
785- self.ubuntutest, ArchivePurpose.PRIMARY)
786-
787- store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
788- sample_data = store.find(BinaryPackageBuild)
789- for build in sample_data:
790- build.buildstate = BuildStatus.FULLYBUILT
791- store.flush()
792-
793- # We test builds that target a primary archive.
794- self.builds = []
795- self.builds.extend(
796- self.publisher.getPubSource(
797- sourcename="gedit", status=PackagePublishingStatus.PUBLISHED,
798- archive=self.archive).createMissingBuilds())
799- self.builds.extend(
800- self.publisher.getPubSource(
801- sourcename="firefox",
802- status=PackagePublishingStatus.PUBLISHED,
803- archive=self.archive).createMissingBuilds())
804- self.builds.extend(
805- self.publisher.getPubSource(
806- sourcename="apg", status=PackagePublishingStatus.PUBLISHED,
807- archive=self.archive).createMissingBuilds())
808- self.builds.extend(
809- self.publisher.getPubSource(
810- sourcename="vim", status=PackagePublishingStatus.PUBLISHED,
811- archive=self.archive).createMissingBuilds())
812- self.builds.extend(
813- self.publisher.getPubSource(
814- sourcename="gcc", status=PackagePublishingStatus.PUBLISHED,
815- archive=self.archive).createMissingBuilds())
816- self.builds.extend(
817- self.publisher.getPubSource(
818- sourcename="bison", status=PackagePublishingStatus.PUBLISHED,
819- archive=self.archive).createMissingBuilds())
820- self.builds.extend(
821- self.publisher.getPubSource(
822- sourcename="flex", status=PackagePublishingStatus.PUBLISHED,
823- archive=self.archive).createMissingBuilds())
824- self.builds.extend(
825- self.publisher.getPubSource(
826- sourcename="postgres",
827- status=PackagePublishingStatus.PUBLISHED,
828- archive=self.archive).createMissingBuilds())
829- # Set up the builds for test.
830- score = 1000
831- duration = 0
832- for build in self.builds:
833- score += 1
834- duration += 60
835- bq = build.buildqueue_record
836- bq.lastscore = score
837- removeSecurityProxy(bq).estimated_duration = timedelta(
838- seconds=duration)
839+ layer = DatabaseFunctionalLayer
840
841 def _getBuildJobsByStatus(self, archive, status):
842 # Return the count for archive build jobs with the given status.
843@@ -474,92 +361,95 @@
844 # status.
845 self.assertEqual(self._getBuildJobsByStatus(archive, status), 0)
846
847- def assertHasBuildJobsWithStatus(self, archive, status):
848+ def assertHasBuildJobsWithStatus(self, archive, status, count):
849 # Check that that there are jobs attached to this archive that have
850 # the specified status.
851- self.assertEqual(self._getBuildJobsByStatus(archive, status), 8)
852+ self.assertEqual(self._getBuildJobsByStatus(archive, status), count)
853
854 def test_enableArchive(self):
855 # Enabling an archive should set all the Archive's suspended builds to
856 # WAITING.
857-
858- # Disable the archive, because it's currently enabled.
859- self.archive.disable()
860- self.assertHasBuildJobsWithStatus(self.archive, JobStatus.SUSPENDED)
861- self.archive.enable()
862- self.assertNoBuildJobsHaveStatus(self.archive, JobStatus.SUSPENDED)
863- self.assertTrue(self.archive.enabled)
864+ archive = self.factory.makeArchive(enabled=True)
865+ self.factory.makeBinaryPackageBuild(
866+ archive=archive, status=BuildStatus.NEEDSBUILD)
867+ # disable the archive, as it is currently enabled
868+ removeSecurityProxy(archive).disable()
869+ self.assertHasBuildJobsWithStatus(archive, JobStatus.SUSPENDED, 1)
870+ removeSecurityProxy(archive).enable()
871+ self.assertNoBuildJobsHaveStatus(archive, JobStatus.SUSPENDED)
872+ self.assertTrue(archive.enabled)
873
874 def test_enableArchiveAlreadyEnabled(self):
875 # Enabling an already enabled Archive should raise an AssertionError.
876- self.assertRaises(AssertionError, self.archive.enable)
877+ archive = self.factory.makeArchive(enabled=True)
878+ self.assertRaises(AssertionError, removeSecurityProxy(archive).enable)
879
880 def test_disableArchive(self):
881 # Disabling an archive should set all the Archive's pending bulds to
882 # SUSPENDED.
883- self.assertHasBuildJobsWithStatus(self.archive, JobStatus.WAITING)
884- self.archive.disable()
885- self.assertNoBuildJobsHaveStatus(self.archive, JobStatus.WAITING)
886- self.assertFalse(self.archive.enabled)
887+ archive = self.factory.makeArchive(enabled=True)
888+ self.factory.makeBinaryPackageBuild(
889+ archive=archive, status=BuildStatus.NEEDSBUILD)
890+ self.assertHasBuildJobsWithStatus(archive, JobStatus.WAITING, 1)
891+ removeSecurityProxy(archive).disable()
892+ self.assertNoBuildJobsHaveStatus(archive, JobStatus.WAITING)
893+ self.assertFalse(archive.enabled)
894
895 def test_disableArchiveAlreadyDisabled(self):
896 # Disabling an already disabled Archive should raise an
897 # AssertionError.
898- self.archive.disable()
899- self.assertRaises(AssertionError, self.archive.disable)
900+ archive = self.factory.makeArchive(enabled=False)
901+ self.assertRaises(
902+ AssertionError, removeSecurityProxy(archive).disable)
903
904
905 class TestCollectLatestPublishedSources(TestCaseWithFactory):
906 """Ensure that the private helper method works as expected."""
907
908- layer = LaunchpadZopelessLayer
909-
910- def setUp(self):
911- """Setup an archive with relevant publications."""
912- super(TestCollectLatestPublishedSources, self).setUp()
913- self.publisher = SoyuzTestPublisher()
914- self.publisher.prepareBreezyAutotest()
915-
916- # Create an archive with some published sources. We'll store
917- # a reference to the naked archive so that we can call
918- # the private method which is not defined on the interface.
919- self.archive = self.factory.makeArchive()
920- self.naked_archive = removeSecurityProxy(self.archive)
921-
922- self.pub_1 = self.publisher.getPubSource(
923- version='0.5.11~ppa1', archive=self.archive, sourcename="foo",
924- status=PackagePublishingStatus.PUBLISHED)
925-
926- self.pub_2 = self.publisher.getPubSource(
927- version='0.5.11~ppa2', archive=self.archive, sourcename="foo",
928- status=PackagePublishingStatus.PUBLISHED)
929-
930- self.pub_3 = self.publisher.getPubSource(
931- version='0.9', archive=self.archive, sourcename="bar",
932- status=PackagePublishingStatus.PUBLISHED)
933+ layer = DatabaseFunctionalLayer
934+
935+ def makePublishedSources(self, archive, statuses, versions, names):
936+ for status, version, name in zip(statuses, versions, names):
937+ self.factory.makeSourcePackagePublishingHistory(
938+ sourcepackagename=name, archive=archive,
939+ version=version, status=status)
940
941 def test_collectLatestPublishedSources_returns_latest(self):
942- pubs = self.naked_archive._collectLatestPublishedSources(
943- self.archive, ["foo"])
944+ sourcepackagename = self.factory.makeSourcePackageName(name="foo")
945+ other_spn = self.factory.makeSourcePackageName(name="bar")
946+ archive = self.factory.makeArchive()
947+ self.makePublishedSources(archive,
948+ [PackagePublishingStatus.PUBLISHED]*3,
949+ ["1.0", "1.1", "2.0"],
950+ [sourcepackagename, sourcepackagename, other_spn])
951+ pubs = removeSecurityProxy(archive)._collectLatestPublishedSources(
952+ archive, ["foo"])
953 self.assertEqual(1, len(pubs))
954- self.assertEqual('0.5.11~ppa2', pubs[0].source_package_version)
955+ self.assertEqual('1.1', pubs[0].source_package_version)
956
957 def test_collectLatestPublishedSources_returns_published_only(self):
958 # Set the status of the latest pub to DELETED and ensure that it
959 # is not returned.
960- self.pub_2.status = PackagePublishingStatus.DELETED
961-
962- pubs = self.naked_archive._collectLatestPublishedSources(
963- self.archive, ["foo"])
964+ sourcepackagename = self.factory.makeSourcePackageName(name="foo")
965+ other_spn = self.factory.makeSourcePackageName(name="bar")
966+ archive = self.factory.makeArchive()
967+ self.makePublishedSources(archive,
968+ [PackagePublishingStatus.PUBLISHED,
969+ PackagePublishingStatus.DELETED,
970+ PackagePublishingStatus.PUBLISHED],
971+ ["1.0", "1.1", "2.0"],
972+ [sourcepackagename, sourcepackagename, other_spn])
973+ pubs = removeSecurityProxy(archive)._collectLatestPublishedSources(
974+ archive, ["foo"])
975 self.assertEqual(1, len(pubs))
976- self.assertEqual('0.5.11~ppa1', pubs[0].source_package_version)
977+ self.assertEqual('1.0', pubs[0].source_package_version)
978
979
980 class TestArchiveCanUpload(TestCaseWithFactory):
981 """Test the various methods that verify whether uploads are allowed to
982 happen."""
983
984- layer = LaunchpadZopelessLayer
985+ layer = DatabaseFunctionalLayer
986
987 def test_checkArchivePermission_by_PPA_owner(self):
988 # Uploading to a PPA should be allowed for a user that is the owner
989@@ -572,50 +462,356 @@
990
991 def test_checkArchivePermission_distro_archive(self):
992 # Regular users can not upload to ubuntu
993- ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
994- archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY,
995- distribution=ubuntu)
996+ archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
997 main = getUtility(IComponentSet)["main"]
998 # A regular user doesn't have access
999- somebody = self.factory.makePerson(name="somebody")
1000+ somebody = self.factory.makePerson()
1001 self.assertEquals(False,
1002 archive.checkArchivePermission(somebody, main))
1003 # An ubuntu core developer does have access
1004- kamion = getUtility(IPersonSet).getByName('kamion')
1005- self.assertEquals(True, archive.checkArchivePermission(kamion, main))
1006+ coredev = self.factory.makePerson()
1007+ with person_logged_in(archive.owner):
1008+ archive.newComponentUploader(coredev, main.name)
1009+ self.assertEquals(True, archive.checkArchivePermission(coredev, main))
1010
1011 def test_checkArchivePermission_ppa(self):
1012- ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
1013- owner = self.factory.makePerson(name="eigenaar")
1014+ owner = self.factory.makePerson()
1015 archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA,
1016- distribution=ubuntu,
1017 owner=owner)
1018- somebody = self.factory.makePerson(name="somebody")
1019+ somebody = self.factory.makePerson()
1020 # The owner has access
1021 self.assertEquals(True, archive.checkArchivePermission(owner))
1022 # Somebody unrelated does not
1023 self.assertEquals(False, archive.checkArchivePermission(somebody))
1024
1025+ def makeArchiveAndActiveDistroSeries(self, purpose=None):
1026+ if purpose is None:
1027+ purpose = ArchivePurpose.PRIMARY
1028+ archive = self.factory.makeArchive(purpose=purpose)
1029+ distroseries = self.factory.makeDistroSeries(
1030+ distribution=archive.distribution,
1031+ status=SeriesStatus.DEVELOPMENT)
1032+ return archive, distroseries
1033+
1034+ def makePersonWithComponentPermission(self, archive):
1035+ person = self.factory.makePerson()
1036+ component = self.factory.makeComponent()
1037+ removeSecurityProxy(archive).newComponentUploader(
1038+ person, component)
1039+ return person, component
1040+
1041+ def checkUpload(self, archive, person, sourcepackagename,
1042+ distroseries=None, component=None,
1043+ pocket=None, strict_component=False):
1044+ if distroseries is None:
1045+ distroseries = self.factory.makeDistroSeries()
1046+ if component is None:
1047+ component = self.factory.makeComponent()
1048+ if pocket is None:
1049+ pocket = PackagePublishingPocket.RELEASE
1050+ return archive.checkUpload(
1051+ person, distroseries, sourcepackagename, component, pocket,
1052+ strict_component=strict_component)
1053+
1054+ def assertCanUpload(self, archive, person, sourcepackagename,
1055+ distroseries=None, component=None,
1056+ pocket=None, strict_component=False):
1057+ """Assert an upload to 'archive' will be accepted."""
1058+ self.assertIs(
1059+ None,
1060+ self.checkUpload(
1061+ archive, person, sourcepackagename,
1062+ distroseries=distroseries, component=component,
1063+ pocket=pocket, strict_component=strict_component))
1064+
1065+ def assertCannotUpload(self, reason, archive, person, sourcepackagename,
1066+ distroseries=None, component=None, pocket=None,
1067+ strict_component=False):
1068+ """Assert that upload to 'archive' will be rejected.
1069+
1070+ :param reason: The expected reason for not being able to upload. A
1071+ class.
1072+ """
1073+ self.assertIsInstance(
1074+ self.checkUpload(
1075+ archive, person, sourcepackagename,
1076+ distroseries=distroseries, component=component,
1077+ pocket=pocket, strict_component=strict_component),
1078+ reason
1079+ )
1080+
1081 def test_checkUpload_partner_invalid_pocket(self):
1082 # Partner archives only have release and proposed pockets
1083- archive = self.factory.makeArchive(purpose=ArchivePurpose.PARTNER)
1084- self.assertIsInstance(archive.checkUpload(self.factory.makePerson(),
1085- self.factory.makeDistroSeries(),
1086- self.factory.makeSourcePackageName(),
1087- self.factory.makeComponent(),
1088- PackagePublishingPocket.UPDATES),
1089- InvalidPocketForPartnerArchive)
1090+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1091+ purpose=ArchivePurpose.PARTNER)
1092+ self.assertCannotUpload(
1093+ InvalidPocketForPartnerArchive, archive,
1094+ self.factory.makePerson(), self.factory.makeSourcePackageName(),
1095+ pocket=PackagePublishingPocket.UPDATES,
1096+ distroseries=distroseries)
1097
1098 def test_checkUpload_ppa_invalid_pocket(self):
1099 # PPA archives only have release pockets
1100- archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
1101- self.assertIsInstance(archive.checkUpload(self.factory.makePerson(),
1102- self.factory.makeDistroSeries(),
1103- self.factory.makeSourcePackageName(),
1104- self.factory.makeComponent(),
1105- PackagePublishingPocket.PROPOSED),
1106- InvalidPocketForPPA)
1107- # XXX: JRV 20100511: IArchive.canUploadSuiteSourcePackage needs tests
1108+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1109+ purpose=ArchivePurpose.PPA)
1110+ self.assertCannotUpload(
1111+ InvalidPocketForPPA, archive,
1112+ self.factory.makePerson(), self.factory.makeSourcePackageName(),
1113+ pocket=PackagePublishingPocket.PROPOSED,
1114+ distroseries=distroseries)
1115+
1116+ def test_checkUpload_invalid_pocket_for_series_state(self):
1117+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1118+ purpose=ArchivePurpose.PRIMARY)
1119+ self.assertCannotUpload(
1120+ CannotUploadToPocket, archive,
1121+ self.factory.makePerson(), self.factory.makeSourcePackageName(),
1122+ pocket=PackagePublishingPocket.PROPOSED,
1123+ distroseries=distroseries)
1124+
1125+ def test_checkUpload_disabled_archive(self):
1126+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1127+ purpose=ArchivePurpose.PRIMARY)
1128+ removeSecurityProxy(archive).disable()
1129+ self.assertCannotUpload(
1130+ ArchiveDisabled, archive, self.factory.makePerson(),
1131+ self.factory.makeSourcePackageName(),
1132+ distroseries=distroseries)
1133+
1134+ def test_checkUpload_ppa_owner(self):
1135+ person = self.factory.makePerson()
1136+ archive = self.factory.makeArchive(
1137+ purpose=ArchivePurpose.PPA, owner=person)
1138+ self.assertCanUpload(
1139+ archive, person, self.factory.makeSourcePackageName())
1140+
1141+ def test_checkUpload_ppa_with_permission(self):
1142+ archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
1143+ person = self.factory.makePerson()
1144+ removeSecurityProxy(archive).newComponentUploader(person, "main")
1145+ # component is ignored
1146+ self.assertCanUpload(
1147+ archive, person, self.factory.makeSourcePackageName(),
1148+ component=self.factory.makeComponent(name="universe"))
1149+
1150+ def test_checkUpload_ppa_with_no_permission(self):
1151+ archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
1152+ person = self.factory.makePerson()
1153+ self.assertCannotUpload(
1154+ CannotUploadToPPA, archive, person,
1155+ self.factory.makeSourcePackageName())
1156+
1157+ def test_owner_can_upload_to_ppa_no_sourcepackage(self):
1158+ # The owner can upload to PPAs even if the source package doesn't
1159+ # exist yet.
1160+ team = self.factory.makeTeam()
1161+ archive = self.factory.makeArchive(
1162+ purpose=ArchivePurpose.PPA, owner=team)
1163+ person = self.factory.makePerson()
1164+ removeSecurityProxy(team).addMember(person, team.teamowner)
1165+ self.assertCanUpload(archive, person, None)
1166+
1167+ def test_can_upload_to_ppa_for_old_series(self):
1168+ # You can upload whatever you want to a PPA, regardless of the upload
1169+ # policy.
1170+ person = self.factory.makePerson()
1171+ archive = self.factory.makeArchive(
1172+ purpose=ArchivePurpose.PPA, owner=person)
1173+ spn = self.factory.makeSourcePackageName()
1174+ distroseries = self.factory.makeDistroSeries(
1175+ status=SeriesStatus.CURRENT)
1176+ self.assertCanUpload(
1177+ archive, person, spn, distroseries=distroseries)
1178+
1179+ def test_checkUpload_copy_archive_no_permission(self):
1180+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1181+ purpose=ArchivePurpose.COPY)
1182+ sourcepackagename = self.factory.makeSourcePackageName()
1183+ person = self.factory.makePerson()
1184+ removeSecurityProxy(archive).newPackageUploader(
1185+ person, sourcepackagename)
1186+ self.assertCannotUpload(
1187+ NoRightsForArchive, archive, person, sourcepackagename,
1188+ distroseries=distroseries)
1189+
1190+ def test_checkUpload_package_permission(self):
1191+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1192+ purpose=ArchivePurpose.PRIMARY)
1193+ sourcepackagename = self.factory.makeSourcePackageName()
1194+ person = self.factory.makePerson()
1195+ removeSecurityProxy(archive).newPackageUploader(
1196+ person, sourcepackagename)
1197+ self.assertCanUpload(
1198+ archive, person, sourcepackagename, distroseries=distroseries)
1199+
1200+ def make_person_with_packageset_permission(self, archive, distroseries,
1201+ packages=()):
1202+ packageset = self.factory.makePackageset(
1203+ distroseries=distroseries, packages=packages)
1204+ person = self.factory.makePerson()
1205+ techboard = getUtility(ILaunchpadCelebrities).ubuntu_techboard
1206+ with person_logged_in(techboard):
1207+ archive.newPackagesetUploader(person, packageset)
1208+ return person, packageset
1209+
1210+ def test_checkUpload_packageset_permission(self):
1211+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1212+ purpose=ArchivePurpose.PRIMARY)
1213+ sourcepackagename = self.factory.makeSourcePackageName()
1214+ person, packageset = self.make_person_with_packageset_permission(
1215+ archive, distroseries, packages=[sourcepackagename])
1216+ self.assertCanUpload(
1217+ archive, person, sourcepackagename, distroseries=distroseries)
1218+
1219+ def test_checkUpload_packageset_wrong_distroseries(self):
1220+ # A person with rights to upload to the package set in distro
1221+ # series K may not upload with these same rights to a different
1222+ # distro series L.
1223+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1224+ purpose=ArchivePurpose.PRIMARY)
1225+ sourcepackagename = self.factory.makeSourcePackageName()
1226+ person, packageset = self.make_person_with_packageset_permission(
1227+ archive, distroseries, packages=[sourcepackagename])
1228+ other_distroseries = self.factory.makeDistroSeries()
1229+ self.assertCannotUpload(
1230+ InsufficientUploadRights, archive, person, sourcepackagename,
1231+ distroseries=other_distroseries)
1232+
1233+ def test_checkUpload_component_permission(self):
1234+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1235+ purpose=ArchivePurpose.PRIMARY)
1236+ sourcepackagename = self.factory.makeSourcePackageName()
1237+ person, component = self.makePersonWithComponentPermission(
1238+ archive)
1239+ self.assertCanUpload(
1240+ archive, person, sourcepackagename, distroseries=distroseries,
1241+ component=component)
1242+
1243+ def test_checkUpload_no_permissions(self):
1244+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1245+ purpose=ArchivePurpose.PRIMARY)
1246+ sourcepackagename = self.factory.makeSourcePackageName()
1247+ person = self.factory.makePerson()
1248+ self.assertCannotUpload(
1249+ NoRightsForArchive, archive, person, sourcepackagename,
1250+ distroseries=distroseries)
1251+
1252+ def test_checkUpload_insufficient_permissions(self):
1253+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1254+ purpose=ArchivePurpose.PRIMARY)
1255+ sourcepackagename = self.factory.makeSourcePackageName()
1256+ person, packageset = self.make_person_with_packageset_permission(
1257+ archive, distroseries)
1258+ self.assertCannotUpload(
1259+ InsufficientUploadRights, archive, person, sourcepackagename,
1260+ distroseries=distroseries)
1261+
1262+ def test_checkUpload_without_strict_component(self):
1263+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1264+ purpose=ArchivePurpose.PRIMARY)
1265+ sourcepackagename = self.factory.makeSourcePackageName()
1266+ person, component = self.makePersonWithComponentPermission(
1267+ archive)
1268+ other_component = self.factory.makeComponent()
1269+ self.assertCanUpload(
1270+ archive, person, sourcepackagename, distroseries=distroseries,
1271+ component=other_component, strict_component=False)
1272+
1273+ def test_checkUpload_with_strict_component(self):
1274+ archive, distroseries = self.makeArchiveAndActiveDistroSeries(
1275+ purpose=ArchivePurpose.PRIMARY)
1276+ sourcepackagename = self.factory.makeSourcePackageName()
1277+ person, component = self.makePersonWithComponentPermission(
1278+ archive)
1279+ other_component = self.factory.makeComponent()
1280+ self.assertCannotUpload(
1281+ NoRightsForComponent, archive, person, sourcepackagename,
1282+ distroseries=distroseries, component=other_component,
1283+ strict_component=True)
1284+
1285+ def test_checkUpload_component_rights_no_package(self):
1286+ # A person allowed to upload to a particular component of an archive
1287+ # can upload basically whatever they want to that component, even if
1288+ # the package doesn't exist yet.
1289+ archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
1290+ person, component = self.makePersonWithComponentPermission(
1291+ archive)
1292+ self.assertCanUpload(archive, person, None, component=component)
1293+
1294+ def makePackageToUpload(self, distroseries):
1295+ sourcepackagename = self.factory.makeSourcePackageName()
1296+ suitesourcepackage = self.factory.makeSuiteSourcePackage(
1297+ pocket=PackagePublishingPocket.RELEASE,
1298+ sourcepackagename=sourcepackagename,
1299+ distroseries=distroseries)
1300+ return suitesourcepackage
1301+
1302+ def test_canUploadSuiteSourcePackage_invalid_pocket(self):
1303+ # Test that canUploadSuiteSourcePackage calls checkUpload for
1304+ # the pocket checks.
1305+ person = self.factory.makePerson()
1306+ archive = self.factory.makeArchive(
1307+ purpose=ArchivePurpose.PPA, owner=person)
1308+ suitesourcepackage = self.factory.makeSuiteSourcePackage(
1309+ pocket=PackagePublishingPocket.PROPOSED)
1310+ self.assertEqual(
1311+ False,
1312+ archive.canUploadSuiteSourcePackage(person, suitesourcepackage))
1313+
1314+ def test_canUploadSuiteSourcePackage_no_permission(self):
1315+ # Test that canUploadSuiteSourcePackage calls verifyUpload for
1316+ # the permission checks.
1317+ archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
1318+ suitesourcepackage = self.factory.makeSuiteSourcePackage(
1319+ pocket=PackagePublishingPocket.RELEASE)
1320+ person = self.factory.makePerson()
1321+ self.assertEqual(
1322+ False,
1323+ archive.canUploadSuiteSourcePackage(person, suitesourcepackage))
1324+
1325+ def test_canUploadSuiteSourcePackage_package_permission(self):
1326+ # Test that a package permission is enough to upload a new
1327+ # package.
1328+ archive, distroseries = self.makeArchiveAndActiveDistroSeries()
1329+ suitesourcepackage = self.makePackageToUpload(distroseries)
1330+ person = self.factory.makePerson()
1331+ removeSecurityProxy(archive).newPackageUploader(
1332+ person, suitesourcepackage.sourcepackagename)
1333+ self.assertEqual(
1334+ True,
1335+ archive.canUploadSuiteSourcePackage(person, suitesourcepackage))
1336+
1337+ def test_canUploadSuiteSourcePackage_component_permission(self):
1338+ # Test that component upload permission is enough to be
1339+ # allowed to upload a new package.
1340+ archive, distroseries = self.makeArchiveAndActiveDistroSeries()
1341+ suitesourcepackage = self.makePackageToUpload(distroseries)
1342+ person = self.factory.makePerson()
1343+ removeSecurityProxy(archive).newComponentUploader(person, "universe")
1344+ self.assertEqual(
1345+ True,
1346+ archive.canUploadSuiteSourcePackage(person, suitesourcepackage))
1347+
1348+ def test_canUploadSuiteSourcePackage_strict_component(self):
1349+ # Test that canUploadSuiteSourcePackage uses strict component
1350+ # checking.
1351+ archive, distroseries = self.makeArchiveAndActiveDistroSeries()
1352+ suitesourcepackage = self.makePackageToUpload(distroseries)
1353+ main_component = self.factory.makeComponent(name="main")
1354+ self.factory.makeSourcePackagePublishingHistory(
1355+ archive=archive, distroseries=distroseries,
1356+ sourcepackagename=suitesourcepackage.sourcepackagename,
1357+ status=PackagePublishingStatus.PUBLISHED,
1358+ pocket=PackagePublishingPocket.RELEASE,
1359+ component=main_component)
1360+ person = self.factory.makePerson()
1361+ removeSecurityProxy(archive).newComponentUploader(person, "universe")
1362+ # This time the user can't upload as there has been a
1363+ # publication and they don't have permission for the component
1364+ # the package is published in.
1365+ self.assertEqual(
1366+ False,
1367+ archive.canUploadSuiteSourcePackage(person, suitesourcepackage))
1368
1369
1370 class TestUpdatePackageDownloadCount(TestCaseWithFactory):
1371@@ -1216,3 +1412,29 @@
1372 component=getUtility(IComponentSet)['universe'])
1373 self.assertDep('i386', 'foo-main', [main_bins[0]])
1374 self.assertDep('i386', 'foo-universe', [universe_bins[0]])
1375+
1376+
1377+class TestComponents(TestCaseWithFactory):
1378+
1379+ layer = DatabaseFunctionalLayer
1380+
1381+ def test_no_components_for_arbitrary_person(self):
1382+ # By default, a person cannot upload to any component of an archive.
1383+ archive = self.factory.makeArchive()
1384+ person = self.factory.makePerson()
1385+ self.assertEqual(set(),
1386+ set(archive.getComponentsForUploader(person)))
1387+
1388+ def test_components_for_person_with_permissions(self):
1389+ # If a person has been explicitly granted upload permissions to a
1390+ # particular component, then those components are included in
1391+ # IArchive.getComponentsForUploader.
1392+ archive = self.factory.makeArchive()
1393+ component = self.factory.makeComponent()
1394+ person = self.factory.makePerson()
1395+ # Only admins or techboard members can add permissions normally. That
1396+ # restriction isn't relevant to this test.
1397+ ap_set = removeSecurityProxy(getUtility(IArchivePermissionSet))
1398+ ap = ap_set.newComponentUploader(archive, person, component)
1399+ self.assertEqual(set([ap]),
1400+ set(archive.getComponentsForUploader(person)))
1401
1402=== modified file 'lib/lp/soyuz/tests/test_buildpackagejob.py'
1403--- lib/lp/soyuz/tests/test_buildpackagejob.py 2010-05-13 19:36:56 +0000
1404+++ lib/lp/soyuz/tests/test_buildpackagejob.py 2010-08-04 22:02:48 +0000
1405@@ -10,7 +10,7 @@
1406
1407 from canonical.launchpad.webapp.interfaces import (
1408 IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)
1409-from canonical.testing import LaunchpadZopelessLayer
1410+from canonical.testing import DatabaseFunctionalLayer, LaunchpadZopelessLayer
1411
1412 from lp.buildmaster.interfaces.buildbase import BuildStatus
1413 from lp.buildmaster.interfaces.builder import IBuilderSet
1414@@ -244,3 +244,22 @@
1415 build_package_job.jobStarted()
1416 self.failUnlessEqual(
1417 BuildStatus.BUILDING, build_package_job.build.status)
1418+
1419+
1420+class TestBuildPackageJobScore(TestCaseWithFactory):
1421+
1422+ layer = DatabaseFunctionalLayer
1423+
1424+ def test_score_unusual_component(self):
1425+ unusual_component = self.factory.makeComponent(name="unusual")
1426+ source_package_release = self.factory.makeSourcePackageRelease()
1427+ self.factory.makeSourcePackagePublishingHistory(
1428+ sourcepackagerelease=source_package_release,
1429+ component=unusual_component,
1430+ archive=source_package_release.upload_archive,
1431+ distroseries=source_package_release.upload_distroseries)
1432+ build = self.factory.makeBinaryPackageBuild(
1433+ source_package_release=source_package_release)
1434+ job = build.buildqueue_record.specific_job
1435+ # For now just test that it doesn't raise an Exception
1436+ job.score()
1437
1438=== modified file 'lib/lp/testing/factory.py'
1439--- lib/lp/testing/factory.py 2010-08-04 00:41:14 +0000
1440+++ lib/lp/testing/factory.py 2010-08-04 22:02:48 +0000
1441@@ -2363,7 +2363,8 @@
1442 libraryfile=library_file, filetype=filetype))
1443
1444 def makeBinaryPackageBuild(self, source_package_release=None,
1445- distroarchseries=None, archive=None, builder=None):
1446+ distroarchseries=None, archive=None, builder=None,
1447+ status=None):
1448 """Create a BinaryPackageBuild.
1449
1450 If archive is not supplied, the source_package_release is used
1451@@ -2373,6 +2374,7 @@
1452 :param distroarchseries: The DistroArchSeries to use.
1453 :param archive: The Archive to use.
1454 :param builder: An optional builder to assign.
1455+ :param status: The BuildStatus for the build.
1456 """
1457 if archive is None:
1458 if source_package_release is None:
1459@@ -2383,16 +2385,21 @@
1460 multiverse = self.makeComponent(name='multiverse')
1461 source_package_release = self.makeSourcePackageRelease(
1462 archive, component=multiverse)
1463+ self.makeSourcePackagePublishingHistory(
1464+ distroseries=source_package_release.upload_distroseries,
1465+ archive=archive, sourcepackagerelease=source_package_release)
1466 processor = self.makeProcessor()
1467 if distroarchseries is None:
1468 distroarchseries = self.makeDistroArchSeries(
1469 distroseries=source_package_release.upload_distroseries,
1470 processorfamily=processor.family)
1471+ if status is None:
1472+ status = BuildStatus.NEEDSBUILD
1473 binary_package_build = getUtility(IBinaryPackageBuildSet).new(
1474 source_package_release=source_package_release,
1475 processor=processor,
1476 distro_arch_series=distroarchseries,
1477- status=BuildStatus.NEEDSBUILD,
1478+ status=status,
1479 archive=archive,
1480 pocket=PackagePublishingPocket.RELEASE,
1481 date_created=self.getUniqueDate())
1482@@ -2611,7 +2618,8 @@
1483 isinstance(sourcepackagename, basestring)):
1484 sourcepackagename = self.getOrMakeSourcePackageName(
1485 sourcepackagename)
1486- return SuiteSourcePackage(distroseries, pocket, sourcepackagename)
1487+ return ProxyFactory(
1488+ SuiteSourcePackage(distroseries, pocket, sourcepackagename))
1489
1490 def makeDistributionSourcePackage(self, sourcepackagename=None,
1491 distribution=None):
1492
1493=== modified file 'lib/lp/testing/tests/test_factory.py'
1494--- lib/lp/testing/tests/test_factory.py 2010-08-02 19:52:59 +0000
1495+++ lib/lp/testing/tests/test_factory.py 2010-08-04 22:02:48 +0000
1496@@ -15,9 +15,12 @@
1497 from canonical.launchpad.webapp.interfaces import ILaunchBag
1498 from canonical.testing.layers import (
1499 DatabaseFunctionalLayer, LaunchpadZopelessLayer)
1500+from lp.buildmaster.interfaces.buildbase import BuildStatus
1501 from lp.code.enums import CodeImportReviewStatus
1502 from lp.registry.interfaces.sourcepackage import SourcePackageFileType
1503+from lp.registry.interfaces.suitesourcepackage import ISuiteSourcePackage
1504 from lp.services.worlddata.interfaces.language import ILanguage
1505+from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuild
1506 from lp.soyuz.interfaces.binarypackagerelease import (
1507 BinaryPackageFileType, IBinaryPackageRelease)
1508 from lp.soyuz.interfaces.files import (
1509@@ -42,6 +45,32 @@
1510 self.assertIsNot(None, person)
1511 self.assertEqual(person, current_person)
1512
1513+ # makeBinaryPackageBuild
1514+ def test_makeBinaryPackageBuild_returns_IBinaryPackageBuild(self):
1515+ bpb = self.factory.makeBinaryPackageBuild()
1516+ self.assertThat(
1517+ removeSecurityProxy(bpb), Provides(IBinaryPackageBuild))
1518+
1519+ def test_makeBinaryPackageBuild_returns_proxy(self):
1520+ bpb = self.factory.makeBinaryPackageBuild()
1521+ self.assertThat(bpb, IsProxied())
1522+
1523+ def test_makeBinaryPackageBuild_created_SPR_is_published(self):
1524+ # It is expected that every build references an SPR that is
1525+ # published in the target archive. Check that a created
1526+ # SPR is also published.
1527+ bpb = self.factory.makeBinaryPackageBuild()
1528+ self.assertIn(
1529+ bpb.archive, bpb.source_package_release.published_archives)
1530+
1531+ def test_makeBinaryPackageBuild_uses_status(self):
1532+ bpb = self.factory.makeBinaryPackageBuild(
1533+ status=BuildStatus.NEEDSBUILD)
1534+ self.assertEqual(BuildStatus.NEEDSBUILD, bpb.status)
1535+ bpb = self.factory.makeBinaryPackageBuild(
1536+ status=BuildStatus.FULLYBUILT)
1537+ self.assertEqual(BuildStatus.FULLYBUILT, bpb.status)
1538+
1539 # makeBinaryPackagePublishingHistory
1540 def test_makeBinaryPackagePublishingHistory_returns_IBPPH(self):
1541 bpph = self.factory.makeBinaryPackagePublishingHistory()
1542@@ -170,6 +199,11 @@
1543 scheduleddeletiondate=scheduleddeletiondate)
1544 self.assertEquals(scheduleddeletiondate, spph.scheduleddeletiondate)
1545
1546+ # makeSuiteSourcePackage
1547+ def test_makeSuiteSourcePackage_returns_ISuiteSourcePackage(self):
1548+ ssp = self.factory.makeSuiteSourcePackage()
1549+ self.assertThat(ssp, ProvidesAndIsProxied(ISuiteSourcePackage))
1550+
1551
1552 class TestFactoryWithLibrarian(TestCaseWithFactory):
1553