Merge lp:~stevenk/launchpad/switch-ifp-to-unittests into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 11343
Proposed branch: lp:~stevenk/launchpad/switch-ifp-to-unittests
Merge into: lp:launchpad
Prerequisite: lp:~stevenk/launchpad/move-ifp-from-idistroseries
Diff against target: 383 lines (+183/-191)
2 files modified
lib/lp/soyuz/doc/initialise-from-parent.txt (+0/-191)
lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py (+183/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/switch-ifp-to-unittests
Reviewer Review Type Date Requested Status
Graham Binns (community) Abstain
Michael Nelson (community) Approve
Review via email: mp+32073@code.launchpad.net

Commit message

Drop the doctest for scripts/ftpmaster-tools/initialise-from-parent.py, and convert it to a unit test.

Description of the change

This branch drops the doctest for initialise-from-parent, and adds unit tests for the same code.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Hi Steve,

So, your new tests look okay, though I'd like to get a second opinion on whether they completely replace the existing doctests since I find the doctests quite torturous to read.

However, the new tests are sorely in need of comments. Firstly, each test_ method should have a comment or docstring (I prefer comments for tests, FTR) explaining what's being tested, in the form:

    def test_frobnob_goes_boing(self):
        # The frobnob will go boing if pushed.

Secondly, I can't tell (because there are no comments to tell me) whether test_initialise() is huge for a reason or whether it can be split into individual tests. I'm guessing that it's huge for a reason, because all the asserts seem to be of the nature of

    foo = bar.foo
    self.assertEqual(expected_foo, foo)

Which is fine, but given the length of the method they should have some explanation with them:

    # The bar's foo will have been updated.
    foo = bar.foo
    self.assertEqual(expected_foo, foo)

As I said, I don't have the context for knowing if the test conversion is accurate, since the old test seems to rely a lot on the output from the script. I'd appreciate it if you could find someone else (Jools maybe) who can confirm that (I'm aware that this is overkill but I'm also aware that this is a Soyuz branch).

I'm marking the branch as needs fixing pending the changes above.

review: Needs Fixing (code)
Revision history for this message
Michael Nelson (michael.nelson) wrote :
Download full text (5.7 KiB)

Hi Steven,

It's great to see the doctest being replaced!

In addition to the method comment mentioned by gmb, I'd also be keen to see all the test_failure_* methods be a bit more specific... the easiest way to do this might be to use self.assertRaisesWithContent() which will ensure that the cause of the raised exception is obvious.

There is generally a lot of info in the doctest which is currently removed... it'd be great to include all the pertinent bits (imagine you knew nothing about soyuz and were looking at this test).

I can't see anything missing from the conversion... perhaps one or two things could be removed (see below). Also, regarding the length of test_initialise,

=== added file 'lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py'
--- lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 1970-01-01 00:00:00 +0000
+++ lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 2010-08-10 14:55:27 +0000
@@ -0,0 +1,144 @@
<snip>
+
+ def test_initialise(self):

From here...
+ foobuntu = self._create_distroseries(self.hoary)
+ self._set_pending_to_failed(self.hoary)
+ transaction.commit()
+ ids = InitialiseDistroSeries(foobuntu)
+ ids.check()
+ ids.initialise()
to here could be extracted into self._initialise_distroseries() ?

and then from here:
+ hoary_pmount_pubs = self.hoary.getPublishedReleases('pmount')
+ foobuntu_pmount_pubs = foobuntu.getPublishedReleases('pmount')
+ self.assertEqual(len(hoary_pmount_pubs), len(foobuntu_pmount_pubs))
+ hoary_i386_pmount_pubs = self.hoary['i386'].getReleasedPackages(
+ 'pmount')
+ foobuntu_i386_pmount_pubs = foobuntu['i386'].getReleasedPackages(
+ 'pmount')
+ self.assertEqual(
+ len(hoary_i386_pmount_pubs), len(foobuntu_i386_pmount_pubs))
+ pmount_binrel = (
+ foobuntu['i386'].getReleasedPackages(
+ 'pmount')[0].binarypackagerelease)
+ self.assertEqual(pmount_binrel.title, u'pmount-0.1-1')
+ self.assertEqual(pmount_binrel.build.id, 7)
+ self.assertEqual(
+ pmount_binrel.build.title,
+ u'i386 build of pmount 0.1-1 in ubuntu hoary RELEASE')
+ pmount_srcrel = pmount_binrel.build.source_package_release
+ self.assertEqual(pmount_srcrel.title, u'pmount - 0.1-1')
+ foobuntu_pmount = pmount_srcrel.getBuildByArch(
+ foobuntu['i386'], foobuntu.main_archive)
+ hoary_pmount = pmount_srcrel.getBuildByArch(
+ self.hoary['i386'], self.hoary.main_archive)
+ self.assertEqual(foobuntu_pmount.id, hoary_pmount.id)
+ pmount_source = self.hoary.getSourcePackage(
+ 'pmount').currentrelease
+ self.assertEqual(
+ pmount_source.title,
+ '"pmount" 0.1-2 source package in The Hoary Hedgehog Release')
+ pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
+ self.assertEqual(
+ pmount_source.title,
+ '"pmount" 0.1-2 source package in The Foobuntu')

...to here into self.assertDistroSeriesEqual() (hrm.. with a more accurate method name), so you have a nice small tes...

Read more...

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Hi Steve,

As per our IRC conv., unless there's a reason for not creating a custom assertion such as assertDistroSeriesInitializdCorrectly(), please rename _check_distroseries() to follow normal unit-test assertion names.

Also, this method (whether it is renamed or not) should definitely not be creating builds... it should only be checking/asserting things. That's why I really think it should be a separate test (see comment above where it's identified).

