← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/launchpad/missing-test-bug-793607 into lp:launchpad

 

Raphaël Victor Badin has proposed merging lp:~rvb/launchpad/missing-test-bug-793607 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #793607 in Launchpad itself: "Missing test: the user 'uploading' should be able to SELECT on DSP."
  https://bugs.launchpad.net/launchpad/+bug/793607

For more details, see:
https://code.launchpad.net/~rvb/launchpad/missing-test-bug-793607/+merge/71727

This branch main goal is to fix tests in lib/lp/archiveuploader/tests/test_uploadprocessor.py so that they also trigger the creation of DSDJs and thus make sure that the user 'uploader' has the right to access the table DistroSeriesParent. This is done by setting the feature flag to allow the DSDJ creation code to kick in. The reason we decided to modify existing tests instead of adding new ones is that the tests in the upload processor are: 1) expensive, 2) hard to set up.

While doing this, we discovered that the tests in test_uploadprocessor.py where not ran as the user 'uploader' so this branch is also fixing this: it fixes the setUp method to switch to the right user (and switches back to launchpad_main when we need to setup data).

= Test =

(modified tests)
./bin/test -vvc test_uploadprocessor

= Q/A =

None.
-- 
https://code.launchpad.net/~rvb/launchpad/missing-test-bug-793607/+merge/71727
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/launchpad/missing-test-bug-793607 into lp:launchpad.
=== modified file 'lib/lp/archiveuploader/tests/test_uploadprocessor.py'
--- lib/lp/archiveuploader/tests/test_uploadprocessor.py	2011-08-12 20:54:19 +0000
+++ lib/lp/archiveuploader/tests/test_uploadprocessor.py	2011-08-16 16:10:28 +0000
@@ -16,6 +16,7 @@
 import tempfile
 
 from storm.locals import Store
