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

Proposed by William Grant
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: 11727
Proposed branch: lp:~wgrant/launchpad/better-publisher-index-tests
Merge into: lp:launchpad
Diff against target: 214 lines (+110/-67)
1 file modified
lib/lp/archivepublisher/tests/test_publisher.py (+110/-67)
To merge this branch: bzr merge lp:~wgrant/launchpad/better-publisher-index-tests
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+38462@code.launchpad.net

Commit message

Start de-duplicating the apt-ftparchive and native publishing tests, and add more thorough index generation tests.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Hi William,

Thanks for this branch.

As we discussed on IRC, in TestArchiveIndices you created two new methods that have default values of '[]'. Since you make the claim you never mutate them please change to be an empty tuple to enforce it.

Otherwise it looks fine.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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-15 08:38:48 +0000
@@ -1081,94 +1081,129 @@
1081 # The Label: field should be set to the archive displayname1081 # The Label: field should be set to the archive displayname
1082 self.assertEqual(release_contents[1], 'Label: Partner archive')1082 self.assertEqual(release_contents[1], 'Label: Partner archive')
10831083
1084 def assertIndicesForArchitectures(self, publisher, present, absent):1084
1085 """Assert that the correct set of archs has indices.1085class TestArchiveIndices(TestPublisherBase):
1086 """Tests for the native publisher's index generation.
1087
1088 Verifies that all Packages/Sources/Release files are generated when
1089 appropriate.
1090 """
1091
1092 def runStepC(self, publisher):
1093 """Run the index generation step of the publisher."""
1094 publisher.C_writeIndexes(False)
1095
1096 def assertIndices(self, publisher, suites, present=(), absent=()):
1097 """Assert that the given suites have correct indices."""
1098 for series, pocket in suites:
1099 self.assertIndicesForSuite(
1100 publisher, series, pocket, present, absent)
1101
1102 def assertIndicesForSuite(self, publisher, series, pocket,
1103 present=(), absent=()):
1104 """Assert that the suite has correct indices.
10861105
1087 Checks that the architecture tags in 'present' have Packages and1106 Checks that the architecture tags in 'present' have Packages and
1088 Release files and are in the series' Release file, and confirms1107 Release files and are in the series' Release file, and confirms
1089 that those in 'absent' are not.1108 that those in 'absent' are not.
1090 """1109 """
10911110
1092 self.checkAllRequestedReleaseFiles(1111 self.assertTrue(
1093 publisher, architecturetags=present)1112 series.getSuite(pocket) in
1113 publisher.apt_handler.release_files_needed)
10941114
1095 arch_template = os.path.join(1115 arch_template = os.path.join(
1096 publisher._config.distsroot, 'breezy-autotest/main/binary-%s')1116 publisher._config.distsroot, series.getSuite(pocket), '%s/%s')
1117
1097 release_template = os.path.join(arch_template, 'Release')1118 release_template = os.path.join(arch_template, 'Release')
1098 packages_template = os.path.join(arch_template, 'Packages')1119 packages_template = os.path.join(arch_template, 'Packages')
1120 sources_template = os.path.join(arch_template, 'Sources')
1099 release_content = open(os.path.join(1121 release_content = open(os.path.join(
1100 publisher._config.distsroot,1122 publisher._config.distsroot, series.getSuite(pocket),
1101 'breezy-autotest/Release')).read()1123 'Release')).read()
11021124
1103 for arch in present:1125 for comp in ('main', 'restricted', 'universe', 'multiverse'):
1104 self.assertTrue(os.path.exists(arch_template % arch))1126 # Check that source indices are present.
1105 self.assertTrue(os.path.exists(release_template % arch))1127 for path in (release_template, sources_template):
1106 self.assertTrue(os.path.exists(packages_template % arch))1128 self.assertTrue(os.path.exists(path % (comp, 'source')))
1107 self.assertTrue(arch in release_content)1129
11081130 # Check that wanted binary indices are present.
1109 for arch in absent:1131 for arch_tag in present:
1110 self.assertFalse(os.path.exists(arch_template % arch))1132 arch = 'binary-' + arch_tag
1111 self.assertFalse(arch in release_content)1133 for path in (release_template, packages_template):
11121134 self.assertTrue(os.path.exists(path % (comp, arch)))
1113 def testNativeNoIndicesForDisabledArchitectures(self):1135 self.assertTrue(arch in release_content)
1114 """Test that no indices are created for disabled archs."""1136
1115 self.getPubBinaries()1137 # Check that unwanted binary indices are absent.
11161138 for arch_tag in absent:
1117 ds = self.ubuntutest.getSeries('breezy-autotest')1139 arch = 'binary-' + arch_tag
1118 ds.getDistroArchSeries('i386').enabled = False1140 self.assertFalse(os.path.exists(arch_template % (comp, arch)))
1119 self.config = Config(self.ubuntutest)1141 self.assertFalse(arch in release_content)
11201142
1121 publisher = Publisher(1143 def testAllIndicesArePublished(self):
1122 self.logger, self.config, self.disk_pool,1144 """Test that indices are created for all components and archs."""
1123 self.ubuntutest.main_archive)1145 # Dirty breezy-autotest with a source. Even though there are no
11241146 # new binaries in the suite, all its indices will still be published.
1125 publisher.A_publish(False)1147 self.getPubSource()
1126 publisher.C_writeIndexes(False)1148 self.getPubSource(pocket=PackagePublishingPocket.PROPOSED)
1127 publisher.D_writeReleaseFiles(False)1149
11281150 # Override the series status to FROZEN, which allows publication
1129 self.assertIndicesForArchitectures(1151 # of all pockets.
1130 publisher, present=['hppa'], absent=['i386'])1152 self.ubuntutest.getSeries('breezy-autotest').status = (
11311153 SeriesStatus.FROZEN)
1132 def testAptFtparchiveNoIndicesForDisabledArchitectures(self):1154
1133 """Test that no indices are created for disabled archs."""1155 self.config = Config(self.ubuntutest)
1134 self.getPubBinaries()1156 publisher = Publisher(
11351157 self.logger, self.config, self.disk_pool,
1136 ds = self.ubuntutest.getSeries('breezy-autotest')1158 self.ubuntutest.main_archive)
1137 ds.getDistroArchSeries('i386').enabled = False1159
1138 self.config = Config(self.ubuntutest)1160 publisher.A_publish(False)
11391161 self.runStepC(publisher)
1140 publisher = Publisher(1162 publisher.D_writeReleaseFiles(False)
1141 self.logger, self.config, self.disk_pool,1163
1142 self.ubuntutest.main_archive)1164 self.assertIndices(
11431165 publisher, [
1144 publisher.A_publish(False)1166 (self.breezy_autotest, PackagePublishingPocket.RELEASE),
1145 publisher.C_doFTPArchive(False)1167 (self.breezy_autotest, PackagePublishingPocket.PROPOSED),
1146 publisher.D_writeReleaseFiles(False)1168 ], present=['hppa', 'i386'])
11471169
1148 self.assertIndicesForArchitectures(1170 def testNoIndicesForDisabledArchitectures(self):
1149 publisher, present=['hppa'], absent=['i386'])1171 """Test that no indices are created for disabled archs."""
1172 self.getPubBinaries()
1173
1174 ds = self.ubuntutest.getSeries('breezy-autotest')
1175 ds.getDistroArchSeries('i386').enabled = False
1176 self.config = Config(self.ubuntutest)
1177
1178 publisher = Publisher(
1179 self.logger, self.config, self.disk_pool,
1180 self.ubuntutest.main_archive)
1181
1182 publisher.A_publish(False)
1183 self.runStepC(publisher)
1184 publisher.D_writeReleaseFiles(False)
1185
1186 self.assertIndicesForSuite(
1187 publisher, self.breezy_autotest, PackagePublishingPocket.RELEASE,
1188 present=['hppa'], absent=['i386'])
11501189
1151 def testWorldAndGroupReadablePackagesAndSources(self):1190 def testWorldAndGroupReadablePackagesAndSources(self):
1152 """Test Packages.gz and Sources.gz files are world and group readable.1191 """Test Packages.gz and Sources.gz files are world readable."""
1192 publisher = Publisher(
1193 self.logger, self.config, self.disk_pool,
1194 self.ubuntutest.main_archive, allowed_suites=[])
11531195
1154 Packages.gz and Sources.gz files generated by NoMoreAF must be1196 self.getPubSource(filecontent='Hello world')
1155 world and group readable. We'll test this in the partner archive
1156 as that uses NoMoreAF. (No More Apt-Ftparchive)
1157 """
1158 archive = self.ubuntutest.getArchiveByComponent('partner')
1159 allowed_suites = []
1160 publisher = getPublisher(archive, allowed_suites, self.logger)
1161 self.getPubSource(filecontent='Hello world', archive=archive)
1162 publisher.A_publish(False)1197 publisher.A_publish(False)
1163 publisher.C_writeIndexes(False)1198 self.runStepC(publisher)
11641199
1165 # Find a Sources.gz and Packages.gz that were just published1200 # Find a Sources.gz and Packages.gz that were just published
1166 # in the breezy-autotest distroseries.1201 # in the breezy-autotest distroseries.
1167 sourcesgz_file = os.path.join(1202 sourcesgz_file = os.path.join(
1168 publisher._config.distsroot, 'breezy-autotest', 'partner',1203 publisher._config.distsroot, 'breezy-autotest', 'main',
1169 'source', 'Sources.gz')1204 'source', 'Sources.gz')
1170 packagesgz_file = os.path.join(1205 packagesgz_file = os.path.join(
1171 publisher._config.distsroot, 'breezy-autotest', 'partner',1206 publisher._config.distsroot, 'breezy-autotest', 'main',
1172 'binary-i386', 'Packages.gz')1207 'binary-i386', 'Packages.gz')
11731208
1174 # What permissions are set on those files?1209 # What permissions are set on those files?
@@ -1180,6 +1215,14 @@
1180 "%s is not world/group readable." % file)1215 "%s is not world/group readable." % file)
11811216
11821217
1218class TestFtparchiveIndices(TestArchiveIndices):
1219 """Tests for the apt-ftparchive publisher's index generation."""
1220
1221 def runStepC(self, publisher):
1222 """Run the apt-ftparchive index generation step of the publisher."""
1223 publisher.C_doFTPArchive(False)
1224
1225
1183class TestPublisherRepositorySignatures(TestPublisherBase):1226class TestPublisherRepositorySignatures(TestPublisherBase):
1184 """Testing `Publisher` signature behaviour."""1227 """Testing `Publisher` signature behaviour."""
11851228