← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~james-w/launchpad/no-more-sampledata-0 into lp:launchpad/devel

 

James Westby has proposed merging lp:~james-w/launchpad/no-more-sampledata-0 into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


Hi,

This changes a bunch of soyuz tests to not use the sampledata.

It goes a bit further than that in that it restructures them to
have less setup and to create the things they need using the
factory rather than SoyuzTestPublisher.

In addition I moved some other code that is too deeply buried
right now in to lp.testing.sampledata, and extended the factory
with some new methods to satisfy the needs of the changed code.

Thanks,

James

-- 
https://code.launchpad.net/~james-w/launchpad/no-more-sampledata-0/+merge/31470
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~james-w/launchpad/no-more-sampledata-0 into lp:launchpad/devel.
=== modified file 'lib/lp/soyuz/tests/ppa.py'
--- lib/lp/soyuz/tests/ppa.py	2010-03-11 16:48:37 +0000
+++ lib/lp/soyuz/tests/ppa.py	2010-07-31 23:06:48 +0000
@@ -25,6 +25,10 @@
 from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
 from lp.soyuz.interfaces.publishing import (
     PackagePublishingPriority, PackagePublishingStatus)
+from lp.testing.sampledata import (
+    HOARY_DISTROSERIES_NAME, I386_ARCHITECTURE_NAME, MAIN_COMPONENT_NAME,
+    MOZILLA_FIREFOX_SOURCEPACKAGENAME, MOZILLA_FIREFOX_SOURCEPACKAGEVERSION,
+    NAME16_PERSON_NAME, UBUNTU_TEAM_NAME)
 
 
 def publishToTeamPPA(team_name=None, distroseries_name=None,
@@ -40,9 +44,9 @@
     The team PPA must already be created.
     """
     if team_name is None:
-        team_name = "ubuntu-team"
+        team_name = UBUNTU_TEAM_NAME
     if team_member_name is None:
-        team_member_name = "name16"
+        team_member_name = NAME16_PERSON_NAME
     team = getUtility(IPersonSet).getByName(team_name)
     _publishToPPA(
         team.archive, team_member_name, distroseries_name,
@@ -67,15 +71,15 @@
     else:
         distribution = getUtility(IDistributionSet)[distribution_name]
     if distroseries_name is None:
-        distroseries_name = "hoary"
+        distroseries_name = HOARY_DISTROSERIES_NAME
     if sourcepackage_name is None:
-        sourcepackage_name = "mozilla-firefox"
+        sourcepackage_name = MOZILLA_FIREFOX_SOURCEPACKAGENAME
     if sourcepackage_version is None:
-        sourcepackage_version = "0.9"
+        sourcepackage_version = MOZILLA_FIREFOX_SOURCEPACKAGEVERSION
     if publishing_status is None:
         publishing_status = PackagePublishingStatus.PENDING
     if arch is None:
-        arch = "i386"
+        arch = I386_ARCHITECTURE_NAME
 
     sourcepackagename = getUtility(ISourcePackageNameSet)[sourcepackage_name]
     distroseries = distribution[distroseries_name]
@@ -88,7 +92,7 @@
         # XXX: kiko 2007-10-25: oy, what a hack. I need to test with cprov
         # and he doesn't have a signing key in the database
         sourcepackagerelease.dscsigningkey = person.gpg_keys[0]
-    main_component = getUtility(IComponentSet)['main']
+    main_component = getUtility(IComponentSet)[MAIN_COMPONENT_NAME]
     SourcePackagePublishingHistory(
         distroseries=distroseries,
         sourcepackagerelease=sourcepackagerelease,

=== modified file 'lib/lp/soyuz/tests/soyuz.py'
--- lib/lp/soyuz/tests/soyuz.py	2010-02-08 11:40:06 +0000
+++ lib/lp/soyuz/tests/soyuz.py	2010-07-31 23:06:48 +0000
@@ -27,14 +27,19 @@
 from lp.soyuz.model.publishing import (
     SourcePackagePublishingHistory,
     BinaryPackagePublishingHistory)
+from lp.testing.sampledata import (
+    CHROOT_LFA, CPROV_NAME, I386_ARCHITECTURE_NAME, LAUNCHPAD_DBUSER_NAME,
+    UBUNTU_DISTRIBUTION_NAME, WARTY_DISTROSERIES_NAME,
+    WARTY_UPDATES_SUITE_NAME)
 
 
 class SoyuzTestHelper:
     """Helper class to support easier tests in Soyuz component."""
 
     def __init__(self):
-        self.ubuntu = getUtility(IDistributionSet)['ubuntu']
-        self.cprov_archive = getUtility(IPersonSet).getByName('cprov').archive
+        self.ubuntu = getUtility(IDistributionSet)[UBUNTU_DISTRIBUTION_NAME]
+        self.cprov_archive = getUtility(
+            IPersonSet).getByName(CPROV_NAME).archive
 
     @property
     def sample_publishing_data(self):
@@ -142,12 +147,13 @@
         Store the `FakePackager` object used in the test uploads as `packager`
         so the tests can reuse it if necessary.
         """
-        self.layer.alterConnection(dbuser='launchpad')
+        self.layer.alterConnection(dbuser=LAUNCHPAD_DBUSER_NAME)
 
-        fake_chroot = LibraryFileAlias.get(1)
-        ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
-        warty = ubuntu.getSeries('warty')
-        warty['i386'].addOrUpdateChroot(fake_chroot)
+        fake_chroot = LibraryFileAlias.get(CHROOT_LFA)
+        ubuntu = getUtility(IDistributionSet).getByName(
+            UBUNTU_DISTRIBUTION_NAME)
+        warty = ubuntu.getSeries(WARTY_DISTROSERIES_NAME)
+        warty[I386_ARCHITECTURE_NAME].addOrUpdateChroot(fake_chroot)
 
         self.layer.txn.commit()
 
@@ -176,13 +182,13 @@
             'zeca', '1.0', 'foo.bar@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
         packager.buildUpstream()
         packager.buildSource()
-        packager.uploadSourceVersion('1.0-1', suite="warty-updates")
+        packager.uploadSourceVersion('1.0-1', suite=WARTY_UPDATES_SUITE_NAME)
 
         # Upload a new version of the source, so a PackageDiff can
         # be created.
         packager.buildVersion('1.0-2', changelog_text="cookies")
         packager.buildSource(include_orig=False)
-        packager.uploadSourceVersion('1.0-2', suite="warty-updates")
+        packager.uploadSourceVersion('1.0-2', suite=WARTY_UPDATES_SUITE_NAME)
 
         # Check if there is exactly one pending PackageDiff record and
         # It's the one we have just created.

=== modified file 'lib/lp/soyuz/tests/soyuzbuilddhelpers.py'
--- lib/lp/soyuz/tests/soyuzbuilddhelpers.py	2010-04-14 13:54:06 +0000
+++ lib/lp/soyuz/tests/soyuzbuilddhelpers.py	2010-07-31 23:06:48 +0000
@@ -26,6 +26,7 @@
     updateBuilderStatus)
 from lp.soyuz.model.binarypackagebuildbehavior import (
     BinaryPackageBuildBehavior)