+import transaction
 from zope.component import (
     getGlobalSiteManager,
     getUtility,
@@ -53,6 +54,7 @@
 from lp.registry.interfaces.sourcepackage import SourcePackageFileType
 from lp.registry.interfaces.sourcepackagename import ISourcePackageNameSet
 from lp.registry.model.sourcepackagename import SourcePackageName
+from lp.services.features.testing import FeatureFixture
 from lp.services.log.logger import BufferLogger
 from lp.services.mail import stub
 from lp.soyuz.enums import (
@@ -73,6 +75,7 @@
 from lp.soyuz.interfaces.sourcepackageformat import (
     ISourcePackageFormatSelectionSet,
     )
+from lp.soyuz.model import distroseriesdifferencejob
 from lp.soyuz.model.archivepermission import ArchivePermission
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
@@ -114,6 +117,14 @@
     """Base class for functional tests over uploadprocessor.py."""
     layer = LaunchpadZopelessLayer
 
+    def useUploader(self):
+        transaction.commit()
+        self.layer.switchDbUser("uploader")
+
+    def useMainUser(self):
+        transaction.commit()
+        self.layer.switchDbUser("launchpad_main")
+
     def setUp(self):
         super(TestUploadProcessorBase, self).setUp()
 
@@ -142,11 +153,19 @@
 
         self.log = BufferLogger()
 
+        self.useFixture(FeatureFixture({
+            distroseriesdifferencejob.FEATURE_FLAG_ENABLE_MODULE: u'on',
+        }))
+
+        self.useUploader()
+
     def tearDown(self):
         shutil.rmtree(self.queue_folder)
+        self.useMainUser()
         super(TestUploadProcessorBase, self).tearDown()
 
     def getUploadProcessor(self, txn, builds=None):
+        self.useMainUser()
         if builds is None:
             builds = self.options.builds
 
@@ -160,13 +179,17 @@
             policy.setOptions(self.options)
             return policy
 
-        return UploadProcessor(
+        upload_processor = UploadProcessor(
             self.options.base_fsroot, self.options.dryrun,
             self.options.nomails, builds, self.options.keep, getPolicy, txn,
             self.log)
+        self.useUploader()
+        return upload_processor
 
     def publishPackage(self, packagename, version, source=True, archive=None):
         """Publish a single package that is currently NEW in the queue."""
+        self.useMainUser()
+
         packagename = unicode(packagename)
         if version is not None:
             version = unicode(version)
@@ -180,6 +203,7 @@
             pubrec = queue_item.sources[0].publish(self.log)
         else:
             pubrec = queue_item.builds[0].publish(self.log)
+        self.useUploader()
         return pubrec
 
     def assertLogContains(self, line):
@@ -222,6 +246,8 @@
         :param permitted_formats: list of SourcePackageFormats to allow
             in the new distroseries. Only permits '1.0' by default.
         """
+        self.useMainUser()
+
         self.ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
         bat = self.ubuntu['breezy-autotest']
         self.breezy = self.ubuntu.newSeries(
@@ -245,6 +271,8 @@
                 getUtility(ISourcePackageFormatSelectionSet).add(
                     self.breezy, format)
 
+        self.useUploader()
+
     def addMockFile(self, filename, content="anything"):
         """Return a librarian file."""
         return getUtility(ILibraryFileAliasSet).create(
@@ -295,10 +323,13 @@
     def setupBreezyAndGetUploadProcessor(self, policy=None):
         """Setup Breezy and return an upload processor for it."""
         self.setupBreezy()
+        self.useMainUser()
         self.layer.txn.commit()
         if policy is not None:
             self.options.context = policy
-        return self.getUploadProcessor(self.layer.txn)
+        upload_processor = self.getUploadProcessor(self.layer.txn)
+        self.useUploader()
+        return upload_processor
 
     def assertEmail(self, contents=None, recipients=None):
         """Check last email content and recipients.
@@ -592,6 +623,7 @@
         # Accept and publish the upload.
         # This is required so that the next upload of a later version of
         # the same package will work correctly.
+        self.useMainUser()
         queue_items = self.breezy.getPackageUploads(
             status=PackageUploadStatus.NEW, name=u"bar",
             version=u"1.0-1", exact_match=True)
@@ -607,6 +639,7 @@
         # existing package will be allowed, but unapproved.
         self.breezy.status = SeriesStatus.FROZEN
         self.layer.txn.commit()
+        self.useUploader()
 
         # Upload a newer version of bar.
         upload_dir = self.queueUpload("bar_1.0-2")
@@ -672,9 +705,11 @@
         bar_bin_pubs = self.publishPackage('bar', '1.0-1', source=False)
         # Mangle its publishing component to "restricted" so we can check
         # the copy archive ancestry override later.
+        self.useMainUser()
         restricted = getUtility(IComponentSet)["restricted"]
         for pub in bar_bin_pubs:
             pub.component = restricted
+        self.useUploader()
 
         # Create a COPY archive for building in non-virtual builds.
         uploader = getUtility(IPersonSet).getByName('name16')
@@ -716,9 +751,11 @@
 
         # The copy archive binary published component should have been
         # inherited from the main archive's.
+        self.useMainUser()
         copy_bin_pubs = queue_items[0].realiseUpload()
         for pub in copy_bin_pubs:
             self.assertEqual(pub.component.name, restricted.name)
+        self.useUploader()
 
     def testCopyArchiveUploadToCurrentDistro(self):
         """Check binary copy archive uploads to RELEASE pockets.
@@ -774,12 +811,14 @@
         [bar_binary_pub] = self.publishPackage("bar", "1.0-1", source=False)
 
         # Prepare ubuntu/breezy-autotest to build sources in i386.
+        self.useMainUser()
         breezy_autotest = self.ubuntu['breezy-autotest']
         breezy_autotest_i386 = breezy_autotest['i386']
         breezy_autotest.nominatedarchindep = breezy_autotest_i386
         fake_chroot = self.addMockFile('fake_chroot.tar.gz')
         breezy_autotest_i386.addOrUpdateChroot(fake_chroot)
         self.layer.txn.commit()
+        self.useUploader()
 
         # Copy 'bar-1.0-1' source from breezy to breezy-autotest and
         # create a build there (this would never happen in reality, it
@@ -1186,6 +1225,7 @@
         # Housekeeping so the next test won't fail.
         shutil.rmtree(upload_dir)
 
+
     def disabled_per_bug_825486_testPartnerUploadToNonReleaseOrProposedPocket(self):
         # XXX: bug 825486 robertcollins 2011-08-13 this test is broken.
         """Test partner upload pockets.
@@ -1195,7 +1235,6 @@
         self.setupBreezy()
 
         # Check unstable states:
-
         self.breezy.status = SeriesStatus.DEVELOPMENT
         self.layer.txn.commit()
         self._uploadPartnerToNonReleasePocketAndCheckFail()
@@ -1456,6 +1495,7 @@
         # permissions to all components at upload time.
         uploader = getUtility(IPersonSet).getByName('name16')
         distro_team = getUtility(IPersonSet).getByName('ubuntu-team')
+        self.useMainUser()
         uploader.leave(distro_team)
 
         # Now give name16 specific permissions to "restricted" only.
@@ -1464,6 +1504,7 @@
             archive=self.ubuntu.main_archive,
             permission=ArchivePermissionType.UPLOAD, person=uploader,
             component=restricted)
+        self.useUploader()
 
         uploadprocessor = self.getUploadProcessor(self.layer.txn)
 
@@ -1486,11 +1527,13 @@
             u"Signer is not permitted to upload to the component 'universe'.")
 
         # Now add permission to upload "bar" for name16.
+        self.useMainUser()
         bar_package = getUtility(ISourcePackageNameSet).queryByName("bar")
         ArchivePermission(
             archive=self.ubuntu.main_archive,
             permission=ArchivePermissionType.UPLOAD, person=uploader,
             sourcepackagename=bar_package)
+        self.useUploader()
 
         # Upload the package again.
         self.processUpload(uploadprocessor, upload_dir)
@@ -1508,6 +1551,7 @@
         # permissions to all components at upload time.
         uploader = getUtility(IPersonSet).getByName('name16')
         distro_team = getUtility(IPersonSet).getByName('ubuntu-team')
+        self.useMainUser()
         uploader.leave(distro_team)
 
         # Now give name16 specific permissions to "restricted" only.
@@ -1516,6 +1560,7 @@
             archive=self.ubuntu.main_archive,
             permission=ArchivePermissionType.UPLOAD, person=uploader,
             component=restricted)
