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
=== removed file 'lib/lp/soyuz/doc/initialise-from-parent.txt'
--- lib/lp/soyuz/doc/initialise-from-parent.txt 2010-08-12 13:49:50 +0000
+++ lib/lp/soyuz/doc/initialise-from-parent.txt 1970-01-01 00:00:00 +0000
@@ -1,191 +0,0 @@
1Check the behaviour of the initialise_from_parent script. It basically
2calls IDistroSeries.initialiseFromParent method with experimental extra
3checks and tasks.
4
5We need to create an initialisable DistroSeries as a child of Ubuntu
6Hoary (we do it inside the ubuntutest distribution to avoid conflicts
7with other tests)
8
9 >>> from canonical.launchpad.interfaces import IDistributionSet
10 >>> from canonical.launchpad.ftests import login
11
12 >>> login("foo.bar@canonical.com")
13 >>> distribution_set = getUtility(IDistributionSet)
14 >>> ubuntutest = distribution_set['ubuntutest']
15 >>> ubuntu = distribution_set['ubuntu']
16 >>> hoary = ubuntu['hoary']
17
18 # XXX cprov 2006-05-29 bug=49133:
19 # New distroseries should be provided by IDistribution.
20 # This maybe affected by derivation design and is documented in bug.
21
22 >>> foobuntu = ubuntutest.newSeries('foobuntu', 'FooBuntu',
23 ... 'The Foobuntu', 'yeck', 'doom',
24 ... '888', hoary, hoary.owner)
25
26
27The script will check that there are no NEEDSBUILD builds in the parent
28distroseries' release pocket, so we need to tweak the status of the NEEDSBUILD
29builds that exist in Ubuntu Hoary in the sampledata:
30
31 >>> from lp.buildmaster.interfaces.buildbase import BuildStatus
32 >>> from lp.registry.interfaces.pocket import PackagePublishingPocket
33
34 >>> pending_builds = hoary.getBuildRecords(BuildStatus.NEEDSBUILD,
35 ... pocket=PackagePublishingPocket.RELEASE)
36 >>> for build in pending_builds:
37 ... build.status = BuildStatus.FAILEDTOBUILD
38
39 >>> import transaction
40 >>> transaction.commit()
41
42
43 >>> import subprocess
44 >>> import os
45 >>> import sys
46 >>> from canonical.config import config
47
48
49Check if it fails for an already released distroseries:
50
51 >>> script = os.path.join(config.root, "scripts", "ftpmaster-tools",
52 ... "initialise-from-parent.py")
53 >>> process = subprocess.Popen([sys.executable, script, "-vv",
54 ... "breezy-autotest"],
55 ... stdout=subprocess.PIPE,
56 ... stderr=subprocess.PIPE,)
57 >>> stdout, stderr = process.communicate()
58 >>> process.returncode
59 1
60 >>> print stderr
61 DEBUG Acquiring lock
62 DEBUG Initialising connection.
63 DEBUG Check empty mutable queues in parentseries
64 DEBUG Check for no pending builds in parentseries
65 DEBUG Copying distroarchseries from parent and setting nominatedarchindep.
66 ERROR Can not copy distroarchseries from parent, there are already distroarchseries(s) initialised for this series.
67 <BLANKLINE>
68
69Let's initialise the just created distroseries:
70
71 >>> process = subprocess.Popen([sys.executable, script, "-vv",
72 ... "-d", "ubuntutest", "foobuntu"],
73 ... stdout=subprocess.PIPE,
74 ... stderr=subprocess.PIPE,)
75 >>> stdout, stderr = process.communicate()
76 >>> process.returncode
77 0
78 >>> print stderr
79 DEBUG Acquiring lock
80 DEBUG Initialising connection.
81 DEBUG Check empty mutable queues in parentseries
82 DEBUG Check for no pending builds in parentseries
83 DEBUG Copying distroarchseries from parent and setting nominatedarchindep.
84 DEBUG initialising from parent, copying publishing records.
85 DEBUG Committing transaction.
86 DEBUG Releasing lock
87 <BLANKLINE>
88
89
90Checking the published sources and binaries of ubuntutest/foobuntu
91against its parent, ubuntu/hoary:
92
93 >>> hoary_pmount_pubs = hoary.getPublishedReleases('pmount')
94 >>> foobuntu_pmount_pubs = foobuntu.getPublishedReleases('pmount')
95 >>> len(foobuntu_pmount_pubs) == len(hoary_pmount_pubs)
96 True
97
98 >>> hoary_i386_pmount_pubs = hoary['i386'].getReleasedPackages('pmount')
99 >>> foobuntu_i386_pmount_pubs = (
100 ... foobuntu['i386'].getReleasedPackages('pmount'))
101 >>> len(foobuntu_i386_pmount_pubs) == len(hoary_i386_pmount_pubs)
102 True
103
104Check how the publication records behave in a just-initialise distroseries.
105First we get a binarypackagerelease published in foobuntu:
106
107 >>> pmount_binrel = (
108 ... foobuntu['i386'].getReleasedPackages(
109 ... 'pmount')[0].binarypackagerelease)
110 >>> pmount_binrel.title
111 u'pmount-0.1-1'
112
113Follow BPR.build and discover it was built in the parent series:
114
115 >>> pmount_binrel.build.id
116 7
117 >>> pmount_binrel.build.title
118 u'i386 build of pmount 0.1-1 in ubuntu hoary RELEASE'
119
120Now we obtain the sourcepackagerelease from the build:
121
122 >>> pmount_srcrel = pmount_binrel.build.source_package_release
123 >>> pmount_srcrel.title
124 u'pmount - 0.1-1'
125
126and check it the ISPR.getBuildByArch() would find out the same build
127record for foobuntu and it's parent series (hoary):
128
129 >>> foobuntu_pmount = pmount_srcrel.getBuildByArch(
130 ... foobuntu['i386'], foobuntu.main_archive)
131 >>> hoary_pmount = pmount_srcrel.getBuildByArch(
132 ... hoary['i386'], hoary.main_archive)
133
134 >>> foobuntu_pmount.id == hoary_pmount.id
135 True
136
137It means that queuebuilder doesn't need to create a new build record
138in for pmount_0.1-1 in foobuntu.
139
140In the other hand there is a newer source for pmount published in
141hoary and consequently in foobuntu:
142
143Note: This is a very unlikely situation, since ubuntu/hoary was marked
144as RELEASED before build pmount_0.1-2 in the sampledata. So when we
145try initialise a distroseries in another distribution based on hoary,
146since they have independent archives (pool), pmount_0.1-1 binary
147becomes a NBS (not build from source) since the pmount_0.1-1 source
148was superseded in hoary and won't be inherited by the initialised
149distroseries.
150
151 >>> pmount_source = hoary.getSourcePackage('pmount').currentrelease
152 >>> print pmount_source.title
153 "pmount" 0.1-2 source package in The Hoary Hedgehog Release
154
155 >>> pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
156 >>> print pmount_source.title
157 "pmount" 0.1-2 source package in The Foobuntu
158
159
160Since pmount_0.1-2 source is published we can safely look up for the
161respective build record:
162
163 >>> pmount_source.sourcepackagerelease.getBuildByArch(
164 ... foobuntu['i386'], ubuntu.main_archive) is None
165 True
166
167It's not present, Let's create it to check if getBuildByArch responds
168appropriately (we won't care about the source architecturehintlist in
169this test, see more details in buildd-queuebuilder)
170
171 >>> from lp.registry.interfaces.pocket import PackagePublishingPocket
172 >>> created_build = pmount_source.sourcepackagerelease.createBuild(
173 ... foobuntu['i386'], PackagePublishingPocket.RELEASE,
174 ... ubuntu.main_archive)
175
176 >>> retrieved_build = pmount_source.sourcepackagerelease.getBuildByArch(
177 ... foobuntu['i386'], ubuntu.main_archive)
178
179 >>> retrieved_build.id == created_build.id
180 True
181
182 >>> pmount_source.sourcepackagerelease.getBuildByArch(
183 ... foobuntu['hppa'], ubuntu.main_archive) is None
184 True
185
186initialiseFromParent also copies the permitted source formats from the
187parent series.
188
189 >>> from lp.soyuz.interfaces.sourcepackageformat import SourcePackageFormat
190 >>> foobuntu.isSourcePackageFormatPermitted(SourcePackageFormat.FORMAT_1_0)
191 True
1920
=== 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-12 13:50:27 +0000
@@ -0,0 +1,183 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Test the initialise_distroseries script machinery."""
5
6__metaclass__ = type
7
8import os
9import subprocess
10import sys
11import transaction
12from zope.component import getUtility
13
14from lp.buildmaster.interfaces.buildbase import BuildStatus
15from lp.registry.interfaces.pocket import PackagePublishingPocket
16from lp.soyuz.interfaces.sourcepackageformat import SourcePackageFormat
17from lp.soyuz.scripts.initialise_distroseries import (
18 InitialiseDistroSeries, InitialisationError)
19from lp.testing import TestCaseWithFactory
20
21from canonical.config import config
22from canonical.launchpad.interfaces import IDistributionSet
23from canonical.launchpad.ftests import login
24from canonical.testing.layers import LaunchpadZopelessLayer
25
26
27class TestInitialiseDistroSeries(TestCaseWithFactory):
28
29 layer = LaunchpadZopelessLayer
30
31 def setUp(self):
32 super(TestInitialiseDistroSeries, self).setUp()
33 login("foo.bar@canonical.com")
34 distribution_set = getUtility(IDistributionSet)
35 self.ubuntutest = distribution_set['ubuntutest']
36 self.ubuntu = distribution_set['ubuntu']
37 self.hoary = self.ubuntu['hoary']
38
39 def _create_distroseries(self, parent_series):
40 return self.ubuntutest.newSeries(
41 'foobuntu', 'FooBuntu', 'The Foobuntu', 'yeck', 'doom',
42 '888', parent_series, self.hoary.owner)
43
44 def _set_pending_to_failed(self, distroseries):
45 pending_builds = distroseries.getBuildRecords(
46 BuildStatus.NEEDSBUILD, pocket=PackagePublishingPocket.RELEASE)
47 for build in pending_builds:
48 build.status = BuildStatus.FAILEDTOBUILD
49
50 def test_failure_with_no_parent_series(self):
51 # Initialising a new distro series requires a parent series to be set
52 foobuntu = self._create_distroseries(None)
53 ids = InitialiseDistroSeries(foobuntu)
54 self.assertRaisesWithContent(
55 InitialisationError, "Parent series required.", ids.check)
56
57 def test_failure_for_already_released_distroseries(self):
58 # Initialising a distro series that has already been used will error
59 ids = InitialiseDistroSeries(self.ubuntutest['breezy-autotest'])
60 self.assertRaisesWithContent(
61 InitialisationError,
62 "Can not copy distroarchseries from parent, there are already "
63 "distroarchseries(s) initialised for this series.", ids.check)
64
65 def test_failure_with_pending_builds(self):
66 # If the parent series has pending builds, we can't initialise
67 foobuntu = self._create_distroseries(self.hoary)
68 transaction.commit()
69 ids = InitialiseDistroSeries(foobuntu)
70 self.assertRaisesWithContent(
71 InitialisationError, "Parent series has pending builds.",
72 ids.check)
73
74 def test_failure_with_queue_items(self):
75 # If the parent series has items in its queues, such as NEW and
76 # UNAPPROVED, we can't initialise
77 foobuntu = self._create_distroseries(
78 self.ubuntu['breezy-autotest'])
79 ids = InitialiseDistroSeries(foobuntu)
80 self.assertRaisesWithContent(
81 InitialisationError,"Parent series queues are not empty.",
82 ids.check)
83
84 def assertDistroSeriesInitialisedCorrectly(self, foobuntu):
85 # Check that 'pmount' has been copied correctly
86 hoary_pmount_pubs = self.hoary.getPublishedReleases('pmount')
87 foobuntu_pmount_pubs = foobuntu.getPublishedReleases('pmount')
88 self.assertEqual(len(hoary_pmount_pubs), len(foobuntu_pmount_pubs))
89 hoary_i386_pmount_pubs = self.hoary['i386'].getReleasedPackages(
90 'pmount')
91 foobuntu_i386_pmount_pubs = foobuntu['i386'].getReleasedPackages(
92 'pmount')
93 self.assertEqual(
94 len(hoary_i386_pmount_pubs), len(foobuntu_i386_pmount_pubs))
95 # And the binary package, and linked source package look fine too
96 pmount_binrel = (
97 foobuntu['i386'].getReleasedPackages(
98 'pmount')[0].binarypackagerelease)
99 self.assertEqual(pmount_binrel.title, u'pmount-0.1-1')
100 self.assertEqual(pmount_binrel.build.id, 7)
101 self.assertEqual(
102 pmount_binrel.build.title,
103 u'i386 build of pmount 0.1-1 in ubuntu hoary RELEASE')
104 pmount_srcrel = pmount_binrel.build.source_package_release
105 self.assertEqual(pmount_srcrel.title, u'pmount - 0.1-1')
106 # The build of pmount 0.1-1 has been copied across.
107 foobuntu_pmount = pmount_srcrel.getBuildByArch(
108 foobuntu['i386'], foobuntu.main_archive)
109 hoary_pmount = pmount_srcrel.getBuildByArch(
110 self.hoary['i386'], self.hoary.main_archive)
111 self.assertEqual(foobuntu_pmount.id, hoary_pmount.id)
112 # We also inherient the permitted source formats from our parent
113 self.assertTrue(
114 foobuntu.isSourcePackageFormatPermitted(
115 SourcePackageFormat.FORMAT_1_0))
116
117 def _full_initialise(self):
118 foobuntu = self._create_distroseries(self.hoary)
119 self._set_pending_to_failed(self.hoary)
120 transaction.commit()
121 ids = InitialiseDistroSeries(foobuntu)
122 ids.check()
123 ids.initialise()
124 return foobuntu
125
126 def test_initialise(self):
127 # Test a full initialise with no errors
128 foobuntu = self._full_initialise()
129 self.assertDistroSeriesInitialisedCorrectly(foobuntu)
130
131 def test_check_no_builds(self):
132 # Test that there is no build for pmount 0.1-2 in the
133 # newly-initialised series.
134 foobuntu = self._full_initialise()
135 pmount_source = self.hoary.getSourcePackage(
136 'pmount').currentrelease
137 self.assertEqual(
138 pmount_source.title,
139 '"pmount" 0.1-2 source package in The Hoary Hedgehog Release')
140 pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
141 self.assertEqual(
142 pmount_source.title,
143 '"pmount" 0.1-2 source package in The Foobuntu')
144 self.assertEqual(
145 pmount_source.sourcepackagerelease.getBuildByArch(
146 foobuntu['i386'], foobuntu.main_archive), None)
147 self.assertEqual(
148 pmount_source.sourcepackagerelease.getBuildByArch(
149 foobuntu['hppa'], foobuntu.main_archive), None)
150
151 def test_create_builds(self):
152 # It turns out the sampledata of hoary includes pmount 0.1-1 as well
153 # as pmount 0.1-2 source, and if foobuntu and hoary don't share a
154 # pool, 0.1-1 will be marked as NBS and removed. So let's check that
155 # builds can be created for foobuntu.
156 foobuntu = self._full_initialise()
157 pmount_source = foobuntu.getSourcePackage('pmount').currentrelease
158 created_build = pmount_source.sourcepackagerelease.createBuild(
159 foobuntu['i386'], PackagePublishingPocket.RELEASE,
160 foobuntu.main_archive)
161 retrieved_build = pmount_source.sourcepackagerelease.getBuildByArch(
162 foobuntu['i386'], foobuntu.main_archive)
163 self.assertEqual(retrieved_build.id, created_build.id)
164 self.assertEqual(
165 'i386 build of pmount 0.1-2 in ubuntutest foobuntu RELEASE',
166 created_build.title)
167
168 def test_script(self):
169 # Do an end-to-end test using the command-line tool
170 foobuntu = self._create_distroseries(self.hoary)
171 self._set_pending_to_failed(self.hoary)
172 transaction.commit()
173 ifp = os.path.join(
174 config.root, 'scripts', 'ftpmaster-tools',
175 'initialise-from-parent.py')
176 process = subprocess.Popen(
177 [sys.executable, ifp, "-vv", "-d", "ubuntutest", "foobuntu"],
178 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
179 stdout, stderr = process.communicate()
180 self.assertEqual(process.returncode, 0)
181 self.assertTrue(
182 "DEBUG Committing transaction." in stderr.split('\n'))
183 self.assertDistroSeriesInitialisedCorrectly(foobuntu)