+from lp.testing.sampledata import I386_ARCHITECTURE_NAME
 
 
 class MockBuilder:
@@ -85,7 +86,7 @@
 
     The architecture tag can be customised during initialisation."""
 
-    def __init__(self, arch_tag='i386'):
+    def __init__(self, arch_tag=I386_ARCHITECTURE_NAME):
         self.arch_tag = arch_tag
 
     def status(self):

=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py	2010-07-21 07:45:50 +0000
+++ lib/lp/soyuz/tests/test_archive.py	2010-07-31 23:06:48 +0000
@@ -3,10 +3,8 @@
 
 """Test Archive features."""
 
-from datetime import date, datetime, timedelta
-import unittest
+from datetime import date, timedelta
 
-import pytz
 import transaction
 
 from zope.component import getUtility
@@ -29,7 +27,8 @@
 from lp.services.worlddata.interfaces.country import ICountrySet
 from lp.soyuz.interfaces.archivearch import IArchiveArchSet
 from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
-from lp.soyuz.interfaces.binarypackagerelease import BinaryPackageFormat
+from lp.soyuz.interfaces.binarypackagerelease import (
+    BinaryPackageFileType, BinaryPackageFormat)
 from lp.soyuz.interfaces.component import IComponentSet
 from lp.soyuz.interfaces.processor import IProcessorFamilySet
 from lp.soyuz.interfaces.publishing import PackagePublishingStatus
@@ -42,118 +41,110 @@
 
 class TestGetPublicationsInArchive(TestCaseWithFactory):
 
-    layer = LaunchpadZopelessLayer
-
-    def setUp(self):
-        """Use `SoyuzTestPublisher` to publish some sources in archives."""
-        super(TestGetPublicationsInArchive, self).setUp()
-
-        self.distribution = getUtility(IDistributionSet)['ubuntutest']
-
-        # Create two PPAs for gedit.
-        self.archives = {}
-        self.archives['ubuntu-main'] = self.distribution.main_archive
-        self.archives['gedit-nightly'] = self.factory.makeArchive(
-            name="gedit-nightly", distribution=self.distribution)
-        self.archives['gedit-beta'] = self.factory.makeArchive(
-            name="gedit-beta", distribution=self.distribution)
-
-        self.publisher = SoyuzTestPublisher()
-        self.publisher.prepareBreezyAutotest()
-
-        # Publish gedit in all three archives, but with different
-        # upload dates.
-        self.gedit_nightly_src_hist = self.publisher.getPubSource(
-            sourcename="gedit", archive=self.archives['gedit-nightly'],
-            date_uploaded=datetime(2010, 12, 1, tzinfo=pytz.UTC),
-            status=PackagePublishingStatus.PUBLISHED)
-        self.gedit_beta_src_hist = self.publisher.getPubSource(
-            sourcename="gedit", archive=self.archives['gedit-beta'],
-            date_uploaded=datetime(2010, 11, 30, tzinfo=pytz.UTC),
-            status=PackagePublishingStatus.PUBLISHED)
-        self.gedit_main_src_hist = self.publisher.getPubSource(
-            sourcename="gedit", archive=self.archives['ubuntu-main'],
-            date_uploaded=datetime(2010, 12, 30, tzinfo=pytz.UTC),
-            status=PackagePublishingStatus.PUBLISHED)
-
-        # Save the archive utility for easy access, as well as the gedit
-        # source package name.
-        self.archive_set = getUtility(IArchiveSet)
-        spr = self.gedit_main_src_hist.sourcepackagerelease
-        self.gedit_name = spr.sourcepackagename
+    layer = DatabaseFunctionalLayer
+
+    def makeThreeArchivesOneDistribution(self):
+        distribution = self.factory.makeDistribution()
+        archives = []
+        for i in range(3):
+            archives.append(
+                self.factory.makeArchive(distribution=distribution))
+        return archives
+
+    def makeThreeArchivesWithPublications(self):
+        archives = self.makeThreeArchivesOneDistribution()
+        sourcepackagename = self.factory.makeSourcePackageName()
+        for archive in archives:
+            self.factory.makeSourcePackagePublishingHistory(
+                sourcepackagename=sourcepackagename, archive=archive,
+                status=PackagePublishingStatus.PUBLISHED,
+                )
+        return archives, sourcepackagename
+
+    def getPublications(self, sourcepackagename, archives, distribution):
+        return getUtility(IArchiveSet).getPublicationsInArchives(
+            sourcepackagename, archives, distribution=distribution)
 
     def testReturnsAllPublishedPublications(self):
         # Returns all currently published publications for archives
-        results = self.archive_set.getPublicationsInArchives(
-            self.gedit_name, self.archives.values(),
-            distribution=self.distribution)
+        archives, sourcepackagename = self.makeThreeArchivesWithPublications()
+        results = self.getPublications(
+            sourcepackagename, archives, archives[0].distribution)
         num_results = results.count()
-        self.assertEquals(3, num_results, "Expected 3 publications but "
-                                          "got %s" % num_results)
+        self.assertEquals(
+            3, num_results,
+            "Expected 3 publications but got %s" % num_results)
 
     def testEmptyListOfArchives(self):
         # Passing an empty list of archives will result in an empty
         # resultset.
-        results = self.archive_set.getPublicationsInArchives(
-            self.gedit_name, [], distribution=self.distribution)
+        archives, sourcepackagename = self.makeThreeArchivesWithPublications()
+        results = self.getPublications(
+            sourcepackagename, [], archives[0].distribution)
         self.assertEquals(0, results.count())
 
     def testReturnsOnlyPublicationsForGivenArchives(self):
         # Returns only publications for the specified archives
-        results = self.archive_set.getPublicationsInArchives(
-            self.gedit_name, [self.archives['gedit-beta']],
-            distribution=self.distribution)
+        archives, sourcepackagename = self.makeThreeArchivesWithPublications()
+        results = self.getPublications(
+            sourcepackagename, [archives[0]], archives[0].distribution)
         num_results = results.count()
-        self.assertEquals(1, num_results, "Expected 1 publication but "
-                                          "got %s" % num_results)
-        self.assertEquals(self.archives['gedit-beta'],
-                          results[0].archive,
-                          "Expected publication from %s but was instead "
-                          "from %s." % (
-                              self.archives['gedit-beta'].displayname,
-                              results[0].archive.displayname))
+        self.assertEquals(
+            1, num_results,
+            "Expected 1 publication but got %s" % num_results)
+        self.assertEquals(
+            archives[0], results[0].archive,
+            "Expected publication from %s but was instead from %s." % (
+                archives[0].displayname, results[0].archive.displayname))
 
     def testReturnsOnlyPublishedPublications(self):
         # Publications that are not published will not be returned.
-        secure_src_hist = self.gedit_beta_src_hist
-        secure_src_hist.status = PackagePublishingStatus.PENDING
-
-        results = self.archive_set.getPublicationsInArchives(
-            self.gedit_name, [self.archives['gedit-beta']],
-            distribution=self.distribution)
+        archive = self.factory.makeArchive()
+        sourcepackagename = self.factory.makeSourcePackageName()
+        self.factory.makeSourcePackagePublishingHistory(
+            archive=archive, sourcepackagename=sourcepackagename,
+            status=PackagePublishingStatus.PENDING)
+        results = self.getPublications(
+            sourcepackagename, [archive], archive.distribution)
         num_results = results.count()
         self.assertEquals(0, num_results, "Expected 0 publication but "
                                           "got %s" % num_results)
 
     def testPubsForSpecificDistro(self):
         # Results can be filtered for specific distributions.
-
-        # Add a publication in the ubuntu distribution
-        ubuntu = getUtility(IDistributionSet)['ubuntu']
-        warty = ubuntu['warty']
-        gedit_main_src_hist = self.publisher.getPubSource(
-            sourcename="gedit",
-            archive=self.archives['ubuntu-main'],
-            distroseries=warty,
-            date_uploaded=datetime(2010, 12, 30, tzinfo=pytz.UTC),
-            status=PackagePublishingStatus.PUBLISHED)
-
-        # Only the 3 results for ubuntutest are returned when requested:
-        results = self.archive_set.getPublicationsInArchives(
-            self.gedit_name, self.archives.values(),
-            distribution=self.distribution)
-        num_results = results.count()
-        self.assertEquals(3, num_results, "Expected 3 publications but "
-                                          "got %s" % num_results)
-
-        # Similarly, requesting the ubuntu publications only returns the
-        # one we created:
-        results = self.archive_set.getPublicationsInArchives(
-            self.gedit_name, self.archives.values(),
-            distribution=ubuntu)
-        num_results = results.count()
-        self.assertEquals(1, num_results, "Expected 1 publication but "
-                                          "got %s" % num_results)
+        sourcepackagename = self.factory.makeSourcePackageName()
+
+        distribution = self.factory.makeDistribution()
+        distroseries = self.factory.makeDistroSeries(
+            distribution=distribution)
+        archive = self.factory.makeArchive(distribution=distribution)
+        self.factory.makeSourcePackagePublishingHistory(
+            archive=archive, sourcepackagename=sourcepackagename,
+            distroseries=distroseries,
+            status=PackagePublishingStatus.PUBLISHED)
+
+        other_distribution = self.factory.makeDistribution()
+        other_distroseries = self.factory.makeDistroSeries(
+            distribution=other_distribution)
+        other_archive = self.factory.makeArchive(
+            distribution=other_distribution)
+        self.factory.makeSourcePackagePublishingHistory(
+            archive=other_archive, sourcepackagename=sourcepackagename,
+            distroseries=other_distroseries,
+            status=PackagePublishingStatus.PUBLISHED)
+
+        # We don't get the results for other_distribution
+        results = self.getPublications(
+            sourcepackagename, [archive, other_archive],
+            distribution=distribution)
+        num_results = results.count()
+        self.assertEquals(
+            1, num_results,
+            "Expected 1 publication but got %s" % num_results)
+        self.assertEquals(
+            archive, results[0].archive,
+            "Expected publication from %s but was instead from %s." % (
+                archive.displayname, results[0].archive.displayname))
 
 
 class TestArchiveRepositorySize(TestCaseWithFactory):
@@ -167,60 +158,59 @@
         self.ppa = self.factory.makeArchive(
             name="testing", distribution=self.publisher.ubuntutest)
 
+    def publish_ddeb_in_archive(self, archive):
+        binarypackagerelease = self.factory.makeBinaryPackageRelease(
+            binpackageformat=BinaryPackageFormat.DDEB)
+        self.factory.makeBinaryPackagePublishingHistory(
+            archive=archive, binarypackagerelease=binarypackagerelease,
+            status=PackagePublishingStatus.PUBLISHED)
+        self.factory.makeBinaryPackageFile(
+            binarypackagerelease=binarypackagerelease,
+            filetype=BinaryPackageFileType.DDEB)
+
     def test_binaries_size_does_not_include_ddebs_for_ppas(self):
         # DDEBs are not computed in the PPA binaries size because
         # they are not being published. See bug #399444.
-        self.assertEquals(0, self.ppa.binaries_size)
-        self.publisher.getPubBinaries(
-            filecontent='X', format=BinaryPackageFormat.DDEB,
-            archive=self.ppa)
-        self.assertEquals(0, self.ppa.binaries_size)
+        ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
+        self.assertEquals(0, ppa.binaries_size)
+        self.publish_ddeb_in_archive(ppa)
+        self.assertEquals(0, ppa.binaries_size)
 
     def test_binaries_size_includes_ddebs_for_other_archives(self):
         # DDEBs size are computed for all archive purposes, except PPAs.
-        previous_size = self.publisher.ubuntutest.main_archive.binaries_size
-        self.publisher.getPubBinaries(
-            filecontent='X', format=BinaryPackageFormat.DDEB)
-        self.assertEquals(
-            previous_size + 1,
-            self.publisher.ubuntutest.main_archive.binaries_size)
+        archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
+        self.assertEquals(0, archive.binaries_size)
+        self.publish_ddeb_in_archive(archive)
+        self.assertNotEquals(0, archive.binaries_size)
 
     def test_sources_size_on_empty_archive(self):
         # Zero is returned for an archive without sources.
+        archive = self.factory.makeArchive()
         self.assertEquals(
-            0, self.ppa.sources_size,
+            0, archive.sources_size,
             'Zero should be returned for an archive without sources.')
 
+    def publish_source_file(self, archive, libraryfile):
+        sourcepackagerelease = self.factory.makeSourcePackageRelease()
+        self.factory.makeSourcePackagePublishingHistory(
+            archive=archive, sourcepackagerelease=sourcepackagerelease,
+            status=PackagePublishingStatus.PUBLISHED)
+        self.factory.makeSourcePackageReleaseFile(
+            sourcepackagerelease=sourcepackagerelease,
+            libraryfile=libraryfile)
+
     def test_sources_size_does_not_count_duplicated_files(self):
         # If there are multiple copies of the same file name/size
         # only one will be counted.
-        pub_1 = self.publisher.getPubSource(
-            filecontent='22', version='0.5.11~ppa1', archive=self.ppa)
-
-        pub_2 = self.publisher.getPubSource(
-            filecontent='333', version='0.5.11~ppa2', archive=self.ppa)
-
-        self.assertEquals(5, self.ppa.sources_size)
-
-        shared_tarball = self.publisher.addMockFile(
-            filename='foo_0.5.11.tar.gz', filecontent='1')
-
-        # After adding a the shared tarball to the ppa1 version,
-        # the sources_size updates to reflect the change.
-        pub_1.sourcepackagerelease.addFile(shared_tarball)
-        self.assertEquals(
-            6, self.ppa.sources_size,
-            'The sources_size should update after a file is added.')
-
-        # But after adding a copy of the shared tarball to the ppa2 version,
-        # the sources_size is unchanged.
-        shared_tarball_copy = self.publisher.addMockFile(
-            filename='foo_0.5.11.tar.gz', filecontent='1')
-
-        pub_2.sourcepackagerelease.addFile(shared_tarball_copy)
-        self.assertEquals(
-            6, self.ppa.sources_size,
-            'The sources_size should change after adding a duplicate file.')
+        archive = self.factory.makeArchive()
+        libraryfile = self.factory.makeLibraryFileAlias()
+        self.publish_source_file(archive, libraryfile)
+        self.assertEquals(
+            libraryfile.content.filesize, archive.sources_size)
+
+        self.publish_source_file(archive, libraryfile)
+        self.assertEquals(
+            libraryfile.content.filesize, archive.sources_size)
 
 
 class TestSeriesWithSources(TestCaseWithFactory):

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2010-07-30 20:33:47 +0000
+++ lib/lp/testing/factory.py	2010-07-31 23:06:48 +0000
@@ -128,7 +128,7 @@
 from lp.registry.interfaces.projectgroup import IProjectGroupSet
 from lp.registry.interfaces.series import SeriesStatus
 from lp.registry.interfaces.sourcepackage import (
-    ISourcePackage, SourcePackageUrgency)
+    ISourcePackage, SourcePackageFileType, SourcePackageUrgency)
 from lp.registry.interfaces.sourcepackagename import (
     ISourcePackageNameSet)
 from lp.registry.interfaces.ssh import ISSHKeySet
@@ -146,18 +146,20 @@
 from lp.soyuz.interfaces.archive import (
     default_name_by_purpose, IArchiveSet, ArchivePurpose)
 from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
-from lp.soyuz.interfaces.binarypackagerelease import BinaryPackageFormat
+from lp.soyuz.interfaces.binarypackagerelease import (
+    BinaryPackageFileType, BinaryPackageFormat)
 from lp.soyuz.interfaces.component import IComponentSet
 from lp.soyuz.interfaces.packageset import IPackagesetSet
 from lp.soyuz.interfaces.processor import IProcessorFamilySet
 from lp.soyuz.interfaces.publishing import (
-    PackagePublishingPriority, PackagePublishingStatus)
+    IPublishingSet, PackagePublishingPriority, PackagePublishingStatus)
 from lp.soyuz.interfaces.section import ISectionSet
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
+from lp.soyuz.model.files import BinaryPackageFile, SourcePackageReleaseFile
 from lp.soyuz.model.processor import ProcessorFamilySet
 from lp.soyuz.model.publishing import (
-    BinaryPackagePublishingHistory, SourcePackagePublishingHistory)
+    SourcePackagePublishingHistory)
 from lp.testing import (
     ANONYMOUS,
     login,
@@ -2338,6 +2340,19 @@
             dateuploaded=date_uploaded,
             source_package_recipe_build=source_package_recipe_build)
 
+    def makeSourcePackageReleaseFile(self, sourcepackagerelease=None,
+                                     libraryfile=None, filetype=None):
+        if sourcepackagerelease is None:
+            sourcepackagerelease = self.makeSourcePackageRelease()
+        if libraryfile is None:
+            libraryfile = self.makeLibraryFileAlias()
+        if filetype is None:
+            filetype = SourcePackageFileType.DSC
+        return ProxyFactory(
+            SourcePackageReleaseFile(
+                sourcepackagerelease=sourcepackagerelease,
+                libraryfile=libraryfile, filetype=filetype))
+
     def makeBinaryPackageBuild(self, source_package_release=None,
             distroarchseries=None, archive=None, builder=None):
         """Create a BinaryPackageBuild.