+        self.useUploader()
 
         uploadprocessor = self.getUploadProcessor(self.layer.txn)
 
@@ -1539,6 +1584,7 @@
 
         # Now put in place a package set, add 'bar' to it and define a
         # permission for the former.
+        self.useMainUser()
         bar_package = getUtility(ISourcePackageNameSet).queryByName("bar")
         ap_set = getUtility(IArchivePermissionSet)
         ps_set = getUtility(IPackagesetSet)
@@ -1550,6 +1596,7 @@
         foo_ps.add((bar_package, ))
         ap_set.newPackagesetUploader(
             self.ubuntu.main_archive, uploader, foo_ps)
+        self.useUploader()
 
         # The uploader now does have a package set based upload permissions
         # to 'bar' in 'grumpy' but not in 'breezy'.
@@ -1571,12 +1618,14 @@
             msg['Subject'], 'bar_1.0-2_source.changes rejected')
 
         # Grant the permissions in the proper series.
+        self.useMainUser()
         breezy_ps = ps_set.new(
             u'foo-pkg-set-breezy', u'Packages that require special care.',
             uploader, distroseries=self.breezy)
         breezy_ps.add((bar_package, ))
         ap_set.newPackagesetUploader(
             self.ubuntu.main_archive, uploader, breezy_ps)
+        self.useUploader()
         # The uploader now does have a package set based upload permission
         # to 'bar' in 'breezy'.
         self.assertTrue(
@@ -1817,6 +1866,7 @@
             status=PackageUploadStatus.NEW, name=u"bar",
             version=u"1.0-1", exact_match=True)
         self.assertEqual(queue_items.count(), 1)
+        self.useMainUser()
         queue_item = queue_items[0]
         queue_item.setAccepted()
         pubrec = queue_item.sources[0].publish(self.log)
@@ -1824,6 +1874,7 @@
         pubrec.datepublished = UTC_NOW
         queue_item.setDone()
         self.PGPSignatureNotPreserved(archive=self.breezy.main_archive)
