Merge lp:~michael.nelson/launchpad/ppa-privatisation-test-refactor2 into lp:launchpad

Proposed by Michael Nelson on 2010-02-19
Status: Merged
Approved by: Michael Nelson on 2010-02-22
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~michael.nelson/launchpad/ppa-privatisation-test-refactor2
Merge into: lp:launchpad
Prerequisite: lp:~michael.nelson/launchpad/ppa-privatisation-test-refactor
Diff against target: 525 lines (+101/-84)
7 files modified
lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py (+26/-24)
lib/lp/buildmaster/tests/test_builder.py (+17/-6)
lib/lp/soyuz/scripts/tests/test_copypackage.py (+19/-17)
lib/lp/soyuz/scripts/tests/test_expire_ppa_bins.py (+14/-13)
lib/lp/soyuz/scripts/tests/test_populatearchive.py (+10/-13)
lib/lp/soyuz/scripts/tests/test_publishdistro.py (+6/-8)
lib/lp/testing/factory.py (+9/-3)
To merge this branch: bzr merge lp:~michael.nelson/launchpad/ppa-privatisation-test-refactor2
Reviewer Review Type Date Requested Status
Guilherme Salgado (community) code 2010-02-19 Approve on 2010-02-19
Review via email: mp+19696@code.launchpad.net
To post a comment you must log in.
Michael Nelson (michael.nelson) wrote :

This is the second branch in a series to refactor soyuz tests after fixing bug 506203.

The MP for the branch that actually fixed the bug is at:

https://code.edge.launchpad.net/~michael.nelson/launchpad/506203-ppa-privatisation-check/+merge/19415

The fix ensures that the privacy of a PPA cannot be altered once it has packages published. Unfortunately most of our test infrastructure does exactly that (switches the privacy to do a few tests and then switches it back).

The complete test breakages are as follows:
http://pastebin.ubuntu.com/378292/

This branch fixes:

bin/test -vv -t TestPPAHtaccessTokenGeneration -t TestFindBuildCandidatePrivatePPA -t CopyPackageTestCase -t TestPPABinaryExpiry -t TestPopulateArchiveScript -t TestPublishDistro

Thanks.

Guilherme Salgado (salgado) wrote :
Download full text (6.0 KiB)

Hi Michael,

This is a very nice branch; thanks a lot for changing the tests to rely
on less sample data. I only have a few remarks, but it's good to go.

 review approve code

On Fri, 2010-02-19 at 11:48 +0000, Michael Nelson wrote:
>
> This is the second branch in a series to refactor soyuz tests after
> fixing bug 506203.
>
> The MP for the branch that actually fixed the bug is at:
>
> https://code.edge.launchpad.net/~michael.nelson/launchpad/506203-ppa-privatisation-check/+merge/19415
>
> The fix ensures that the privacy of a PPA cannot be altered once it
> has packages published. Unfortunately most of our test infrastructure
> does exactly that (switches the privacy to do a few tests and then
> switches it back).
>

> === modified file 'lib/lp/buildmaster/tests/test_builder.py'
> --- lib/lp/buildmaster/tests/test_builder.py 2010-02-05 15:06:28 +0000
> +++ lib/lp/buildmaster/tests/test_builder.py 2010-02-19 11:48:25 +0000
> @@ -119,14 +119,22 @@
> build.builder = self.builders[count]
> count += 1
>
> - def setUp(self):
> - """Publish some builds for the test archive."""
> - super(TestFindBuildCandidatePPA, self).setUp()
> + def createPPAs(self):
> + """Helper to create the PPAs for this test.
>
> + This is here only so that it can be overridden for a subsequent
> + private PPA test, privatising the PPA before any packages
> + are published."""
> # Create two PPAs and add some builds to each.

Will the makeArchive() call actually add builds to the PPAs?

