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
1=== modified file 'lib/lp/archivepublisher/tests/test_publisher.py'
2--- lib/lp/archivepublisher/tests/test_publisher.py 2010-10-07 13:44:47 +0000
3+++ lib/lp/archivepublisher/tests/test_publisher.py 2010-10-15 08:38:48 +0000
4@@ -1081,94 +1081,129 @@
5 # The Label: field should be set to the archive displayname
6 self.assertEqual(release_contents[1], 'Label: Partner archive')
7
8- def assertIndicesForArchitectures(self, publisher, present, absent):
9- """Assert that the correct set of archs has indices.
10+
11+class TestArchiveIndices(TestPublisherBase):
12+ """Tests for the native publisher's index generation.
13+
14+ Verifies that all Packages/Sources/Release files are generated when
15+ appropriate.
16+ """
17+
18+ def runStepC(self, publisher):
19+ """Run the index generation step of the publisher."""
20+ publisher.C_writeIndexes(False)
21+
22+ def assertIndices(self, publisher, suites, present=(), absent=()):
23+ """Assert that the given suites have correct indices."""
24+ for series, pocket in suites:
25+ self.assertIndicesForSuite(
26+ publisher, series, pocket, present, absent)
27+
28+ def assertIndicesForSuite(self, publisher, series, pocket,
29+ present=(), absent=()):
30+ """Assert that the suite has correct indices.
31
32 Checks that the architecture tags in 'present' have Packages and
33 Release files and are in the series' Release file, and confirms
34 that those in 'absent' are not.
35 """
36
37- self.checkAllRequestedReleaseFiles(
38- publisher, architecturetags=present)
39+ self.assertTrue(
40+ series.getSuite(pocket) in
41+ publisher.apt_handler.release_files_needed)
42
43 arch_template = os.path.join(
44- publisher._config.distsroot, 'breezy-autotest/main/binary-%s')
45+ publisher._config.distsroot, series.getSuite(pocket), '%s/%s')
46+
47 release_template = os.path.join(arch_template, 'Release')
48 packages_template = os.path.join(arch_template, 'Packages')
49+ sources_template = os.path.join(arch_template, 'Sources')
50 release_content = open(os.path.join(
51- publisher._config.distsroot,
52- 'breezy-autotest/Release')).read()
53-
54- for arch in present:
55- self.assertTrue(os.path.exists(arch_template % arch))
56- self.assertTrue(os.path.exists(release_template % arch))
57- self.assertTrue(os.path.exists(packages_template % arch))
58- self.assertTrue(arch in release_content)
59-
60- for arch in absent:
61- self.assertFalse(os.path.exists(arch_template % arch))
62- self.assertFalse(arch in release_content)
63-
64- def testNativeNoIndicesForDisabledArchitectures(self):
65- """Test that no indices are created for disabled archs."""
66- self.getPubBinaries()
67-
68- ds = self.ubuntutest.getSeries('breezy-autotest')
69- ds.getDistroArchSeries('i386').enabled = False
70- self.config = Config(self.ubuntutest)
71-
72- publisher = Publisher(
73- self.logger, self.config, self.disk_pool,
74- self.ubuntutest.main_archive)
75-
76- publisher.A_publish(False)
77- publisher.C_writeIndexes(False)
78- publisher.D_writeReleaseFiles(False)
79-
80- self.assertIndicesForArchitectures(
81- publisher, present=['hppa'], absent=['i386'])
82-
83- def testAptFtparchiveNoIndicesForDisabledArchitectures(self):
84- """Test that no indices are created for disabled archs."""
85- self.getPubBinaries()
86-
87- ds = self.ubuntutest.getSeries('breezy-autotest')
88- ds.getDistroArchSeries('i386').enabled = False
89- self.config = Config(self.ubuntutest)
90-
91- publisher = Publisher(
92- self.logger, self.config, self.disk_pool,
93- self.ubuntutest.main_archive)
94-
95- publisher.A_publish(False)
96- publisher.C_doFTPArchive(False)
97- publisher.D_writeReleaseFiles(False)
98-
99- self.assertIndicesForArchitectures(
100- publisher, present=['hppa'], absent=['i386'])
101+ publisher._config.distsroot, series.getSuite(pocket),
102+ 'Release')).read()
103+
104+ for comp in ('main', 'restricted', 'universe', 'multiverse'):
105+ # Check that source indices are present.
106+ for path in (release_template, sources_template):
107+ self.assertTrue(os.path.exists(path % (comp, 'source')))
108+
109+ # Check that wanted binary indices are present.
110+ for arch_tag in present:
111+ arch = 'binary-' + arch_tag
112+ for path in (release_template, packages_template):
113+ self.assertTrue(os.path.exists(path % (comp, arch)))
114+ self.assertTrue(arch in release_content)
115+
116+ # Check that unwanted binary indices are absent.
117+ for arch_tag in absent:
118+ arch = 'binary-' + arch_tag
119+ self.assertFalse(os.path.exists(arch_template % (comp, arch)))
120+ self.assertFalse(arch in release_content)
121+
122+ def testAllIndicesArePublished(self):
123+ """Test that indices are created for all components and archs."""
124+ # Dirty breezy-autotest with a source. Even though there are no
125+ # new binaries in the suite, all its indices will still be published.
126+ self.getPubSource()
127+ self.getPubSource(pocket=PackagePublishingPocket.PROPOSED)
128+
129+ # Override the series status to FROZEN, which allows publication
130+ # of all pockets.
131+ self.ubuntutest.getSeries('breezy-autotest').status = (
132+ SeriesStatus.FROZEN)
133+
134+ self.config = Config(self.ubuntutest)
135+ publisher = Publisher(
136+ self.logger, self.config, self.disk_pool,
137+ self.ubuntutest.main_archive)
138+
139+ publisher.A_publish(False)
140+ self.runStepC(publisher)
141+ publisher.D_writeReleaseFiles(False)
142+
143+ self.assertIndices(
144+ publisher, [
145+ (self.breezy_autotest, PackagePublishingPocket.RELEASE),
146+ (self.breezy_autotest, PackagePublishingPocket.PROPOSED),
147+ ], present=['hppa', 'i386'])
148+
149+ def testNoIndicesForDisabledArchitectures(self):
150+ """Test that no indices are created for disabled archs."""
151+ self.getPubBinaries()
152+
153+ ds = self.ubuntutest.getSeries('breezy-autotest')
154+ ds.getDistroArchSeries('i386').enabled = False
155+ self.config = Config(self.ubuntutest)
156+
157+ publisher = Publisher(
158+ self.logger, self.config, self.disk_pool,
159+ self.ubuntutest.main_archive)
160+
161+ publisher.A_publish(False)
162+ self.runStepC(publisher)
163+ publisher.D_writeReleaseFiles(False)
164+
165+ self.assertIndicesForSuite(
166+ publisher, self.breezy_autotest, PackagePublishingPocket.RELEASE,
167+ present=['hppa'], absent=['i386'])
168
169 def testWorldAndGroupReadablePackagesAndSources(self):
170- """Test Packages.gz and Sources.gz files are world and group readable.
171+ """Test Packages.gz and Sources.gz files are world readable."""
172+ publisher = Publisher(
173+ self.logger, self.config, self.disk_pool,
174+ self.ubuntutest.main_archive, allowed_suites=[])
175
176- Packages.gz and Sources.gz files generated by NoMoreAF must be
177- world and group readable. We'll test this in the partner archive
178- as that uses NoMoreAF. (No More Apt-Ftparchive)
179- """
180- archive = self.ubuntutest.getArchiveByComponent('partner')
181- allowed_suites = []
182- publisher = getPublisher(archive, allowed_suites, self.logger)
183- self.getPubSource(filecontent='Hello world', archive=archive)
184+ self.getPubSource(filecontent='Hello world')
185 publisher.A_publish(False)
186- publisher.C_writeIndexes(False)
187+ self.runStepC(publisher)
188
189 # Find a Sources.gz and Packages.gz that were just published
190 # in the breezy-autotest distroseries.
191 sourcesgz_file = os.path.join(
192- publisher._config.distsroot, 'breezy-autotest', 'partner',
193+ publisher._config.distsroot, 'breezy-autotest', 'main',
194 'source', 'Sources.gz')
195 packagesgz_file = os.path.join(
196- publisher._config.distsroot, 'breezy-autotest', 'partner',
197+ publisher._config.distsroot, 'breezy-autotest', 'main',
198 'binary-i386', 'Packages.gz')
199
200 # What permissions are set on those files?
201@@ -1180,6 +1215,14 @@
202 "%s is not world/group readable." % file)
203
204
205+class TestFtparchiveIndices(TestArchiveIndices):
206+ """Tests for the apt-ftparchive publisher's index generation."""
207+
208+ def runStepC(self, publisher):
209+ """Run the apt-ftparchive index generation step of the publisher."""
210+ publisher.C_doFTPArchive(False)
211+
212+
213 class TestPublisherRepositorySignatures(TestPublisherBase):
214 """Testing `Publisher` signature behaviour."""
215