← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/better-publisher-index-tests into lp:launchpad/devel

 

William Grant has proposed merging lp:~wgrant/launchpad/better-publisher-index-tests into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


Soyuz's two index publication methods (apt-ftparchive and native) perform the same function, so logically should share tests. This branch starts to reduce duplication in test_publisher by running the same tests over both methods.

It also adds a new test that more thoroughly verifies that the right indices are created.
-- 
https://code.launchpad.net/~wgrant/launchpad/better-publisher-index-tests/+merge/38462
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/better-publisher-index-tests into lp:launchpad/devel.
=== modified file 'lib/lp/archivepublisher/tests/test_publisher.py'
--- lib/lp/archivepublisher/tests/test_publisher.py	2010-10-07 13:44:47 +0000
+++ lib/lp/archivepublisher/tests/test_publisher.py	2010-10-14 21:26:11 +0000
@@ -1081,94 +1081,129 @@
         # The Label: field should be set to the archive displayname
         self.assertEqual(release_contents[1], 'Label: Partner archive')
 
-    def assertIndicesForArchitectures(self, publisher, present, absent):
-        """Assert that the correct set of archs has indices.
+
+class TestArchiveIndices(TestPublisherBase):
+    """Tests for the native publisher's index generation.
+
+    Verifies that all Packages/Sources/Release files are generated when
+    appropriate.
+    """
+
+    def runStepC(self, publisher):
+        """Run the index generation step of the publisher."""
+        publisher.C_writeIndexes(False)
+
+    def assertIndices(self, publisher, suites, present=[], absent=[]):
+        """Assert that the given suites have correct indices."""
+        for series, pocket in suites:
+            self.assertIndicesForSuite(
+                publisher, series, pocket, present, absent)
+
+    def assertIndicesForSuite(self, publisher, series, pocket,
+                              present=[], absent=[]):
+        """Assert that the suite has correct indices.
 
         Checks that the architecture tags in 'present' have Packages and
         Release files and are in the series' Release file, and confirms
         that those in 'absent' are not.
         """
 
-        self.checkAllRequestedReleaseFiles(
-            publisher, architecturetags=present)
+        self.assertTrue(
+            series.getSuite(pocket) in
+            publisher.apt_handler.release_files_needed)
 
         arch_template = os.path.join(
-            publisher._config.distsroot, 'breezy-autotest/main/binary-%s')
+            publisher._config.distsroot, series.getSuite(pocket), '%s/%s')
+
         release_template = os.path.join(arch_template, 'Release')
         packages_template = os.path.join(arch_template, 'Packages')
+        sources_template = os.path.join(arch_template, 'Sources')
         release_content = open(os.path.join(
-            publisher._config.distsroot,
-            'breezy-autotest/Release')).read()
-
-        for arch in present:
-            self.assertTrue(os.path.exists(arch_template % arch))
-            self.assertTrue(os.path.exists(release_template % arch))
-            self.assertTrue(os.path.exists(packages_template % arch))
-            self.assertTrue(arch in release_content)
-
-        for arch in absent:
-            self.assertFalse(os.path.exists(arch_template % arch))
-            self.assertFalse(arch in release_content)
-
-    def testNativeNoIndicesForDisabledArchitectures(self):
-        """Test that no indices are created for disabled archs."""
-        self.getPubBinaries()
-
-        ds = self.ubuntutest.getSeries('breezy-autotest')
-        ds.getDistroArchSeries('i386').enabled = False
-        self.config = Config(self.ubuntutest)
-
-        publisher = Publisher(
-            self.logger, self.config, self.disk_pool,
-            self.ubuntutest.main_archive)
-
-        publisher.A_publish(False)
-        publisher.C_writeIndexes(False)
-        publisher.D_writeReleaseFiles(False)
-
-        self.assertIndicesForArchitectures(
-            publisher, present=['hppa'], absent=['i386'])
-
-    def testAptFtparchiveNoIndicesForDisabledArchitectures(self):
-        """Test that no indices are created for disabled archs."""
-        self.getPubBinaries()
-
-        ds = self.ubuntutest.getSeries('breezy-autotest')
-        ds.getDistroArchSeries('i386').enabled = False
-        self.config = Config(self.ubuntutest)
-
-        publisher = Publisher(
-            self.logger, self.config, self.disk_pool,
-            self.ubuntutest.main_archive)
-
-        publisher.A_publish(False)
-        publisher.C_doFTPArchive(False)
-        publisher.D_writeReleaseFiles(False)
-
-        self.assertIndicesForArchitectures(
-            publisher, present=['hppa'], absent=['i386'])
+            publisher._config.distsroot, series.getSuite(pocket),
+            'Release')).read()
+
+        for comp in ('main', 'restricted', 'universe', 'multiverse'):
+            # Check that source indices are present.
+            for path in (release_template, sources_template):
+                self.assertTrue(os.path.exists(path % (comp, 'source')))
+
+            # Check that wanted binary indices are present.
+            for arch_tag in present:
+                arch = 'binary-' + arch_tag
+                for path in (release_template, packages_template):
+                    self.assertTrue(os.path.exists(path % (comp, arch)))
+                self.assertTrue(arch in release_content)
+
+            # Check that unwanted binary indices are absent.
+            for arch_tag in absent:
+                arch = 'binary-' + arch_tag
+                self.assertFalse(os.path.exists(arch_template % (comp, arch)))
+                self.assertFalse(arch in release_content)
+
+    def testAllIndicesArePublished(self):
+        """Test that indices are created for all components and archs."""
+        # Dirty breezy-autotest with a source. Even though there are no
+        # new binaries in the suite, all its indices will still be published.
+        self.getPubSource()
+        self.getPubSource(pocket=PackagePublishingPocket.PROPOSED)
+
+        # Override the series status to FROZEN, which allows publication
+        # of all pockets.
+        self.ubuntutest.getSeries('breezy-autotest').status = (
+            SeriesStatus.FROZEN)
+
+        self.config = Config(self.ubuntutest)
+        publisher = Publisher(
+            self.logger, self.config, self.disk_pool,
+            self.ubuntutest.main_archive)
+
+        publisher.A_publish(False)
+        self.runStepC(publisher)
+        publisher.D_writeReleaseFiles(False)
+
+        self.assertIndices(
+            publisher, [
+                (self.breezy_autotest, PackagePublishingPocket.RELEASE),
+                (self.breezy_autotest, PackagePublishingPocket.PROPOSED),
+            ], present=['hppa', 'i386'])
+
+    def testNoIndicesForDisabledArchitectures(self):
+        """Test that no indices are created for disabled archs."""
+        self.getPubBinaries()
+
+        ds = self.ubuntutest.getSeries('breezy-autotest')
+        ds.getDistroArchSeries('i386').enabled = False
+        self.config = Config(self.ubuntutest)
+
+        publisher = Publisher(
+            self.logger, self.config, self.disk_pool,
+            self.ubuntutest.main_archive)
+
+        publisher.A_publish(False)
+        self.runStepC(publisher)
+        publisher.D_writeReleaseFiles(False)
+
+        self.assertIndicesForSuite(
+            publisher, self.breezy_autotest, PackagePublishingPocket.RELEASE,
+            present=['hppa'], absent=['i386'])
 
     def testWorldAndGroupReadablePackagesAndSources(self):
-        """Test Packages.gz and Sources.gz files are world and group readable.
+        """Test Packages.gz and Sources.gz files are world readable."""
+        publisher = Publisher(
+            self.logger, self.config, self.disk_pool,
+            self.ubuntutest.main_archive, allowed_suites=[])
 