@@ -2399,6 +2414,7 @@
                                            dsc_standards_version='3.6.2',
                                            dsc_format='1.0',
                                            dsc_binaries='foo-bin',
+                                           sourcepackagerelease=None,
                                            ):
         """Make a `SourcePackagePublishingHistory`."""
         if distroseries is None:
@@ -2419,40 +2435,38 @@
         if status is None:
             status = PackagePublishingStatus.PENDING
 
-        spr = self.makeSourcePackageRelease(
-            archive=archive,
-            sourcepackagename=sourcepackagename,
-            distroseries=distroseries,
-            maintainer=maintainer,
-            creator=creator, component=component,
-            section_name=section_name,
-            urgency=urgency,
-            version=version,
-            builddepends=builddepends,
-            builddependsindep=builddependsindep,
-            build_conflicts=build_conflicts,
-            build_conflicts_indep=build_conflicts_indep,
-            architecturehintlist=architecturehintlist,
-            dsc_standards_version=dsc_standards_version,
-            dsc_format=dsc_format,
-            dsc_binaries=dsc_binaries,
-            date_uploaded=date_uploaded)
-
-        sspph = SourcePackagePublishingHistory(
-            distroseries=distroseries,
-            sourcepackagerelease=spr,
-            component=spr.component,
-            section=spr.section,
-            status=status,
-            datecreated=date_uploaded,
-            dateremoved=dateremoved,
-            scheduleddeletiondate=scheduleddeletiondate,
-            pocket=pocket,
-            archive=archive)
-
-        # SPPH and SSPPH IDs are the same, since they are SPPH is a SQLVIEW
-        # of SSPPH and other useful attributes.
-        return SourcePackagePublishingHistory.get(sspph.id)
+        if sourcepackagerelease is None:
+            sourcepackagerelease = self.makeSourcePackageRelease(
+                archive=archive,
+                sourcepackagename=sourcepackagename,
+                distroseries=distroseries,
+                maintainer=maintainer,
+                creator=creator, component=component,
+                section_name=section_name,
+                urgency=urgency,
+                version=version,
+                builddepends=builddepends,
+                builddependsindep=builddependsindep,
+                build_conflicts=build_conflicts,
+                build_conflicts_indep=build_conflicts_indep,
+                architecturehintlist=architecturehintlist,
+                dsc_standards_version=dsc_standards_version,
+                dsc_format=dsc_format,
+                dsc_binaries=dsc_binaries,
+                date_uploaded=date_uploaded)
+
+        return ProxyFactory(
+            SourcePackagePublishingHistory(
+                distroseries=distroseries,
+                sourcepackagerelease=sourcepackagerelease,
+                component=sourcepackagerelease.component,
+                section=sourcepackagerelease.section,
+                status=status,
+                datecreated=date_uploaded,
+                dateremoved=dateremoved,
+                scheduleddeletiondate=scheduleddeletiondate,
+                pocket=pocket,
+                archive=archive))
 
     def makeBinaryPackagePublishingHistory(self, binarypackagerelease=None,
                                            distroarchseries=None,
@@ -2485,28 +2499,40 @@
         if priority is None:
             priority = PackagePublishingPriority.OPTIONAL
 
-        bpr = self.makeBinaryPackageRelease(
-            component=component,
-            section_name=section_name,
-            priority=priority)
+        if binarypackagerelease is None:
+            binarypackagerelease = self.makeBinaryPackageRelease(
+                component=component,
+                section_name=section_name,
+                priority=priority)
 
-        return BinaryPackagePublishingHistory(
-            distroarchseries=distroarchseries,
-            binarypackagerelease=bpr,
-            component=bpr.component,
-            section=bpr.section,
-            status=status,
-            dateremoved=dateremoved,
-            scheduleddeletiondate=scheduleddeletiondate,
-            pocket=pocket,
-            priority=priority,
-            archive=archive)
+        bpph = getUtility(IPublishingSet).newBinaryPublication(
+            archive, binarypackagerelease, distroarchseries,
+            binarypackagerelease.component, binarypackagerelease.section,
+            priority, pocket)
+        naked_bpph = removeSecurityProxy(bpph)
+        naked_bpph.status = status
+        naked_bpph.dateremoved = dateremoved
+        naked_bpph.scheduleddeletiondate = scheduleddeletiondate
+        naked_bpph.priority = priority
+        return bpph
 
     def makeBinaryPackageName(self, name=None):
         if name is None:
             name = self.getUniqueString("binarypackage")
         return BinaryPackageName(name=name)
 
+    def makeBinaryPackageFile(self, binarypackagerelease=None,
+                              libraryfile=None, filetype=None):
+        if binarypackagerelease is None:
+            binarypackagerelease = self.makeBinaryPackageRelease()
+        if libraryfile is None:
+            libraryfile = self.makeLibraryFileAlias()
+        if filetype is None:
+            filetype = BinaryPackageFileType.DEB
+        return ProxyFactory(BinaryPackageFile(
+            binarypackagerelease=binarypackagerelease,
+            libraryfile=libraryfile, filetype=filetype))
+
     def makeBinaryPackageRelease(self, binarypackagename=None,
                                  version=None, build=None,
                                  binpackageformat=None, component=None,
@@ -2531,13 +2557,13 @@
             summary = self.getUniqueString("summary")
         if description is None:
             description = self.getUniqueString("description")
-        return BinaryPackageRelease(binarypackagename=binarypackagename,
-                                    version=version, build=build,
-                                    binpackageformat=binpackageformat,
-                                    component=component, section=section,
-                                    priority=priority, summary=summary,
-                                    description=description,
-                                    architecturespecific=architecturespecific)
+        return ProxyFactory(
+            BinaryPackageRelease(
+                binarypackagename=binarypackagename, version=version,
+                build=build, binpackageformat=binpackageformat,
+                component=component, section=section, priority=priority,
+                summary=summary, description=description,
+                architecturespecific=architecturespecific))
 
     def makeSection(self, name=None):
         """Make a `Section`."""

=== modified file 'lib/lp/testing/sampledata.py'
--- lib/lp/testing/sampledata.py	2010-07-17 15:52:19 +0000
+++ lib/lp/testing/sampledata.py	2010-07-31 23:06:48 +0000
@@ -9,8 +9,35 @@
 
 __metaclass__ = type
 __all__ = [
+    'CHROOT_LFA',
+    'CPROV_NAME',
+    'HOARY_DISTROSERIES_NAME',
+    'I386_ARCHITECTURE_NAME',
+    'LAUNCHPAD_DBUSER_NAME',
+    'MAIN_COMPONENT_NAME',
+    'MOZILLA_FIREFOX_SOURCEPACKAGENAME',
+    'MOZILLA_FIREFOX_SOURCEPACKAGEVERSION',
+    'NAME16_PERSON_NAME',
     'NO_PRIVILEGE_EMAIL',
+    'UBUNTU_DISTRIBUTION_NAME',
+    'UBUNTU_TEAM_NAME',
+    'UBUNTUTEST_DISTRIBUTION_NAME',
+    'WARTY_DISTROSERIES_NAME',
+    'WARTY_UPDATES_SUITE_NAME',
     ]
 
 
+CHROOT_LFA = 1
+CPROV_NAME = 'cprov'
+HOARY_DISTROSERIES_NAME = 'hoary'
+I386_ARCHITECTURE_NAME = 'i386'
+LAUNCHPAD_DBUSER_NAME = 'launchpad'
+MAIN_COMPONENT_NAME = 'main'
+MOZILLA_FIREFOX_SOURCEPACKAGENAME = 'mozilla-firefox'
+MOZILLA_FIREFOX_SOURCEPACKAGEVERSION = '0.9'
+NAME16_PERSON_NAME = 'name16'
 NO_PRIVILEGE_EMAIL = 'no-priv@xxxxxxxxxxxxx'
+UBUNTU_DISTRIBUTION_NAME = 'ubuntu'
+UBUNTU_TEAM_NAME = 'ubuntu-team'
+WARTY_DISTROSERIES_NAME = 'warty'
+WARTY_UPDATES_SUITE_NAME = WARTY_DISTROSERIES_NAME + '-updates'


Follow ups