+        self.useUploader()
 
 
 class TestBuildUploadProcessor(TestUploadProcessorBase):
@@ -1873,6 +1924,7 @@
         [build] = source_pub.createMissingBuilds()
 
         # Move the source from the accepted queue.
+        self.useMainUser()
         [queue_item] = self.breezy.getPackageUploads(
             status=PackageUploadStatus.ACCEPTED,
             version=u"1.0-1", name=u"bar")
@@ -1884,6 +1936,7 @@
 
         build.status = BuildStatus.UPLOADING
         build.date_finished = UTC_NOW
+        self.useUploader()
 
         # Upload and accept a binary for the primary archive source.
         shutil.rmtree(upload_dir)
@@ -1917,14 +1970,15 @@
         [build] = source_pub.createMissingBuilds()
 
         # Move the source from the accepted queue.
+        self.useMainUser()
         [queue_item] = self.breezy.getPackageUploads(
             status=PackageUploadStatus.ACCEPTED,
             version=u"1.0-1", name=u"bar")
         queue_item.setDone()
 
         build.buildqueue_record.markAsBuilding(self.factory.makeBuilder())
-
         build.status = BuildStatus.UPLOADING
+        self.useUploader()
 
         # Upload and accept a binary for the primary archive source.
         shutil.rmtree(upload_dir)
@@ -1948,6 +2002,7 @@
 
     def doSuccessRecipeBuild(self):
         # Upload a source package
+        self.useMainUser()
         archive = self.factory.makeArchive()
         archive.require_virtualized = False
         build = self.factory.makeSourcePackageRecipeBuild(sourcename=u"bar",
@@ -1955,6 +2010,7 @@
             requester=archive.owner)
         self.assertEquals(archive.owner, build.requester)
         self.factory.makeSourcePackageRecipeBuildJob(recipe_build=build)
+        self.useUploader()
         # Commit so the build cookie has the right ids.
         self.layer.txn.commit()
         leaf_name = build.getUploadDirLeaf(build.getBuildCookie())
@@ -1998,6 +2054,7 @@
         # A source package recipe build will fail if no files are present.
 
         # Upload a source package
+        self.useMainUser()
         archive = self.factory.makeArchive()
         archive.require_virtualized = False
         build = self.factory.makeSourcePackageRecipeBuild(sourcename=u"bar",
@@ -2010,6 +2067,7 @@
         self.options.context = 'buildd'
         self.options.builds = True
         build.jobStarted()
+        self.useUploader()
         # Commit so date_started is recorded and doesn't cause constraint
         # violations later.
         Store.of(build).flush()
@@ -2040,11 +2098,13 @@
         # A source package recipe build will fail if the recipe is deleted.
 
         # Upload a source package
+        self.useMainUser()
         archive = self.factory.makeArchive()
         archive.require_virtualized = False
         build = self.factory.makeSourcePackageRecipeBuild(sourcename=u"bar",
             distroseries=self.breezy, archive=archive)
         self.factory.makeSourcePackageRecipeBuildJob(recipe_build=build)
+        self.useUploader()
         # Commit so the build cookie has the right ids.
         Store.of(build).flush()
         leaf_name = build.getUploadDirLeaf(build.getBuildCookie())
@@ -2052,7 +2112,9 @@
         self.options.context = 'buildd'
         self.options.builds = True
         build.jobStarted()
+        self.useMainUser()
         build.recipe.destroySelf()
+        self.useUploader()
         # Commit so date_started is recorded and doesn't cause constraint
         # violations later.
         Store.of(build).flush()
@@ -2079,6 +2141,7 @@
         [build] = source_pub.createMissingBuilds()
 
         # Move the source from the accepted queue.
+        self.useMainUser()
         [queue_item] = self.breezy.getPackageUploads(
             status=PackageUploadStatus.ACCEPTED,
             version=u"1.0-1", name=u"bar")
@@ -2086,6 +2149,7 @@
 
         build.buildqueue_record.markAsBuilding(self.factory.makeBuilder())
         build.status = BuildStatus.BUILDING
+        self.useUploader()
 
         shutil.rmtree(upload_dir)