And lastly, you didn't comment on the _initiale_distroseries() - ah, it'd only be necessary/useful to avoid duplicate code if you had the separate test as above.

{{{
12:15 < noodles> StevenK: I assumed when you said earlier that it adds nothing to the test run, that you'd isolated the positive tests, but the diff on the MP still only has test_initialize? Also any reason for not calling _check_distroseries assertDistroSeriesInitialized(distro1, distro2) or similar? (it is a custom assertion right?)
12:19 < jelmer> bigjools: While I'm changing the BinaryPackageRelease table, would it be ok if I also added the field for Homepage?
12:19 < bigjools> jelmer: what's that for?
12:19 < jelmer> bigjools: I have to touch the code that fills it in, and it would help for bug 319196 and bug 602385
12:19 < edbot> Bug #319196: On the source+ page, provide external links <https://launchpad.net/bugs/319196> <soyuz [Triaged/Low] No assignee>
12:19 < edbot> Bug #602385: Allow SPs to register an upstream project <https://launchpad.net/bugs/602385> <launchpad-registry [In Progress/High] Edwin
               Grubbs>
12:20 < bigjools> jelmer: that would need to be on SourcePackageRelease woundn't it?
12:20 < bigjools> wouldn't, even
12:22 < StevenK> noodles: It shouldn't ...
12:22 < StevenK> noodles: Both test_initialise() and test_script() call self._check_distroseries(foobuntu)
12:22 < bigjools> jelmer: also, I'm not sure about that first bug any more, I think we should do it through packaging links
12:22 < bigjools> as per the 2nd bug
12
:23 < bigjools> it might be worth talking to Curtis
12:23 < noodles> StevenK: yes, but they both use it like an assertion, so why not a custom assertion as above?
12:23 < jelmer> bigjools: It would need to be on both spr and bpr I guess, since its in both their control fields
12:23 < jelmer> bigjools: I'll ask him, thanks
12:24 < StevenK> noodles: I can rename the method if you wish, but the intent is clear
12:24 < bigjools> jelmer: I can't see the actual use for it in LP if it's on BPR though
12:24 < noodles> StevenK: I don't mind... I was just wondering if there was a reason for not using standard unit-test conventions?
12:24 < StevenK> noodles: I was trying to get away with changing as little code as possible
12:25 < StevenK> It worked, too.
}}}

