Merge lp:~james-w/launchpad/code-imports-use-ibranchtarget into lp:launchpad

Proposed by James Westby
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~james-w/launchpad/code-imports-use-ibranchtarget
Merge into: lp:launchpad
Prerequisite: lp:~james-w/launchpad/nuke-code-import-warts
Diff against target: 556 lines (+75/-61)
14 files modified
lib/canonical/launchpad/webapp/tales.py (+2/-2)
lib/lp/code/browser/codeimport.py (+2/-1)
lib/lp/code/doc/codeimport.txt (+26/-25)
lib/lp/code/interfaces/codeimport.py (+5/-2)
lib/lp/code/mail/tests/test_codeimport.py (+4/-4)
lib/lp/code/model/codeimport.py (+2/-2)
lib/lp/code/model/tests/test_branchtarget.py (+1/-1)
lib/lp/code/model/tests/test_codeimport.py (+9/-8)
lib/lp/code/stories/branches/xx-branch-edit.txt (+1/-1)
lib/lp/code/stories/codeimport/xx-admin-codeimport.txt (+5/-5)
lib/lp/code/stories/codeimport/xx-edit-codeimport.txt (+1/-1)
lib/lp/code/stories/codeimport/xx-failing-codeimport.txt (+1/-1)
lib/lp/code/stories/webservice/xx-code-import.txt (+1/-1)
lib/lp/testing/factory.py (+15/-7)
To merge this branch: bzr merge lp:~james-w/launchpad/code-imports-use-ibranchtarget
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+21651@code.launchpad.net

Commit message

ICodeImportSet.new now takes an IBranchTarget instead of an IProduct.

Description of the change

Make ICodeImportSet.new act on IBranchTargets.

The code import creation only cares about a namespace, so use the more
generic interface to get one.

This changes the factory, adding makeProductCodeImport to still allow you
to pass product which will be turned in to an IBranch target as needed.

This doesn't add any new functionality, that will come later.

Most of the changes are mechanical, it's only a few places where the
behaviour may have changed.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Now passes all .*code.* tests in ec2, so ready for review.

Thanks,

James

Revision history for this message
Tim Penhey (thumper) wrote :

James, this all looks good.

My only comment is about the codeimport doc test.

How much work is it to change the following line:

>>> target = IBranchTarget(getUtility(IProductSet).getByName('firefox'))

to use factory.makeProduct(name='widget') ?

I'd love to move more away from sample data in the tests.

review: Approve
Revision history for this message
James Westby (james-w) wrote :

On Thu, 18 Mar 2010 21:06:13 -0000, Tim Penhey <email address hidden> wrote:
> Review: Approve
> James, this all looks good.
>
> My only comment is about the codeimport doc test.
>
> How much work is it to change the following line:
>
> >>> target = IBranchTarget(getUtility(IProductSet).getByName('firefox'))
>
> to use factory.makeProduct(name='widget') ?
>
> I'd love to move more away from sample data in the tests.

I'll have a look, it's rather an old doctest, so there may be some
cleanup involved.

Thanks,

James

Revision history for this message
Tim Penhey (thumper) wrote :

If you are going to print out the email of a person, make it explicit in the creation of the person.