> self.ppa_joe = self.factory.makeArchive(name="joesppa")
> self.ppa_jim = self.factory.makeArchive(name="jimsppa")
>
> + def setUp(self):
> + """Publish some builds for the test archive."""
> + super(TestFindBuildCandidatePPA, self).setUp()
> +
> + self.createPPAs()
> +
> self.joe_builds = []
> self.joe_builds.extend(
> self.publisher.getPubSource(
> @@ -183,11 +191,19 @@
> build = getUtility(IBuildSet).getByQueueEntry(next_job)
> self.failUnlessEqual('joesppa', build.archive.name)
>
> +
> +class TestFindBuildCandidatePrivatePPA(TestFindBuildCandidatePPA):
> +
> + def createPPAs(self):
> + """Overridden to ensure that joe's ppa is privatised before any
> + packages are published."""
> + super(TestFindBuildCandidatePrivatePPA, self).createPPAs()
> + self.ppa_joe.private = True
> + self.ppa_joe.buildd_secret = 'sekrit'
> +
> def test_findBuildCandidate_for_private_ppa(self):
> # If a ppa is private it will be able to have parallel builds
> # for the one architecture.
> - self.ppa_joe.private = True
> - self.ppa_joe.buildd_secret = 'sekrit'
> next_job = removeSecurityProxy(self.builder4)._findBuildCandidate()
> build = getUtility(IBuildSet).getByQueueEntry(next_job)
> self.failUnlessEqual('joesppa', build.archive.name)
>

> === modified file 'lib/lp/soyuz/scripts/tests/test_populatearchive.py'
> --- lib/lp/soyuz/scripts/tests/test_populatearchive.py 2010-02-11 06:22:38 +0000
> +++ lib/lp/soyuz...

Read more...

review: Approve (code)
Michael Nelson (michael.nelson) wrote :
Download full text (4.0 KiB)

On Fri, Feb 19, 2010 at 2:06 PM, Guilherme Salgado
<email address hidden> wrote:
> Review: Approve code
> Hi Michael,
>
> This is a very nice branch; thanks a lot for changing the tests to rely
> on less sample data.  I only have a few remarks, but it's good to go.
>

Thanks Guilherme. One note below.

>  review approve code
>
> On Fri, 2010-02-19 at 11:48 +0000, Michael Nelson wrote:
...
>> === modified file 'lib/lp/buildmaster/tests/test_builder.py'
>> --- lib/lp/buildmaster/tests/test_builder.py    2010-02-05 15:06:28 +0000
>> +++ lib/lp/buildmaster/tests/test_builder.py    2010-02-19 11:48:25 +0000
>> @@ -119,14 +119,22 @@
>>                  build.builder = self.builders[count]
>>              count += 1
>>
>> -    def setUp(self):
>> -        """Publish some builds for the test archive."""
>> -        super(TestFindBuildCandidatePPA, self).setUp()
>> +    def createPPAs(self):
>> +        """Helper to create the PPAs for this test.
>>
>> +        This is here only so that it can be overridden for a subsequent
>> +        private PPA test, privatising the PPA before any packages
>> +        are published."""
>>          # Create two PPAs and add some builds to each.
>
> Will the makeArchive() call actually add builds to the PPAs?

Hrm, I'm guessing you reviewed r10333 rather than r10334, as I
actually had to refactor the way that test was setup due to a failure.
You might like to take a look at the diff for r10334. The above
comment is now in the context of the creation and adding of builds.

>
>>          self.ppa_joe = self.factory.makeArchive(name="joesppa")
>>          self.ppa_jim = self.factory.makeArchive(name="jimsppa")
>>
>> +    def setUp(self):
>> +        """Publish some builds for the test archive."""
>> +        super(TestFindBuildCandidatePPA, self).setUp()
>> +
>> +        self.createPPAs()
>> +
>>          self.joe_builds = []
>>          self.joe_builds.extend(
>>              self.publisher.getPubSource(
>> @@ -183,11 +191,19 @@
>>          build = getUtility(IBuildSet).getByQueueEntry(next_job)
>>          self.failUnlessEqual('joesppa', build.archive.name)
>>
>> +
>> +class TestFindBuildCandidatePrivatePPA(TestFindBuildCandidatePPA):
>> +
>> +    def createPPAs(self):
>> +        """Overridden to ensure that joe's ppa is privatised before any
>> +        packages are published."""
>> +        super(TestFindBuildCandidatePrivatePPA, self).createPPAs()
>> +        self.ppa_joe.private = True
>> +        self.ppa_joe.buildd_secret = 'sekrit'
>> +
>>      def test_findBuildCandidate_for_private_ppa(self):
>>          # If a ppa is private it will be able to have parallel builds
>>          # for the one architecture.
>> -        self.ppa_joe.private = True
>> -        self.ppa_joe.buildd_secret = 'sekrit'
>>          next_job = removeSecurityProxy(self.builder4)._findBuildCandidate()
>>          build = getUtility(IBuildSet).getByQueueEntry(next_job)
>>          self.failUnlessEqual('joesppa', build.archive.name)
>>
>
>> === modified file 'lib/lp/soyuz/scripts/tests/test_populatearchive.py'
>> --- lib/lp/soyuz/scripts/tests/test_populatearchive.py  2010-02-11 06:22:38 +0000
>> +++ lib/lp/soyuz/scripts/tests/test_populat...

Read more...

1=== modified file 'lib/lp/soyuz/scripts/tests/test_populatearchive.py'
2--- lib/lp/soyuz/scripts/tests/test_populatearchive.py 2010-02-19 11:25:35 +0000
3+++ lib/lp/soyuz/scripts/tests/test_populatearchive.py 2010-02-19 13:38:33 +0000
4@@ -690,7 +690,7 @@
5 The copying of packages from private archives to public ones
6 thus constitutes a security breach.
7 """
8- # We will make cprov's PPA private and then attempt to copy from it.
9+ # We will make a private PPA and then attempt to copy from it.
10 joe = self.factory.makePerson(name='joe')
11 ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
12 joes_private_ppa = self.factory.makeArchive(
Guilherme Salgado (salgado) wrote :

On Fri, 2010-02-19 at 13:42 +0000, Michael Nelson wrote:
> On Fri, Feb 19, 2010 at 2:06 PM, Guilherme Salgado
> <email address hidden> wrote:
> > Review: Approve code
> > Hi Michael,
> >
> > This is a very nice branch; thanks a lot for changing the tests to rely
> > on less sample data. I only have a few remarks, but it's good to go.
> >
>
> Thanks Guilherme. One note below.
>
> > review approve code
> >
> > On Fri, 2010-02-19 at 11:48 +0000, Michael Nelson wrote:
> ...
> >> === modified file 'lib/lp/buildmaster/tests/test_builder.py'
> >> --- lib/lp/buildmaster/tests/test_builder.py 2010-02-05 15:06:28 +0000
> >> +++ lib/lp/buildmaster/tests/test_builder.py 2010-02-19 11:48:25 +0000
> >> @@ -119,14 +119,22 @@
> >> build.builder = self.builders[count]
> >> count += 1
> >>
> >> - def setUp(self):
> >> - """Publish some builds for the test archive."""
> >> - super(TestFindBuildCandidatePPA, self).setUp()
> >> + def createPPAs(self):
> >> + """Helper to create the PPAs for this test.
> >>
> >> + This is here only so that it can be overridden for a subsequent
> >> + private PPA test, privatising the PPA before any packages
> >> + are published."""
> >> # Create two PPAs and add some builds to each.
> >
> > Will the makeArchive() call actually add builds to the PPAs?
>
> Hrm, I'm guessing you reviewed r10333 rather than r10334, as I
> actually had to refactor the way that test was setup due to a failure.
> You might like to take a look at the diff for r10334. The above
> comment is now in the context of the creation and adding of builds.

Yeah, I've reviewed the diff that was sent by email together with the
m-p notification. I'll file a bug asking for an email to be sent when
there's a new revision added to a branch for with a m-p exists.

Anyway, I've just checked the diff for f10334 and it looks good.

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_generate_ppa_htaccess.py'
2--- lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py 2009-08-27 02:00:29 +0000
3+++ lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py 2010-02-26 15:32:18 +0000
4@@ -26,21 +26,23 @@
5 HtaccessTokenGenerator)
6 from lp.soyuz.interfaces.archivesubscriber import (
7 ArchiveSubscriberStatus)
8-from lp.testing.factory import LaunchpadObjectFactory
9+from lp.testing import TestCaseWithFactory
10 from lp.testing.mail_helpers import pop_notifications
11 from lp.services.mail import stub
12
13
14-class TestPPAHtaccessTokenGeneration(unittest.TestCase):
15+class TestPPAHtaccessTokenGeneration(TestCaseWithFactory):
16 """Test the generate_ppa_htaccess.py script."""
17
18 layer = LaunchpadZopelessLayer
19 dbuser = config.generateppahtaccess.dbuser
20
21 def setUp(self):
22- self.ppa = getUtility(IPersonSet).getByName('cprov').archive
23- self.ppa.private = True
24- self.ppa.buildd_secret = "secret"
25+ super(TestPPAHtaccessTokenGeneration, self).setUp()
26+ self.owner = self.factory.makePerson(
27+ name="joe", displayname="Joe Smith")
28+ self.ppa = self.factory.makeArchive(
29+ owner=self.owner, name="myppa", private=True)
30
31 # "Ubuntu" doesn't have a proper publisher config but Ubuntutest
32 # does, so override the PPA's distro here.
33@@ -60,7 +62,7 @@
34
35 def runScript(self):
36 """Run the expiry script.
37-
38+
39 :return: a tuple of return code, stdout and stderr.
40 """
41 script = os.path.join(
42@@ -148,7 +150,7 @@
43 # Generate the passwd file.
44 script = self.getScript()
45 filename = script.generateHtpasswd(self.ppa, tokens)
46-
47+
48 # It should be a temp file in the same directory as the intended
49 # target file when it's renamed, so that os.rename() won't
50 # complain about renaming across file systems.
51@@ -159,7 +161,7 @@
52 # Read it back in.
53 file = open(filename, "r")
54 file_contents = file.read().splitlines()
55-
56+
57 # The first line should be the buildd_secret.
58 [user, password] = file_contents[0].split(":", 1)
59 self.assertEqual(user, "buildd")
60@@ -179,7 +181,7 @@
61 # For the names to appear in the order above, the dabatase IDs
62 # for the tokens have to be in that order. (To ensure a
63 # consistent ordering)
64- self.assertTrue(tokens[0].id < tokens[1].id)
65+ self.assertTrue(tokens[0].id < tokens[1].id)
66
67 os.remove(filename)
68
69@@ -237,32 +239,31 @@
70 # - All members of a team lose their tokens when a team of a
71 # subscribed team leaves it.
72
73- factory = LaunchpadObjectFactory()
74 persons1 = []
75 persons2 = []
76 name12 = getUtility(IPersonSet).getByName("name12")
77- team1 = factory.makeTeam(owner=name12)
78- team2 = factory.makeTeam(owner=name12)
79+ team1 = self.factory.makeTeam(owner=name12)
80+ team2 = self.factory.makeTeam(owner=name12)
81 for count in range(5):
82- person = factory.makePerson()
83+ person = self.factory.makePerson()
84 team1.addMember(person, name12)
85 persons1.append(person)
86- person = factory.makePerson()
87+ person = self.factory.makePerson()
88 team2.addMember(person, name12)
89 persons2.append(person)
90
91 all_persons = persons1 + persons2
92
93- parent_team = factory.makeTeam(owner=name12)
94+ parent_team = self.factory.makeTeam(owner=name12)
95 # This needs to be forced or TeamParticipation is not updated.
96 parent_team.addMember(team2, name12, force_team_add=True)
97
98- promiscuous_person = factory.makePerson()
99+ promiscuous_person = self.factory.makePerson()
100 team1.addMember(promiscuous_person, name12)
101 team2.addMember(promiscuous_person, name12)
102 all_persons.append(promiscuous_person)
103
104- lonely_person = factory.makePerson()
105+ lonely_person = self.factory.makePerson()
106 all_persons.append(lonely_person)
107
108 # At this point we have team1, with 5 people in it, team2 with 5
109@@ -411,7 +412,7 @@
110 # .htpasswd.
111 return_code, stdout, stderr = self.runScript()
112 self.assertEqual(
113- return_code, 0, "Got a bad return code of %s\nOutput:\n%s" %
114+ return_code, 0, "Got a bad return code of %s\nOutput:\n%s" %
115 (return_code, stderr))
116 self.assertTrue(os.path.isfile(htaccess))
117 self.assertTrue(os.path.isfile(htpasswd))
118@@ -464,7 +465,7 @@
119 self.assertEqual(subs[0].status, ArchiveSubscriberStatus.CURRENT)
120
121 script = self.getScript()
122- script.blacklist = {'cprov': ['my_other_ppa', 'ppa', 'and_another']}
123+ script.blacklist = {'joe': ['my_other_ppa', 'myppa', 'and_another']}
124 script.main()
125
126 # The tokens will still be deactivated, and subscriptions expired.
127@@ -477,7 +478,7 @@
128
129 def testSendingCancellationEmail(self):
130 """Test that when a token is deactivated, its user gets an email.
131-
132+
133 The email must contain the right headers and text.
134 """
135 subs, tokens = self.setupDummyTokens()
136@@ -495,10 +496,11 @@
137 [email] = pop_notifications()
138 self.assertEqual(
139 email['Subject'],
140- "PPA access cancelled for PPA for Celso Providelo")
141+ "PPA access cancelled for PPA named myppa for Joe Smith")
142 self.assertEqual(email['To'], "test@canonical.com")
143 self.assertEqual(
144- email['From'], "PPA for Celso Providelo <noreply@launchpad.net>")
145+ email['From'],
146+ "PPA named myppa for Joe Smith <noreply@launchpad.net>")
147 self.assertEqual(email['Sender'], "bounces@canonical.com")
148
149 body = email.get_payload()
150@@ -508,7 +510,7 @@
151 "Launchpad: cancellation of archive access\n"
152 "-----------------------------------------\n\n"
153 "Your access to the private software archive "
154- "\"PPA for Celso Providelo\",\n"
155+ "\"PPA named myppa for Joe\nSmith\", "
156 "which is hosted by Launchpad, has been "
157 "cancelled.\n\n"
158 "You will now no longer be able to download software from this "
159@@ -518,7 +520,7 @@
160 "of the archive to verify it.\n\n"
161 "You can contact the archive owner by visiting their Launchpad "
162 "page here:\n\n"
163- "<http://launchpad.dev/~cprov>\n\n"
164+ "<http://launchpad.dev/~joe>\n\n"
165 "If you have any concerns you can contact the Launchpad team by "
166 "emailing\n"
167 "feedback@launchpad.net\n\n"
168
169=== modified file 'lib/lp/buildmaster/tests/test_builder.py'
170--- lib/lp/buildmaster/tests/test_builder.py 2010-02-05 15:06:28 +0000
171+++ lib/lp/buildmaster/tests/test_builder.py 2010-02-26 15:32:18 +0000
172@@ -103,7 +103,10 @@
173 self.assertEqual('joesppa', build.archive.name)
174
175
176-class TestFindBuildCandidatePPA(TestFindBuildCandidateBase):
177+class TestFindBuildCandidatePPABase(TestFindBuildCandidateBase):
178+
179+ ppa_joe_private = False
180+ ppa_jim_private = False
181
182 def _setBuildsBuildingForArch(self, builds_list, num_builds,
183 archtag="i386"):
184@@ -121,11 +124,13 @@
185
186 def setUp(self):
187 """Publish some builds for the test archive."""
188- super(TestFindBuildCandidatePPA, self).setUp()
189+ super(TestFindBuildCandidatePPABase, self).setUp()
190
191 # Create two PPAs and add some builds to each.
192- self.ppa_joe = self.factory.makeArchive(name="joesppa")
193- self.ppa_jim = self.factory.makeArchive(name="jimsppa")
194+ self.ppa_joe = self.factory.makeArchive(
195+ name="joesppa", private=self.ppa_joe_private)
196+ self.ppa_jim = self.factory.makeArchive(
197+ name="jimsppa", private=self.ppa_jim_private)
198
199 self.joe_builds = []
200 self.joe_builds.extend(
201@@ -168,6 +173,9 @@
202 num_free_builders = len(self.builders) - num_active_builders
203 self.assertEqual(num_free_builders, 2)
204
205+
206+class TestFindBuildCandidatePPA(TestFindBuildCandidatePPABase):
207+
208 def test_findBuildCandidate_first_build_started(self):
209 # A PPA cannot start a build if it would use 80% or more of the
210 # builders.
211@@ -183,11 +191,14 @@
212 build = getUtility(IBuildSet).getByQueueEntry(next_job)
213 self.failUnlessEqual('joesppa', build.archive.name)
214
215+
216+class TestFindBuildCandidatePrivatePPA(TestFindBuildCandidatePPABase):
217+
218+ ppa_joe_private = True
219+
220 def test_findBuildCandidate_for_private_ppa(self):
221 # If a ppa is private it will be able to have parallel builds
222 # for the one architecture.
223- self.ppa_joe.private = True
224- self.ppa_joe.buildd_secret = 'sekrit'
225 next_job = removeSecurityProxy(self.builder4)._findBuildCandidate()
226 build = getUtility(IBuildSet).getByQueueEntry(next_job)
227 self.failUnlessEqual('joesppa', build.archive.name)
228
229=== modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
230--- lib/lp/soyuz/scripts/tests/test_copypackage.py 2010-01-20 15:41:25 +0000
231+++ lib/lp/soyuz/scripts/tests/test_copypackage.py 2010-02-26 15:32:18 +0000
232@@ -1225,7 +1225,7 @@
233 self.assertEqual(num_bin_pub + 4, num_bin_pub_after)
234
235
236-class CopyPackageTestCase(TestCase):
237+class CopyPackageTestCase(TestCaseWithFactory):
238 """Test the CopyPackageHelper class."""
239 layer = LaunchpadZopelessLayer
240 dbuser = config.archivepublisher.dbuser
241@@ -2148,30 +2148,31 @@
242 def testCopyFromPrivateToPublicPPAs(self):
243 """Copies from private to public archives are allowed."""
244 # Set up a private PPA.
245- cprov = getUtility(IPersonSet).getByName("cprov")
246- cprov.archive.buildd_secret = "secret"
247- cprov.archive.private = True
248+ joe = self.factory.makePerson(name="joe")
249+ ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
250+ joe_private_ppa = self.factory.makeArchive(
251+ owner=joe, name='ppa', private=True,
252+ distribution=ubuntu)
253
254 # Create a source and binary private publication.
255- ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
256 hoary = ubuntu.getSeries('hoary')
257 test_publisher = self.getTestPublisher(hoary)
258 ppa_source = test_publisher.getPubSource(
259- archive=cprov.archive, version='1.0', distroseries=hoary)
260+ archive=joe_private_ppa, version='1.0', distroseries=hoary)
261 ppa_binaries = test_publisher.getPubBinaries(
262 pub_source=ppa_source, distroseries=hoary)
263 self.layer.txn.commit()
264
265 # Run the copy package script storing the logged information.
266 copy_helper = self.getCopier(
267- sourcename='foo', from_ppa='cprov', include_binaries=True,
268- from_suite='hoary', to_suite='hoary')
269+ sourcename='foo', from_ppa='joe',
270+ include_binaries=True, from_suite='hoary', to_suite='hoary')
271 copied = copy_helper.mainTask()
272
273 # The private files are copied via a delayed-copy request.
274 self.assertEqual(len(copied), 1)
275 self.assertEqual(
276- ['INFO: FROM: cprov: hoary-RELEASE',
277+ ['INFO: FROM: joe: hoary-RELEASE',
278 'INFO: TO: Primary Archive for Ubuntu Linux: hoary-RELEASE',
279 'INFO: Copy candidates:',
280 'INFO: \tfoo 1.0 in hoary',
281@@ -2186,23 +2187,24 @@
282 def testUnembargoing(self):
283 """Test UnembargoSecurityPackage, which wraps PackagerCopier."""
284 # Set up a private PPA.
285- cprov = getUtility(IPersonSet).getByName("cprov")
286- cprov.archive.buildd_secret = "secret"
287- cprov.archive.private = True
288+ joe = self.factory.makePerson(name="joe")
289+ ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
290+ joe_private_ppa = self.factory.makeArchive(
291+ owner=joe, name='ppa', private=True,
292+ distribution=ubuntu)
293
294 # Setup a SoyuzTestPublisher object, so we can create publication
295 # to be unembargoed.
296- ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
297 warty = ubuntu.getSeries('warty')
298 test_publisher = self.getTestPublisher(warty)
299
300 # Create a source and binary pair to be unembargoed from the PPA.
301 ppa_source = test_publisher.getPubSource(
302- archive=cprov.archive, version='1.1',
303+ archive=joe_private_ppa, version='1.1',
304 distroseries=warty,
305 status=PackagePublishingStatus.PUBLISHED)
306 other_source = test_publisher.getPubSource(
307- archive=cprov.archive, version='1.1',
308+ archive=joe_private_ppa, version='1.1',
309 sourcename="sourcefordiff", distroseries=warty,
310 status=PackagePublishingStatus.PUBLISHED)
311 test_publisher.addFakeChroots(warty)
312@@ -2214,7 +2216,7 @@
313 sourcepackagerelease = other_source.sourcepackagerelease
314 diff_file = test_publisher.addMockFile("diff_file", restricted=True)
315 package_diff = sourcepackagerelease.requestDiffTo(
316- cprov, ppa_source.sourcepackagerelease)
317+ joe, ppa_source.sourcepackagerelease)
318 package_diff.diff_content = diff_file
319
320 # Prepare a *restricted* buildlog file for the Build instances.
321@@ -2245,7 +2247,7 @@
322
323 # Now we can invoke the unembargo script and check its results.
324 test_args = [
325- "--ppa", "cprov",
326+ "--ppa", "joe",
327 "--ppa-name", "ppa",
328 "-s", "%s" % ppa_source.distroseries.name + "-security",
329 "foo"
330
331=== modified file 'lib/lp/soyuz/scripts/tests/test_expire_ppa_bins.py'
332--- lib/lp/soyuz/scripts/tests/test_expire_ppa_bins.py 2010-01-17 09:15:43 +0000
333+++ lib/lp/soyuz/scripts/tests/test_expire_ppa_bins.py 2010-02-26 15:32:18 +0000
334@@ -4,22 +4,24 @@
335 """Test the expire-ppa-binaries.py script. """
336
337 import pytz
338+
339+from datetime import datetime, timedelta
340+
341 import unittest
342
343-from datetime import datetime, timedelta
344-
345 from zope.component import getUtility
346
347 from canonical.config import config
348+from canonical.launchpad.scripts import QuietFakeLogger
349+from canonical.testing.layers import LaunchpadZopelessLayer
350 from lp.registry.interfaces.distribution import IDistributionSet
351 from lp.registry.interfaces.person import IPersonSet
352-from canonical.launchpad.scripts import QuietFakeLogger
353 from lp.soyuz.scripts.expire_ppa_binaries import PPABinaryExpirer
354 from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
355-from canonical.testing.layers import LaunchpadZopelessLayer
356-
357-
358-class TestPPABinaryExpiry(unittest.TestCase):
359+from lp.testing import TestCaseWithFactory
360+
361+
362+class TestPPABinaryExpiry(TestCaseWithFactory):
363 """Test the expire-ppa-binaries.py script."""
364
365 layer = LaunchpadZopelessLayer
366@@ -41,6 +43,7 @@
367
368 def setUp(self):
369 """Set up some test publications."""
370+ super(TestPPABinaryExpiry, self).setUp()
371 # Configure the test publisher.
372 self.layer.switchDbUser("launchpad")
373 self.stp = SoyuzTestPublisher()
374@@ -52,10 +55,8 @@
375 self.over_threshold_date = self.now - timedelta(days=31)
376
377 # Prepare two PPAs for the tests to use.
378- cprov = getUtility(IPersonSet).getByName('cprov')
379- self.ppa = cprov.archive
380- mark = getUtility(IPersonSet).getByName('mark')
381- self.ppa2 = mark.archive
382+ self.ppa = self.factory.makeArchive()
383+ self.ppa2 = self.factory.makeArchive()
384
385 def getScript(self, test_args=None):
386 """Return a PPABinaryExpirer instance."""
387@@ -209,9 +210,9 @@
388
389 def testBlacklistingWorks(self):
390 """Test that blacklisted PPAs are not expired."""
391- source, binary = self._setUpExpirablePublications()
392+ source, binary = self._setUpExpirablePublications(archive=self.ppa)
393 script = self.getScript()
394- script.blacklist = ["cprov",]
395+ script.blacklist = [self.ppa.owner.name, ]
396 self.layer.txn.commit()
397 self.layer.switchDbUser(self.dbuser)
398 script.main()
399
400=== modified file 'lib/lp/soyuz/scripts/tests/test_populatearchive.py'
401--- lib/lp/soyuz/scripts/tests/test_populatearchive.py 2010-02-11 06:22:38 +0000
402+++ lib/lp/soyuz/scripts/tests/test_populatearchive.py 2010-02-26 15:32:18 +0000
403@@ -29,7 +29,7 @@
404 from lp.soyuz.scripts.ftpmaster import PackageLocationError, SoyuzScriptError
405 from lp.soyuz.scripts.populate_archive import ArchivePopulator
406 from lp.soyuz.tests.test_publishing import SoyuzTestPublisher
407-from lp.testing import TestCase
408+from lp.testing import TestCaseWithFactory
409
410
411 def get_spn(build):
412@@ -38,7 +38,7 @@
413 return pub.sourcepackagerelease.sourcepackagename
414
415
416-class TestPopulateArchiveScript(TestCase):
417+class TestPopulateArchiveScript(TestCaseWithFactory):
418 """Test the copy-package.py script."""
419
420 layer = LaunchpadZopelessLayer
421@@ -542,7 +542,7 @@
422
423 This test should provoke a `SoyuzScriptError` exception because the
424 copy archive does not exist yet and will need to be created.
425-
426+
427 This is different from a merge copy scenario where the destination
428 copy archive exists already and hence no archive creation reason is
429 needed.
430@@ -690,20 +690,17 @@
431 The copying of packages from private archives to public ones
432 thus constitutes a security breach.
433 """
434- # We will make cprov's PPA private and then attempt to copy from it.
435- cprov = getUtility(IPersonSet).getByName('cprov')
436- ppa = cprov.archive
437- ppa.buildd_secret = 'super-secret-123'
438- ppa.private = True
439+ # We will make a private PPA and then attempt to copy from it.
440+ joe = self.factory.makePerson(name='joe')
441+ ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
442+ joes_private_ppa = self.factory.makeArchive(
443+ owner=joe, private=True, name="ppa", distribution=ubuntu)
444
445- extra_args = ['--from-user', 'cprov', '-a', 'amd64']
446+ extra_args = ['--from-user', 'joe', '-a', 'amd64']
447 copy_archive = self.runScript(
448 extra_args=extra_args, exception_type=SoyuzScriptError,
449 exception_text=(
450- "Cannot copy from private archive ('cprov/ppa')"))
451-
452- ppa.private = False
453- ppa.buildd_secret = None
454+ "Cannot copy from private archive ('joe/ppa')"))
455
456 def testDisabledDestinationArchive(self):
457 """Try copying to a disabled archive.
458
459=== modified file 'lib/lp/soyuz/scripts/tests/test_publishdistro.py'
460--- lib/lp/soyuz/scripts/tests/test_publishdistro.py 2010-02-25 12:30:49 +0000
461+++ lib/lp/soyuz/scripts/tests/test_publishdistro.py 2010-02-26 15:32:18 +0000
462@@ -239,17 +239,15 @@
463
464 It should only publish private PPAs.
465 """
466- # First, we'll make cprov's archive private.
467+ # First, we'll make a private PPA and populate it with a
468+ # publishing record.
469 ubuntutest = getUtility(IDistributionSet)['ubuntutest']
470- cprov = getUtility(IPersonSet).getByName('cprov')
471- cprov_ppa = removeSecurityProxy(cprov.archive)
472- cprov_ppa.private = True
473- cprov_ppa.buildd_secret = "secret"
474- cprov_ppa.distribution = self.ubuntutest
475+ private_ppa = self.factory.makeArchive(
476+ private=True, distribution=ubuntutest)
477
478- # Publish something to cprov's PPA:
479+ # Publish something to the private PPA:
480 pub_source = self.getPubSource(
481- sourcename='baz', filecontent='baz', archive=cprov.archive)
482+ sourcename='baz', filecontent='baz', archive=private_ppa)
483 self.layer.txn.commit()
484
485 # Try a plain PPA run, to ensure the private one is NOT published.
486
487=== modified file 'lib/lp/testing/factory.py'
488--- lib/lp/testing/factory.py 2010-02-24 23:16:07 +0000
489+++ lib/lp/testing/factory.py 2010-02-26 15:32:18 +0000
490@@ -145,7 +145,7 @@
491 @@ -121,6 +121,10 @@
492 'Gur pbasyvpgf grkg qrfpevovat nal cngu be grkg pbasyvpgf.'),
493 ernqbayl=Gehr))
494-
495+
496 + unf_pbasyvpgf = Obby(
497 + gvgyr=_('Unf pbasyvpgf'), ernqbayl=Gehr,
498 + qrfpevcgvba=_('Gur cerivrjrq zretr cebqhprf pbasyvpgf.'))
499@@ -1558,7 +1558,7 @@
500 return getUtility(IComponentSet).ensure(name)
501
502 def makeArchive(self, distribution=None, owner=None, name=None,
503- purpose=None, enabled=True):
504+ purpose=None, enabled=True, private=False):
505 """Create and return a new arbitrary archive.
506
507 :param distribution: Supply IDistribution, defaults to a new one
508@@ -1586,10 +1586,16 @@
509 if purpose == ArchivePurpose.PRIMARY:
510 return distribution.main_archive
511
512- return getUtility(IArchiveSet).new(
513+ archive = getUtility(IArchiveSet).new(
514 owner=owner, purpose=purpose,
515 distribution=distribution, name=name, enabled=enabled)
516
517+ if private:
518+ archive.private = True
519+ archive.buildd_secret = "sekrit"
520+
521+ return archive
522+
523 def makeBuilder(self, processor=None, url=None, name=None, title=None,
524 description=None, owner=None, active=True,
525 virtualized=True, vm_host=None):