Revision history for this message
Robert Collins (lifeless) wrote :

@Michael, re custom assertions - have you seen the matcher stuff that
James Westby has been emailing about on the dev list? I'm biased ;),
but I think its really nice and cleaner than custom assertions.

-Rob

Revision history for this message
Michael Nelson (michael.nelson) wrote :

> @Michael, re custom assertions - have you seen the matcher stuff that
> James Westby has been emailing about on the dev list? I'm biased ;),
> but I think its really nice and cleaner than custom assertions.
>
> -Rob

Yeah I did... they do look great :) I'd be happy if StevenK wanted to use them, but didn't want to request even more changes. I'll leave that up to StevenK.

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Thanks again Steven. It looks good now... there are just some inconsistencies in the comments which I've highlighted with a diff (to save confusion):

http://pastebin.ubuntu.com/476903/

With those fixed up as you see fit, r=me.

review: Approve
Revision history for this message
Graham Binns (gmb) wrote :

I think Michael's review is more than comprehensive enough to cover my original concerns.

review: Abstain

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'lib/lp/soyuz/doc/initialise-from-parent.txt'
2--- lib/lp/soyuz/doc/initialise-from-parent.txt 2010-08-12 13:49:50 +0000
3+++ lib/lp/soyuz/doc/initialise-from-parent.txt 1970-01-01 00:00:00 +0000
4@@ -1,191 +0,0 @@
5-Check the behaviour of the initialise_from_parent script. It basically
6-calls IDistroSeries.initialiseFromParent method with experimental extra
7-checks and tasks.
8-
9-We need to create an initialisable DistroSeries as a child of Ubuntu
10-Hoary (we do it inside the ubuntutest distribution to avoid conflicts
11-with other tests)
12-
13- >>> from canonical.launchpad.interfaces import IDistributionSet
14- >>> from canonical.launchpad.ftests import login
15-
16- >>> login("foo.bar@canonical.com")
17- >>> distribution_set = getUtility(IDistributionSet)
18- >>> ubuntutest = distribution_set['ubuntutest']
19- >>> ubuntu = distribution_set['ubuntu']
20- >>> hoary = ubuntu['hoary']
21-
22- # XXX cprov 2006-05-29 bug=49133:
23- # New distroseries should be provided by IDistribution.
24- # This maybe affected by derivation design and is documented in bug.
25-
26- >>> foobuntu = ubuntutest.newSeries('foobuntu', 'FooBuntu',
27- ... 'The Foobuntu', 'yeck', 'doom',
28- ... '888', hoary, hoary.owner)
29-
30-
31-The script will check that there are no NEEDSBUILD builds in the parent
32-distroseries' release pocket, so we need to tweak the status of the NEEDSBUILD
33-builds that exist in Ubuntu Hoary in the sampledata:
34-
35- >>> from lp.buildmaster.interfaces.buildbase import BuildStatus
36- >>> from lp.registry.interfaces.pocket import PackagePublishingPocket
37-
38- >>> pending_builds = hoary.getBuildRecords(BuildStatus.NEEDSBUILD,
39- ... pocket=PackagePublishingPocket.RELEASE)
40- >>> for build in pending_builds:
41- ... build.status = BuildStatus.FAILEDTOBUILD
42-
43- >>> import transaction
44- >>> transaction.commit()
45-
46-
47- >>> import subprocess
48- >>> import os
49- >>> import sys
50- >>> from canonical.config import config
51-
52-
53-Check if it fails for an already released distroseries:
54-
55- >>> script = os.path.join(config.root, "scripts", "ftpmaster-tools",
56- ... "initialise-from-parent.py")
57- >>> process = subprocess.Popen([sys.executable, script, "-vv",
58- ... "breezy-autotest"],
59- ... stdout=subprocess.PIPE,
60- ... stderr=subprocess.PIPE,)
61- >>> stdout, stderr = process.communicate()
62- >>> process.returncode
63- 1
64- >>> print stderr
65- DEBUG Acquiring lock
66- DEBUG Initialising connection.
67- DEBUG Check empty mutable queues in parentseries
68- DEBUG Check for no pending builds in parentseries
69- DEBUG Copying distroarchseries from parent and setting nominatedarchindep.
70- ERROR Can not copy distroarchseries from parent, there are already distroarchseries(s) initialised for this series.
71- <BLANKLINE>
72-
73-Let's initialise the just created distroseries:
74-
75- >>> process = subprocess.Popen([sys.executable, script, "-vv",
76- ... "-d", "ubuntutest", "foobuntu"],
77- ... stdout=subprocess.PIPE,
78- ... stderr=subprocess.PIPE,)
79- >>> stdout, stderr = process.communicate()
80- >>> process.returncode
81- 0
82- >>> print stderr
83- DEBUG Acquiring lock
84- DEBUG Initialising connection.
85- DEBUG Check empty mutable queues in parentseries
86- DEBUG Check for no pending builds in parentseries
87- DEBUG Copying distroarchseries from parent and setting nominatedarchindep.
88- DEBUG initialising from parent, copying publishing records.
89- DEBUG Committing transaction.
90- DEBUG Releasing lock
91- <BLANKLINE>
92-
93-
94-Checking the published sources and binaries of ubuntutest/foobuntu
95-against its parent, ubuntu/hoary:
96-
97- >>> hoary_pmount_pubs = hoary.getPublishedReleases('pmount')
98- >>> foobuntu_pmount_pubs = foobuntu.getPublishedReleases('pmount')
99- >>> len(foobuntu_pmount_pubs) == len(hoary_pmount_pubs)
100- True
101-
102- >>> hoary_i386_pmount_pubs = hoary['i386'].getReleasedPackages('pmount')
103- >>> foobuntu_i386_pmount_pubs = (
104- ... foobuntu['i386'].getReleasedPackages('pmount'))
105- >>> len(foobuntu_i386_pmount_pubs) == len(hoary_i386_pmount_pubs)
106- True
107-
108-Check how the publication records behave in a just-initialise distroseries.
109-First we get a binarypackagerelease published in foobuntu:
110-
111- >>> pmount_binrel = (
112- ... foobuntu['i386'].getReleasedPackages(
113- ... 'pmount')[0].binarypackagerelease)
114- >>> pmount_binrel.title
115- u'pmount-0.1-1'
116-
117-Follow BPR.build and discover it was built in the parent series:
118-
119- >>> pmount_binrel.build.id
120- 7
121- >>> pmount_binrel.build.title
122- u'i386 build of pmount 0.1-1 in ubuntu hoary RELEASE'
123-
124-Now we obtain the sourcepackagerelease from the build:
125-
126- >>> pmount_srcrel = pmount_binrel.build.source_package_release
127- >>> pmount_srcrel.title
128- u'pmount - 0.1-1'
129-
130-and check it the ISPR.getBuildByArch() would find out the same build
131-record for foobuntu and it's parent series (hoary):
132-
133- >>> foobuntu_pmount = pmount_srcrel.getBuildByArch(
134- ... foobuntu['i386'], foobuntu.main_archive)
135- >>> hoary_pmount = pmount_srcrel.getBuildByArch(
136- ... hoary['i386'], hoary.main_archive)
137-
138- >>> foobuntu_pmount.id == hoary_pmount.id
139- True
140-
141-It means that queuebuilder doesn't need to create a new build record
142-in for pmount_0.1-1 in foobuntu.
143-
144-In the other hand there is a newer source for pmount published in
145-hoary and consequently in foobuntu:
146-
147-Note: This is a very unlikely situation, since ubuntu/hoary was marked
148-as RELEASED before build pmount_0.1-2 in the sampledata. So when we
149-try initialise a distroseries in another distribution based on hoary,
150-since they have independent archives (pool), pmount_0.1-1 binary
151-becomes a NBS (not build from source) since the pmount_0.1-1 source
152-was superseded in hoary and won't be inherited by the initialised
153-distroseries.
154-
155- >>> pmount_source = hoary.getSourcePackage('pmount').currentrelease
156- >>> print pmount_source.title
157- "pmount" 0.1-2 source package in The Hoary Hedgehog Release
158-
159- >>> pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
160- >>> print pmount_source.title
161- "pmount" 0.1-2 source package in The Foobuntu
162-
163-
164-Since pmount_0.1-2 source is published we can safely look up for the
165-respective build record:
166-
167- >>> pmount_source.sourcepackagerelease.getBuildByArch(
168- ... foobuntu['i386'], ubuntu.main_archive) is None
169- True
170-
171-It's not present, Let's create it to check if getBuildByArch responds
172-appropriately (we won't care about the source architecturehintlist in
173-this test, see more details in buildd-queuebuilder)
174-
175- >>> from lp.registry.interfaces.pocket import PackagePublishingPocket
176- >>> created_build = pmount_source.sourcepackagerelease.createBuild(
177- ... foobuntu['i386'], PackagePublishingPocket.RELEASE,
178- ... ubuntu.main_archive)
179-
180- >>> retrieved_build = pmount_source.sourcepackagerelease.getBuildByArch(
181- ... foobuntu['i386'], ubuntu.main_archive)
182-
183- >>> retrieved_build.id == created_build.id
184- True
185-
186- >>> pmount_source.sourcepackagerelease.getBuildByArch(
187- ... foobuntu['hppa'], ubuntu.main_archive) is None
188- True
189-
190-initialiseFromParent also copies the permitted source formats from the
191-parent series.
192-
193- >>> from lp.soyuz.interfaces.sourcepackageformat import SourcePackageFormat
194- >>> foobuntu.isSourcePackageFormatPermitted(SourcePackageFormat.FORMAT_1_0)
195- True
196
197=== added file 'lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py'
198--- lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 1970-01-01 00:00:00 +0000
199+++ lib/lp/soyuz/scripts/tests/test_initialise_distroseries.py 2010-08-12 13:50:27 +0000
200@@ -0,0 +1,183 @@
201+# Copyright 2010 Canonical Ltd. This software is licensed under the
202+# GNU Affero General Public License version 3 (see the file LICENSE).
203+
204+"""Test the initialise_distroseries script machinery."""
205+
206+__metaclass__ = type
207+
208+import os
209+import subprocess
210+import sys
211+import transaction
212+from zope.component import getUtility
213+
214+from lp.buildmaster.interfaces.buildbase import BuildStatus
215+from lp.registry.interfaces.pocket import PackagePublishingPocket
216+from lp.soyuz.interfaces.sourcepackageformat import SourcePackageFormat
217+from lp.soyuz.scripts.initialise_distroseries import (
218+ InitialiseDistroSeries, InitialisationError)
219+from lp.testing import TestCaseWithFactory
220+
221+from canonical.config import config
222+from canonical.launchpad.interfaces import IDistributionSet
223+from canonical.launchpad.ftests import login
224+from canonical.testing.layers import LaunchpadZopelessLayer
225+
226+
227+class TestInitialiseDistroSeries(TestCaseWithFactory):
228+
229+ layer = LaunchpadZopelessLayer
230+
231+ def setUp(self):
232+ super(TestInitialiseDistroSeries, self).setUp()
233+ login("foo.bar@canonical.com")
234+ distribution_set = getUtility(IDistributionSet)
235+ self.ubuntutest = distribution_set['ubuntutest']
236+ self.ubuntu = distribution_set['ubuntu']
237+ self.hoary = self.ubuntu['hoary']
238+
239+ def _create_distroseries(self, parent_series):
240+ return self.ubuntutest.newSeries(
241+ 'foobuntu', 'FooBuntu', 'The Foobuntu', 'yeck', 'doom',
242+ '888', parent_series, self.hoary.owner)
243+
244+ def _set_pending_to_failed(self, distroseries):
245+ pending_builds = distroseries.getBuildRecords(
246+ BuildStatus.NEEDSBUILD, pocket=PackagePublishingPocket.RELEASE)
247+ for build in pending_builds:
248+ build.status = BuildStatus.FAILEDTOBUILD
249+
250+ def test_failure_with_no_parent_series(self):
251+ # Initialising a new distro series requires a parent series to be set
252+ foobuntu = self._create_distroseries(None)
253+ ids = InitialiseDistroSeries(foobuntu)
254+ self.assertRaisesWithContent(
255+ InitialisationError, "Parent series required.", ids.check)
256+
257+ def test_failure_for_already_released_distroseries(self):
258+ # Initialising a distro series that has already been used will error
259+ ids = InitialiseDistroSeries(self.ubuntutest['breezy-autotest'])
260+ self.assertRaisesWithContent(
261+ InitialisationError,
262+ "Can not copy distroarchseries from parent, there are already "
263+ "distroarchseries(s) initialised for this series.", ids.check)
264+
265+ def test_failure_with_pending_builds(self):
266+ # If the parent series has pending builds, we can't initialise
267+ foobuntu = self._create_distroseries(self.hoary)
268+ transaction.commit()
269+ ids = InitialiseDistroSeries(foobuntu)
270+ self.assertRaisesWithContent(
271+ InitialisationError, "Parent series has pending builds.",
272+ ids.check)
273+
274+ def test_failure_with_queue_items(self):
275+ # If the parent series has items in its queues, such as NEW and
276+ # UNAPPROVED, we can't initialise
277+ foobuntu = self._create_distroseries(
278+ self.ubuntu['breezy-autotest'])
279+ ids = InitialiseDistroSeries(foobuntu)
280+ self.assertRaisesWithContent(
281+ InitialisationError,"Parent series queues are not empty.",
282+ ids.check)
283+
284+ def assertDistroSeriesInitialisedCorrectly(self, foobuntu):
285+ # Check that 'pmount' has been copied correctly
286+ hoary_pmount_pubs = self.hoary.getPublishedReleases('pmount')
287+ foobuntu_pmount_pubs = foobuntu.getPublishedReleases('pmount')
288+ self.assertEqual(len(hoary_pmount_pubs), len(foobuntu_pmount_pubs))
289+ hoary_i386_pmount_pubs = self.hoary['i386'].getReleasedPackages(
290+ 'pmount')
291+ foobuntu_i386_pmount_pubs = foobuntu['i386'].getReleasedPackages(
292+ 'pmount')
293+ self.assertEqual(
294+ len(hoary_i386_pmount_pubs), len(foobuntu_i386_pmount_pubs))
295+ # And the binary package, and linked source package look fine too
296+ pmount_binrel = (
297+ foobuntu['i386'].getReleasedPackages(
298+ 'pmount')[0].binarypackagerelease)
299+ self.assertEqual(pmount_binrel.title, u'pmount-0.1-1')
300+ self.assertEqual(pmount_binrel.build.id, 7)
301+ self.assertEqual(
302+ pmount_binrel.build.title,
303+ u'i386 build of pmount 0.1-1 in ubuntu hoary RELEASE')
304+ pmount_srcrel = pmount_binrel.build.source_package_release
305+ self.assertEqual(pmount_srcrel.title, u'pmount - 0.1-1')
306+ # The build of pmount 0.1-1 has been copied across.
307+ foobuntu_pmount = pmount_srcrel.getBuildByArch(
308+ foobuntu['i386'], foobuntu.main_archive)
309+ hoary_pmount = pmount_srcrel.getBuildByArch(
310+ self.hoary['i386'], self.hoary.main_archive)
311+ self.assertEqual(foobuntu_pmount.id, hoary_pmount.id)
312+ # We also inherient the permitted source formats from our parent
313+ self.assertTrue(
314+ foobuntu.isSourcePackageFormatPermitted(
315+ SourcePackageFormat.FORMAT_1_0))
316+
317+ def _full_initialise(self):
318+ foobuntu = self._create_distroseries(self.hoary)
319+ self._set_pending_to_failed(self.hoary)
320+ transaction.commit()
321+ ids = InitialiseDistroSeries(foobuntu)
322+ ids.check()
323+ ids.initialise()
324+ return foobuntu
325+
326+ def test_initialise(self):
327+ # Test a full initialise with no errors
328+ foobuntu = self._full_initialise()
329+ self.assertDistroSeriesInitialisedCorrectly(foobuntu)
330+
331+ def test_check_no_builds(self):
332+ # Test that there is no build for pmount 0.1-2 in the
333+ # newly-initialised series.
334+ foobuntu = self._full_initialise()
335+ pmount_source = self.hoary.getSourcePackage(
336+ 'pmount').currentrelease
337+ self.assertEqual(
338+ pmount_source.title,
339+ '"pmount" 0.1-2 source package in The Hoary Hedgehog Release')
340+ pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
341+ self.assertEqual(
342+ pmount_source.title,
343+ '"pmount" 0.1-2 source package in The Foobuntu')
344+ self.assertEqual(
345+ pmount_source.sourcepackagerelease.getBuildByArch(
346+ foobuntu['i386'], foobuntu.main_archive), None)
347+ self.assertEqual(
348+ pmount_source.sourcepackagerelease.getBuildByArch(
349+ foobuntu['hppa'], foobuntu.main_archive), None)
350+
351+ def test_create_builds(self):
352+ # It turns out the sampledata of hoary includes pmount 0.1-1 as well
353+ # as pmount 0.1-2 source, and if foobuntu and hoary don't share a
354+ # pool, 0.1-1 will be marked as NBS and removed. So let's check that
355+ # builds can be created for foobuntu.
356+ foobuntu = self._full_initialise()
357+ pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
358+ created_build = pmount_source.sourcepackagerelease.createBuild(
359+ foobuntu['i386'], PackagePublishingPocket.RELEASE,
360+ foobuntu.main_archive)
361+ retrieved_build = pmount_source.sourcepackagerelease.getBuildByArch(
362+ foobuntu['i386'], foobuntu.main_archive)
363+ self.assertEqual(retrieved_build.id, created_build.id)
364+ self.assertEqual(
365+ 'i386 build of pmount 0.1-2 in ubuntutest foobuntu RELEASE',
366+ created_build.title)
367+
368+ def test_script(self):
369+ # Do an end-to-end test using the command-line tool
370+ foobuntu = self._create_distroseries(self.hoary)
371+ self._set_pending_to_failed(self.hoary)
372+ transaction.commit()
373+ ifp = os.path.join(
374+ config.root, 'scripts', 'ftpmaster-tools',
375+ 'initialise-from-parent.py')
376+ process = subprocess.Popen(
377+ [sys.executable, ifp, "-vv", "-d", "ubuntutest", "foobuntu"],
378+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
379+ stdout, stderr = process.communicate()
380+ self.assertEqual(process.returncode, 0)
381+ self.assertTrue(
382+ "DEBUG Committing transaction." in stderr.split('\n'))
383+ self.assertDistroSeriesInitialisedCorrectly(foobuntu)