-        Packages.gz and Sources.gz files generated by NoMoreAF must be
-        world and group readable.  We'll test this in the partner archive
-        as that uses NoMoreAF. (No More Apt-Ftparchive)
-        """
-        archive = self.ubuntutest.getArchiveByComponent('partner')
-        allowed_suites = []
-        publisher = getPublisher(archive, allowed_suites, self.logger)
-        self.getPubSource(filecontent='Hello world', archive=archive)
+        self.getPubSource(filecontent='Hello world')
         publisher.A_publish(False)
-        publisher.C_writeIndexes(False)
+        self.runStepC(publisher)
 
         # Find a Sources.gz and Packages.gz that were just published
         # in the breezy-autotest distroseries.
         sourcesgz_file = os.path.join(
-            publisher._config.distsroot, 'breezy-autotest', 'partner',
+            publisher._config.distsroot, 'breezy-autotest', 'main',
             'source', 'Sources.gz')
         packagesgz_file = os.path.join(
-            publisher._config.distsroot, 'breezy-autotest', 'partner',
+            publisher._config.distsroot, 'breezy-autotest', 'main',
             'binary-i386', 'Packages.gz')
 
         # What permissions are set on those files?
@@ -1180,6 +1215,14 @@
                 "%s is not world/group readable." % file)
 
 
+class TestFtparchiveIndices(TestArchiveIndices):
+    """Tests for the apt-ftparchive publisher's index generation."""
+
+    def runStepC(self, publisher):
+        """Run the apt-ftparchive index generation step of the publisher."""
+        publisher.C_doFTPArchive(False)
+
+
 class TestPublisherRepositorySignatures(TestPublisherBase):
     """Testing `Publisher` signature behaviour."""