So,
   factory.makePerson(displayname="Code Import Person", <email address hidden>")
instead of just:
   factory.makePerson(displayname="Code Import Person")

Thanks for updating the test.

review: Approve
Revision history for this message
James Westby (james-w) wrote :

Fixed, it now defines the name and email for the created person
so as not to rely on the created values.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/webapp/tales.py'
2--- lib/canonical/launchpad/webapp/tales.py 2010-03-16 05:09:55 +0000
3+++ lib/canonical/launchpad/webapp/tales.py 2010-03-20 22:14:44 +0000
4@@ -1494,12 +1494,12 @@
5 class CodeImportFormatterAPI(CustomizableFormatter):
6 """Adapter providing fmt support for CodeImport objects"""
7
8- _link_summary_template = _('Import of %(product)s: %(branch)s')
9+ _link_summary_template = _('Import of %(target)s: %(branch)s')
10 _link_permission = 'zope.Public'
11
12 def _link_summary_values(self):
13 """See CustomizableFormatter._link_summary_values."""
14- return {'product': self._context.product.displayname,
15+ return {'target': self._context.branch.target.displayname,
16 'branch': self._context.branch.bzr_identity,
17 }
18
19
20=== modified file 'lib/lp/code/browser/codeimport.py'
21--- lib/lp/code/browser/codeimport.py 2010-03-20 22:14:06 +0000
22+++ lib/lp/code/browser/codeimport.py 2010-03-20 22:14:44 +0000
23@@ -39,6 +39,7 @@
24 ICodeImport, ICodeImportSet)
25 from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet
26 from lp.code.interfaces.branch import BranchExists, IBranch
27+from lp.code.interfaces.branchtarget import IBranchTarget
28 from lp.registry.interfaces.product import IProduct
29 from canonical.launchpad.webapp import (
30 action, canonical_url, custom_widget, LaunchpadFormView, LaunchpadView,
31@@ -333,7 +334,7 @@
32 cvs_root, cvs_module, url = self._getImportLocation(data)
33 return getUtility(ICodeImportSet).new(
34 registrant=self.user,
35- product=product,
36+ target=IBranchTarget(product),
37 branch_name=data['branch_name'],
38 rcs_type=data['rcs_type'],
39 url=url,
40
41=== modified file 'lib/lp/code/doc/codeimport.txt'
42--- lib/lp/code/doc/codeimport.txt 2010-03-18 06:03:11 +0000
43+++ lib/lp/code/doc/codeimport.txt 2010-03-20 22:14:44 +0000
44@@ -21,6 +21,7 @@
45 CodeImports are created and found using the ICodeImportSet interface,
46 which is registered as a utility.
47
48+ >>> from lp.code.interfaces.branchtarget import IBranchTarget
49 >>> from lp.code.interfaces.codeimport import ICodeImport, ICodeImportSet
50 >>> from canonical.launchpad.webapp.testing import verifyObject
51 >>> from zope.component import getUtility
52@@ -29,11 +30,12 @@
53 >>> verifyObject(ICodeImportSet, removeSecurityProxy(code_import_set))
54 True
55
56-CodeImports record who created them, and we're going to pretend that
57-this is done by 'No Privileges Person'.
58+CodeImports record who created them, so we're going to create a new
59+person with no special privileges.
60
61- >>> from lp.registry.interfaces.person import IPersonSet
62- >>> nopriv = getUtility(IPersonSet).getByName('no-priv')
63+ >>> nopriv = factory.makePerson(
64+ ... displayname="Code Import Person", email="import@example.com",
65+ ... name="import-person")
66
67
68 CodeImport events
69@@ -71,10 +73,9 @@
70 >>> cvs = RevisionControlSystems.CVS
71 >>> cvs_root = ':pserver:anonymous@cvs.example.com:/cvsroot'
72 >>> cvs_module = 'hello'
73- >>> from lp.registry.interfaces.product import IProductSet
74- >>> product = getUtility(IProductSet).getByName('firefox')
75+ >>> target = IBranchTarget(factory.makeProduct(name='widget'))
76 >>> cvs_import = code_import_set.new(
77- ... registrant=nopriv, product=product, branch_name='trunk-cvs',
78+ ... registrant=nopriv, target=target, branch_name='trunk-cvs',
79 ... rcs_type=cvs, cvs_root=cvs_root, cvs_module=cvs_module)
80 >>> verifyObject(ICodeImport, removeSecurityProxy(cvs_import))
81 True
82@@ -95,12 +96,12 @@
83 >>> import email
84 >>> message = email.message_from_string(stub.test_emails[0][2])
85 >>> print message['subject']
86- New code import: firefox/trunk-cvs
87+ New code import: widget/trunk-cvs
88 >>> print message['X-Launchpad-Message-Rationale']
89 Operator @vcs-imports
90 >>> print message.get_payload(decode=True)
91- A new CVS code import has been requested by No Privileges Person:
92- http://code.launchpad.dev/~no-priv/firefox/trunk-cvs
93+ A new CVS code import has been requested by Code Import Person:
94+ http://code.launchpad.dev/~import-person/widget/trunk-cvs
95 from
96 :pserver:anonymous@cvs.example.com:/cvsroot, hello
97 <BLANKLINE>
98@@ -131,7 +132,7 @@
99 >>> svn = RevisionControlSystems.SVN
100 >>> svn_url = 'svn://svn.example.com/trunk'
101 >>> svn_import = code_import_set.new(
102- ... registrant=nopriv, product=product, branch_name='trunk-svn',
103+ ... registrant=nopriv, target=target, branch_name='trunk-svn',
104 ... rcs_type=svn, url=svn_url)
105 >>> verifyObject(ICodeImport, removeSecurityProxy(svn_import))
106 True
107@@ -160,7 +161,7 @@
108 >>> bzr_svn = RevisionControlSystems.BZR_SVN
109 >>> bzr_svn_url = 'svn://svn.example.com/for-bzr-svn/trunk'
110 >>> bzr_svn_import = code_import_set.new(
111- ... registrant=nopriv, product=product, branch_name='trunk-bzr-svn',
112+ ... registrant=nopriv, target=target, branch_name='trunk-bzr-svn',
113 ... rcs_type=bzr_svn, url=bzr_svn_url)
114 >>> verifyObject(ICodeImport, removeSecurityProxy(svn_import))
115 True
116@@ -182,7 +183,7 @@
117 >>> git = RevisionControlSystems.GIT
118 >>> git_url = 'git://git.example.com/hello.git'
119 >>> git_import = code_import_set.new(
120- ... registrant=nopriv, product=product, branch_name='trunk-git',
121+ ... registrant=nopriv, target=target, branch_name='trunk-git',
122 ... rcs_type=git, url=git_url)
123 >>> verifyObject(ICodeImport, removeSecurityProxy(git_import))
124 True
125@@ -209,7 +210,7 @@
126 >>> hg = RevisionControlSystems.HG
127 >>> hg_url = 'http://hg.example.com/metallic'
128 >>> hg_import = code_import_set.new(
129- ... registrant=nopriv, product=product, branch_name='trunk-hg',
130+ ... registrant=nopriv, target=target, branch_name='trunk-hg',
131 ... rcs_type=hg, url=hg_url)
132 >>> verifyObject(ICodeImport, removeSecurityProxy(hg_import))
133 True
134@@ -237,7 +238,7 @@
135 'updateFromData'. updateFromData returns a MODIFY CodeImportEvent if
136 any changes were made, or None if not.
137
138- >>> code_import = factory.makeCodeImport(
139+ >>> code_import = factory.makeProductCodeImport(
140 ... svn_branch_url='http://svn.example.com/project')
141 >>> print code_import.review_status.title
142 Pending Review
143@@ -268,7 +269,7 @@
144 ... 'url': 'http://svn.example.com/project/trunk'},
145 ... nopriv)
146 >>> print_emails(group_similar=True)
147- From: No Privileges Person <no-priv@canonical.com>
148+ From: Code Import Person <import@example.com>
149 To: david.allouche@canonical.com, ...
150 Subject: Code import product.../name... status: Reviewed
151 <BLANKLINE>
152@@ -286,8 +287,8 @@
153 team.
154 <BLANKLINE>
155 ----------------------------------------
156- From: No Privileges Person <no-priv@canonical.com>
157- To: no-priv@canonical.com
158+ From: Code Import Person <import@example.com>
159+ To: import@example.com
160 Subject: Code import product.../name... status: Reviewed
161 <BLANKLINE>
162 The import has been approved and an import will start shortly.
163@@ -324,7 +325,7 @@
164 Subject: Code import product.../name... status: Reviewed
165 ...
166 From: noreply@launchpad.net
167- To: no-priv@canonical.com
168+ To: import@example.com
169 Subject: Code import product.../name... status: Reviewed
170 ...
171
172@@ -473,9 +474,9 @@
173 only over the API.
174
175 >>> print canonical_url(svn_import.branch)
176- http://code.launchpad.dev/~no-priv/firefox/trunk-svn
177+ http://code.launchpad.dev/~import-person/widget/trunk-svn
178 >>> print canonical_url(svn_import)
179- http://code.launchpad.dev/~no-priv/firefox/trunk-svn/+code-import
180+ http://code.launchpad.dev/~import-person/widget/trunk-svn/+code-import
181
182
183 Modifying CodeImports
184@@ -532,7 +533,7 @@
185 >>> modify_event = cvs_import.updateFromData(data, nopriv)
186 >>> print make_email_body_for_code_import_update(
187 ... cvs_import, modify_event, None)
188- ~no-priv/firefox/trunk-cvs is now being imported from:
189+ ~import-person/widget/trunk-cvs is now being imported from:
190 hello from :pserver:anoncvs@cvs.example.com:/var/cvsroot
191 instead of:
192 hello from :pserver:anonymous@cvs.example.com:/cvsroot
193@@ -543,7 +544,7 @@
194 >>> modify_event = git_import.updateFromData(data, nopriv)
195 >>> print make_email_body_for_code_import_update(
196 ... git_import, modify_event, None)
197- ~no-priv/firefox/trunk-git is now being imported from:
198+ ~import-person/widget/trunk-git is now being imported from:
199 git://git.example.com/goodbye.git
200 instead of:
201 git://git.example.com/hello.git
202@@ -554,7 +555,7 @@
203 >>> modify_event = bzr_svn_import.updateFromData(data, nopriv)
204 >>> print make_email_body_for_code_import_update(
205 ... bzr_svn_import, modify_event, None)
206- ~no-priv/firefox/trunk-bzr-svn is now being imported from:
207+ ~import-person/widget/trunk-bzr-svn is now being imported from:
208 http://svn.example.com/for-bzr-svn/trunk
209 instead of:
210 svn://svn.example.com/for-bzr-svn/trunk
211@@ -565,7 +566,7 @@
212 >>> modify_event = hg_import.updateFromData(data, nopriv)
213 >>> print make_email_body_for_code_import_update(
214 ... hg_import, modify_event, None)
215- ~no-priv/firefox/trunk-hg is now being imported from:
216+ ~import-person/widget/trunk-hg is now being imported from:
217 http://metal.example.com/byebye.hg
218 instead of:
219 http://hg.example.com/metallic
220
221=== modified file 'lib/lp/code/interfaces/codeimport.py'
222--- lib/lp/code/interfaces/codeimport.py 2010-03-20 22:14:06 +0000
223+++ lib/lp/code/interfaces/codeimport.py 2010-03-20 22:14:44 +0000
224@@ -178,9 +178,12 @@
225 class ICodeImportSet(Interface):
226 """Interface representing the set of code imports."""
227
228- def new(registrant, product, branch_name, rcs_type, url=None,
229+ def new(registrant, target, branch_name, rcs_type, url=None,
230 cvs_root=None, cvs_module=None, review_status=None):
231- """Create a new CodeImport."""
232+ """Create a new CodeImport.
233+
234+ :param target: An `IBranchTarget` that the code is associated with.
235+ """
236
237 def getActiveImports(text=None):
238 """Return an iterable of all 'active' CodeImport objects.
239
240=== modified file 'lib/lp/code/mail/tests/test_codeimport.py'
241--- lib/lp/code/mail/tests/test_codeimport.py 2010-03-09 07:38:04 +0000
242+++ lib/lp/code/mail/tests/test_codeimport.py 2010-03-20 22:14:44 +0000
243@@ -25,7 +25,7 @@
244 fooix = self.factory.makeProduct(name='fooix')
245 # Eric needs to be logged in for the mail to be sent.
246 login_person(eric)
247- code_import = self.factory.makeCodeImport(
248+ code_import = self.factory.makeProductCodeImport(
249 cvs_root=':pserver:anonymouse@cvs.example.com:/cvsroot',
250 cvs_module='a_module', branch_name='import',
251 product=fooix, registrant=eric)
252@@ -48,7 +48,7 @@
253 fooix = self.factory.makeProduct(name='fooix')
254 # Eric needs to be logged in for the mail to be sent.
255 login_person(eric)
256- code_import = self.factory.makeCodeImport(
257+ code_import = self.factory.makeProductCodeImport(
258 svn_branch_url='svn://svn.example.com/fooix/trunk',
259 branch_name='trunk', product=fooix, registrant=eric,
260 rcs_type=RevisionControlSystems.BZR_SVN)
261@@ -71,7 +71,7 @@
262 fooix = self.factory.makeProduct(name='fooix')
263 # Eric needs to be logged in for the mail to be sent.
264 login_person(eric)
265- code_import = self.factory.makeCodeImport(
266+ code_import = self.factory.makeProductCodeImport(
267 git_repo_url='git://git.example.com/fooix.git',
268 branch_name='master', product=fooix, registrant=eric)
269 transaction.commit()
270@@ -94,7 +94,7 @@
271 fooix = self.factory.makeProduct(name='fooix')
272 # Eric needs to be logged in for the mail to be sent.
273 login_person(eric)
274- code_import = self.factory.makeCodeImport(
275+ code_import = self.factory.makeProductCodeImport(
276 hg_repo_url='http://hg.example.com/fooix.hg',
277 branch_name='master', product=fooix, registrant=eric)
278 transaction.commit()
279
280=== modified file 'lib/lp/code/model/codeimport.py'
281--- lib/lp/code/model/codeimport.py 2010-03-20 22:14:06 +0000
282+++ lib/lp/code/model/codeimport.py 2010-03-20 22:14:44 +0000
283@@ -205,7 +205,7 @@
284
285 implements(ICodeImportSet)
286
287- def new(self, registrant, product, branch_name, rcs_type,
288+ def new(self, registrant, target, branch_name, rcs_type,
289 url=None, cvs_root=None, cvs_module=None, review_status=None):
290 """See `ICodeImportSet`."""
291 if rcs_type == RevisionControlSystems.CVS:
292@@ -229,7 +229,7 @@
293 else:
294 review_status = CodeImportReviewStatus.NEW
295 # Create the branch for the CodeImport.
296- namespace = get_branch_namespace(registrant, product)
297+ namespace = target.getNamespace(registrant)
298 import_branch = namespace.createBranch(
299 branch_type=BranchType.IMPORTED, name=branch_name,
300 registrant=registrant)
301
302=== modified file 'lib/lp/code/model/tests/test_branchtarget.py'
303--- lib/lp/code/model/tests/test_branchtarget.py 2009-11-16 22:53:42 +0000
304+++ lib/lp/code/model/tests/test_branchtarget.py 2010-03-20 22:14:44 +0000
305@@ -91,7 +91,7 @@
306
307 def test_adapter(self):
308 target = IBranchTarget(self.original)
309- self.assertIsInstance(self.target, PackageBranchTarget)
310+ self.assertIsInstance(target, PackageBranchTarget)
311
312 def test_components(self):
313 target = IBranchTarget(self.original)
314
315=== modified file 'lib/lp/code/model/tests/test_codeimport.py'
316--- lib/lp/code/model/tests/test_codeimport.py 2010-03-20 22:14:06 +0000
317+++ lib/lp/code/model/tests/test_codeimport.py 2010-03-20 22:14:44 +0000
318@@ -17,6 +17,7 @@
319 from lp.code.model.codeimportevent import CodeImportEvent
320 from lp.code.model.codeimportjob import CodeImportJob, CodeImportJobSet
321 from lp.code.model.codeimportresult import CodeImportResult
322+from lp.code.interfaces.branchtarget import IBranchTarget
323 from lp.code.interfaces.codeimport import ICodeImportSet
324 from lp.registry.interfaces.person import IPersonSet
325 from lp.code.enums import (
326@@ -39,7 +40,7 @@
327 """A new subversion code import should have NEW status."""
328 code_import = CodeImportSet().new(
329 registrant=self.factory.makePerson(),
330- product=self.factory.makeProduct(),
331+ target=IBranchTarget(self.factory.makeProduct()),
332 branch_name='imported',
333 rcs_type=RevisionControlSystems.SVN,
334 url=self.factory.getUniqueURL())
335@@ -53,7 +54,7 @@
336 """A specific review status can be set for a new import."""
337 code_import = CodeImportSet().new(
338 registrant=self.factory.makePerson(),
339- product=self.factory.makeProduct(),
340+ target=IBranchTarget(self.factory.makeProduct()),
341 branch_name='imported',
342 rcs_type=RevisionControlSystems.SVN,
343 url=self.factory.getUniqueURL(),
344@@ -68,7 +69,7 @@
345 """A new CVS code import should have NEW status."""
346 code_import = CodeImportSet().new(
347 registrant=self.factory.makePerson(),
348- product=self.factory.makeProduct(),
349+ target=IBranchTarget(self.factory.makeProduct()),
350 branch_name='imported',
351 rcs_type=RevisionControlSystems.CVS,
352 cvs_root=self.factory.getUniqueURL(),
353@@ -83,7 +84,7 @@
354 """A specific review status can be set for a new import."""
355 code_import = CodeImportSet().new(
356 registrant=self.factory.makePerson(),
357- product=self.factory.makeProduct(),
358+ target=IBranchTarget(self.factory.makeProduct()),
359 branch_name='imported',
360 rcs_type=RevisionControlSystems.CVS,
361 cvs_root=self.factory.getUniqueURL(),
362@@ -99,7 +100,7 @@
363 """A new git import is always reviewed by default."""
364 code_import = CodeImportSet().new(
365 registrant=self.factory.makePerson(),
366- product=self.factory.makeProduct(),
367+ target=IBranchTarget(self.factory.makeProduct()),
368 branch_name='imported',
369 rcs_type=RevisionControlSystems.GIT,
370 url=self.factory.getUniqueURL(),
371@@ -114,7 +115,7 @@
372 """A new hg import is always reviewed by default."""
373 code_import = CodeImportSet().new(
374 registrant=self.factory.makePerson(),
375- product=self.factory.makeProduct(),
376+ target=IBranchTarget(self.factory.makeProduct()),
377 branch_name='imported',
378 rcs_type=RevisionControlSystems.HG,
379 url=self.factory.getUniqueURL(),
380@@ -565,7 +566,7 @@
381 project = None
382 product = factory.makeProduct(
383 name=product_name, displayname=product_name, project=project)
384- code_import = factory.makeCodeImport(
385+ code_import = factory.makeProductCodeImport(
386 product=product, branch_name=branch_name,
387 svn_branch_url=svn_branch_url, cvs_root=cvs_root,
388 cvs_module=cvs_module, git_repo_url=git_repo_url,
389@@ -662,7 +663,7 @@
390 self.factory, product_name='prod1', branch_name='a')
391 prod2_a = make_active_import(
392 self.factory, product_name='prod2', branch_name='a')
393- prod1_b = self.factory.makeCodeImport(
394+ prod1_b = self.factory.makeProductCodeImport(
395 product=prod1_a.branch.product, branch_name='b')
396 make_import_active(self.factory, prod1_b)
397 results = getUtility(ICodeImportSet).getActiveImports()
398
399=== modified file 'lib/lp/code/stories/branches/xx-branch-edit.txt'
400--- lib/lp/code/stories/branches/xx-branch-edit.txt 2010-03-09 16:58:30 +0000
401+++ lib/lp/code/stories/branches/xx-branch-edit.txt 2010-03-20 22:14:44 +0000
402@@ -216,7 +216,7 @@
403 >>> sample_person = getUtility(IPersonSet).getByName('name12')
404 >>> foogoo = factory.makeProduct(
405 ... name='foogoo', owner=sample_person)
406- >>> foogoo_svn_import = factory.makeCodeImport(
407+ >>> foogoo_svn_import = factory.makeProductCodeImport(
408 ... svn_branch_url='http://foogoo.example.com',
409 ... branch_name='foogoo-svn', product=foogoo, registrant=sample_person)
410 >>> foogoo_svn = foogoo_svn_import.branch
411
412=== modified file 'lib/lp/code/stories/codeimport/xx-admin-codeimport.txt'
413--- lib/lp/code/stories/codeimport/xx-admin-codeimport.txt 2010-01-22 03:16:44 +0000
414+++ lib/lp/code/stories/codeimport/xx-admin-codeimport.txt 2010-03-20 22:14:44 +0000
415@@ -10,30 +10,30 @@
416 >>> from lp.testing import ANONYMOUS, login, logout
417 >>> login('test@canonical.com')
418
419- >>> svn_import = factory.makeCodeImport(
420+ >>> svn_import = factory.makeProductCodeImport(
421 ... svn_branch_url='svn://svn.example.com/fooix/trunk')
422 >>> from canonical.launchpad.webapp import canonical_url
423 >>> svn_import_location = str(canonical_url(svn_import.branch))
424 >>> svn_import_branch_unique_name = svn_import.branch.unique_name
425
426- >>> bzr_svn_import = factory.makeCodeImport(
427+ >>> bzr_svn_import = factory.makeProductCodeImport(
428 ... svn_branch_url='svn://svn.example.com/bzr-svn/trunk',
429 ... rcs_type=RevisionControlSystems.BZR_SVN)
430 >>> bzr_svn_import_location = str(canonical_url(bzr_svn_import.branch))
431 >>> bzr_svn_import_branch_unique_name = bzr_svn_import.branch.unique_name
432
433- >>> cvs_import = factory.makeCodeImport(
434+ >>> cvs_import = factory.makeProductCodeImport(
435 ... cvs_root=":pserver:anonymous@cvs.example.com:/fooix",
436 ... cvs_module="fooix")
437 >>> cvs_import_location = str(canonical_url(cvs_import.branch))
438 >>> cvs_import_branch_unique_name = cvs_import.branch.unique_name
439
440- >>> git_import = factory.makeCodeImport(
441+ >>> git_import = factory.makeProductCodeImport(
442 ... git_repo_url="git://git.example.org/fooix")
443 >>> git_import_location = str(canonical_url(git_import.branch))
444 >>> git_import_branch_unique_name = git_import.branch.unique_name
445
446- >>> hg_import = factory.makeCodeImport(
447+ >>> hg_import = factory.makeProductCodeImport(
448 ... hg_repo_url="http://hg.example.org/bar")
449 >>> hg_import_location = str(canonical_url(hg_import.branch))
450 >>> hg_import_branch_unique_name = hg_import.branch.unique_name
451
452=== modified file 'lib/lp/code/stories/codeimport/xx-edit-codeimport.txt'
453--- lib/lp/code/stories/codeimport/xx-edit-codeimport.txt 2010-03-11 20:54:36 +0000
454+++ lib/lp/code/stories/codeimport/xx-edit-codeimport.txt 2010-03-20 22:14:44 +0000
455@@ -12,7 +12,7 @@
456
457 >>> login(ANONYMOUS)
458 >>> registrant = factory.makePerson(password='test')
459- >>> svn_import = factory.makeCodeImport(
460+ >>> svn_import = factory.makeProductCodeImport(
461 ... svn_branch_url='svn://svn.example.com/fooix/trunk',
462 ... registrant=registrant)
463 >>> svn_import_location = str(canonical_url(svn_import.branch))
464
465=== modified file 'lib/lp/code/stories/codeimport/xx-failing-codeimport.txt'
466--- lib/lp/code/stories/codeimport/xx-failing-codeimport.txt 2009-10-06 17:44:23 +0000
467+++ lib/lp/code/stories/codeimport/xx-failing-codeimport.txt 2010-03-20 22:14:44 +0000
468@@ -10,7 +10,7 @@
469 >>> from canonical.config import config
470 >>> product = factory.makeProduct(name='imported')
471 >>> owner = factory.makePerson(name='import-owner')
472- >>> code_import = factory.makeCodeImport(
473+ >>> code_import = factory.makeProductCodeImport(
474 ... product=product, branch_name='trunk', registrant=owner)
475 >>> for i in range(config.codeimport.consecutive_failure_limit):
476 ... dummy = make_finished_import(
477
478=== modified file 'lib/lp/code/stories/webservice/xx-code-import.txt'
479--- lib/lp/code/stories/webservice/xx-code-import.txt 2010-03-16 19:27:44 +0000
480+++ lib/lp/code/stories/webservice/xx-code-import.txt 2010-03-20 22:14:44 +0000
481@@ -11,7 +11,7 @@
482 >>> login(ANONYMOUS)
483 >>> person = factory.makePerson(name='import-owner')
484 >>> product = factory.makeProduct(name='scruff')
485- >>> code_import = removeSecurityProxy(factory.makeCodeImport(
486+ >>> code_import = removeSecurityProxy(factory.makeProductCodeImport(
487 ... registrant=person, product=product, branch_name='import'))
488 >>> no_import_branch = removeSecurityProxy(factory.makeProductBranch(
489 ... owner=person, product=product, name='no-import'))
490
491=== modified file 'lib/lp/testing/factory.py'
492--- lib/lp/testing/factory.py 2010-03-15 15:12:20 +0000
493+++ lib/lp/testing/factory.py 2010-03-20 22:14:44 +0000
494@@ -79,6 +79,7 @@
495 from lp.code.errors import UnknownBranchTypeError
496 from lp.code.interfaces.branchmergequeue import IBranchMergeQueueSet
497 from lp.code.interfaces.branchnamespace import get_branch_namespace
498+from lp.code.interfaces.branchtarget import IBranchTarget
499 from lp.code.interfaces.codeimport import ICodeImportSet
500 from lp.code.interfaces.codeimportevent import ICodeImportEventSet
501 from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet
502@@ -1370,8 +1371,15 @@
503 return target.newFAQ(
504 owner=target.owner, title=title, content='content')
505
506+ def makeProductCodeImport(self, product=None, **kwargs):
507+ """Make a code import targetting a product."""
508+ if product is None:
509+ product = self.makeProduct()
510+ target = IBranchTarget(product)
511+ return self.makeCodeImport(target=target, **kwargs)
512+
513 def makeCodeImport(self, svn_branch_url=None, cvs_root=None,
514- cvs_module=None, product=None, branch_name=None,
515+ cvs_module=None, target=None, branch_name=None,
516 git_repo_url=None, hg_repo_url=None, registrant=None,
517 rcs_type=None):
518 """Create and return a new, arbitrary code import.
519@@ -1384,8 +1392,8 @@
520 hg_repo_url is None):
521 svn_branch_url = self.getUniqueURL()
522
523- if product is None:
524- product = self.makeProduct()
525+ if target is None:
526+ target = IBranchTarget(self.makeProduct())
527 if branch_name is None:
528 branch_name = self.getUniqueString('name')
529 if registrant is None:
530@@ -1399,23 +1407,23 @@
531 assert rcs_type in (RevisionControlSystems.SVN,
532 RevisionControlSystems.BZR_SVN)
533 return code_import_set.new(
534- registrant, product, branch_name, rcs_type=rcs_type,
535+ registrant, target, branch_name, rcs_type=rcs_type,
536 url=svn_branch_url)
537 elif git_repo_url is not None:
538 assert rcs_type in (None, RevisionControlSystems.GIT)
539 return code_import_set.new(
540- registrant, product, branch_name,
541+ registrant, target, branch_name,
542 rcs_type=RevisionControlSystems.GIT,
543 url=git_repo_url)
544 elif hg_repo_url is not None:
545 return code_import_set.new(
546- registrant, product, branch_name,
547+ registrant, target, branch_name,
548 rcs_type=RevisionControlSystems.HG,
549 url=hg_repo_url)
550 else:
551 assert rcs_type in (None, RevisionControlSystems.CVS)
552 return code_import_set.new(
553- registrant, product, branch_name,
554+ registrant, target, branch_name,
555 rcs_type=RevisionControlSystems.CVS,
556 cvs_root=cvs_root, cvs_module=cvs_module)
557