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
=== modified file 'lib/canonical/launchpad/webapp/tales.py'
--- lib/canonical/launchpad/webapp/tales.py 2010-03-16 05:09:55 +0000
+++ lib/canonical/launchpad/webapp/tales.py 2010-03-20 22:14:44 +0000
@@ -1494,12 +1494,12 @@
1494class CodeImportFormatterAPI(CustomizableFormatter):1494class CodeImportFormatterAPI(CustomizableFormatter):
1495 """Adapter providing fmt support for CodeImport objects"""1495 """Adapter providing fmt support for CodeImport objects"""
14961496
1497 _link_summary_template = _('Import of %(product)s: %(branch)s')1497 _link_summary_template = _('Import of %(target)s: %(branch)s')
1498 _link_permission = 'zope.Public'1498 _link_permission = 'zope.Public'
14991499
1500 def _link_summary_values(self):1500 def _link_summary_values(self):
1501 """See CustomizableFormatter._link_summary_values."""1501 """See CustomizableFormatter._link_summary_values."""
1502 return {'product': self._context.product.displayname,1502 return {'target': self._context.branch.target.displayname,
1503 'branch': self._context.branch.bzr_identity,1503 'branch': self._context.branch.bzr_identity,
1504 }1504 }
15051505
15061506
=== modified file 'lib/lp/code/browser/codeimport.py'
--- lib/lp/code/browser/codeimport.py 2010-03-20 22:14:06 +0000
+++ lib/lp/code/browser/codeimport.py 2010-03-20 22:14:44 +0000
@@ -39,6 +39,7 @@
39 ICodeImport, ICodeImportSet)39 ICodeImport, ICodeImportSet)
40from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet40from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet
41from lp.code.interfaces.branch import BranchExists, IBranch41from lp.code.interfaces.branch import BranchExists, IBranch
42from lp.code.interfaces.branchtarget import IBranchTarget
42from lp.registry.interfaces.product import IProduct43from lp.registry.interfaces.product import IProduct
43from canonical.launchpad.webapp import (44from canonical.launchpad.webapp import (
44 action, canonical_url, custom_widget, LaunchpadFormView, LaunchpadView,45 action, canonical_url, custom_widget, LaunchpadFormView, LaunchpadView,
@@ -333,7 +334,7 @@
333 cvs_root, cvs_module, url = self._getImportLocation(data)334 cvs_root, cvs_module, url = self._getImportLocation(data)
334 return getUtility(ICodeImportSet).new(335 return getUtility(ICodeImportSet).new(
335 registrant=self.user,336 registrant=self.user,
336 product=product,337 target=IBranchTarget(product),
337 branch_name=data['branch_name'],338 branch_name=data['branch_name'],
338 rcs_type=data['rcs_type'],339 rcs_type=data['rcs_type'],
339 url=url,340 url=url,
340341
=== modified file 'lib/lp/code/doc/codeimport.txt'
--- lib/lp/code/doc/codeimport.txt 2010-03-18 06:03:11 +0000
+++ lib/lp/code/doc/codeimport.txt 2010-03-20 22:14:44 +0000
@@ -21,6 +21,7 @@
21CodeImports are created and found using the ICodeImportSet interface,21CodeImports are created and found using the ICodeImportSet interface,
22which is registered as a utility.22which is registered as a utility.
2323
24 >>> from lp.code.interfaces.branchtarget import IBranchTarget
24 >>> from lp.code.interfaces.codeimport import ICodeImport, ICodeImportSet25 >>> from lp.code.interfaces.codeimport import ICodeImport, ICodeImportSet
25 >>> from canonical.launchpad.webapp.testing import verifyObject26 >>> from canonical.launchpad.webapp.testing import verifyObject
26 >>> from zope.component import getUtility27 >>> from zope.component import getUtility
@@ -29,11 +30,12 @@
29 >>> verifyObject(ICodeImportSet, removeSecurityProxy(code_import_set))30 >>> verifyObject(ICodeImportSet, removeSecurityProxy(code_import_set))
30 True31 True
3132
32CodeImports record who created them, and we're going to pretend that33CodeImports record who created them, so we're going to create a new
33this is done by 'No Privileges Person'.34person with no special privileges.
3435
35 >>> from lp.registry.interfaces.person import IPersonSet36 >>> nopriv = factory.makePerson(
36 >>> nopriv = getUtility(IPersonSet).getByName('no-priv')37 ... displayname="Code Import Person", email="import@example.com",
38 ... name="import-person")
3739
3840
39CodeImport events41CodeImport events
@@ -71,10 +73,9 @@
71 >>> cvs = RevisionControlSystems.CVS73 >>> cvs = RevisionControlSystems.CVS
72 >>> cvs_root = ':pserver:anonymous@cvs.example.com:/cvsroot'74 >>> cvs_root = ':pserver:anonymous@cvs.example.com:/cvsroot'
73 >>> cvs_module = 'hello'75 >>> cvs_module = 'hello'
74 >>> from lp.registry.interfaces.product import IProductSet76 >>> target = IBranchTarget(factory.makeProduct(name='widget'))
75 >>> product = getUtility(IProductSet).getByName('firefox')
76 >>> cvs_import = code_import_set.new(77 >>> cvs_import = code_import_set.new(
77 ... registrant=nopriv, product=product, branch_name='trunk-cvs',78 ... registrant=nopriv, target=target, branch_name='trunk-cvs',
78 ... rcs_type=cvs, cvs_root=cvs_root, cvs_module=cvs_module)79 ... rcs_type=cvs, cvs_root=cvs_root, cvs_module=cvs_module)
79 >>> verifyObject(ICodeImport, removeSecurityProxy(cvs_import))80 >>> verifyObject(ICodeImport, removeSecurityProxy(cvs_import))
80 True81 True
@@ -95,12 +96,12 @@
95 >>> import email96 >>> import email
96 >>> message = email.message_from_string(stub.test_emails[0][2])97 >>> message = email.message_from_string(stub.test_emails[0][2])
97 >>> print message['subject']98 >>> print message['subject']
98 New code import: firefox/trunk-cvs99 New code import: widget/trunk-cvs
99 >>> print message['X-Launchpad-Message-Rationale']100 >>> print message['X-Launchpad-Message-Rationale']
100 Operator @vcs-imports101 Operator @vcs-imports
101 >>> print message.get_payload(decode=True)102 >>> print message.get_payload(decode=True)
102 A new CVS code import has been requested by No Privileges Person:103 A new CVS code import has been requested by Code Import Person:
103 http://code.launchpad.dev/~no-priv/firefox/trunk-cvs104 http://code.launchpad.dev/~import-person/widget/trunk-cvs
104 from105 from
105 :pserver:anonymous@cvs.example.com:/cvsroot, hello106 :pserver:anonymous@cvs.example.com:/cvsroot, hello
106 <BLANKLINE>107 <BLANKLINE>
@@ -131,7 +132,7 @@
131 >>> svn = RevisionControlSystems.SVN132 >>> svn = RevisionControlSystems.SVN
132 >>> svn_url = 'svn://svn.example.com/trunk'133 >>> svn_url = 'svn://svn.example.com/trunk'
133 >>> svn_import = code_import_set.new(134 >>> svn_import = code_import_set.new(
134 ... registrant=nopriv, product=product, branch_name='trunk-svn',135 ... registrant=nopriv, target=target, branch_name='trunk-svn',
135 ... rcs_type=svn, url=svn_url)136 ... rcs_type=svn, url=svn_url)
136 >>> verifyObject(ICodeImport, removeSecurityProxy(svn_import))137 >>> verifyObject(ICodeImport, removeSecurityProxy(svn_import))
137 True138 True
@@ -160,7 +161,7 @@
160 >>> bzr_svn = RevisionControlSystems.BZR_SVN161 >>> bzr_svn = RevisionControlSystems.BZR_SVN
161 >>> bzr_svn_url = 'svn://svn.example.com/for-bzr-svn/trunk'162 >>> bzr_svn_url = 'svn://svn.example.com/for-bzr-svn/trunk'
162 >>> bzr_svn_import = code_import_set.new(163 >>> bzr_svn_import = code_import_set.new(
163 ... registrant=nopriv, product=product, branch_name='trunk-bzr-svn',164 ... registrant=nopriv, target=target, branch_name='trunk-bzr-svn',
164 ... rcs_type=bzr_svn, url=bzr_svn_url)165 ... rcs_type=bzr_svn, url=bzr_svn_url)
165 >>> verifyObject(ICodeImport, removeSecurityProxy(svn_import))166 >>> verifyObject(ICodeImport, removeSecurityProxy(svn_import))
166 True167 True
@@ -182,7 +183,7 @@
182 >>> git = RevisionControlSystems.GIT183 >>> git = RevisionControlSystems.GIT
183 >>> git_url = 'git://git.example.com/hello.git'184 >>> git_url = 'git://git.example.com/hello.git'
184 >>> git_import = code_import_set.new(185 >>> git_import = code_import_set.new(
185 ... registrant=nopriv, product=product, branch_name='trunk-git',186 ... registrant=nopriv, target=target, branch_name='trunk-git',
186 ... rcs_type=git, url=git_url)187 ... rcs_type=git, url=git_url)
187 >>> verifyObject(ICodeImport, removeSecurityProxy(git_import))188 >>> verifyObject(ICodeImport, removeSecurityProxy(git_import))
188 True189 True
@@ -209,7 +210,7 @@
209 >>> hg = RevisionControlSystems.HG210 >>> hg = RevisionControlSystems.HG
210 >>> hg_url = 'http://hg.example.com/metallic'211 >>> hg_url = 'http://hg.example.com/metallic'
211 >>> hg_import = code_import_set.new(212 >>> hg_import = code_import_set.new(
212 ... registrant=nopriv, product=product, branch_name='trunk-hg',213 ... registrant=nopriv, target=target, branch_name='trunk-hg',
213 ... rcs_type=hg, url=hg_url)214 ... rcs_type=hg, url=hg_url)
214 >>> verifyObject(ICodeImport, removeSecurityProxy(hg_import))215 >>> verifyObject(ICodeImport, removeSecurityProxy(hg_import))
215 True216 True
@@ -237,7 +238,7 @@
237'updateFromData'. updateFromData returns a MODIFY CodeImportEvent if238'updateFromData'. updateFromData returns a MODIFY CodeImportEvent if
238any changes were made, or None if not.239any changes were made, or None if not.
239240
240 >>> code_import = factory.makeCodeImport(241 >>> code_import = factory.makeProductCodeImport(
241 ... svn_branch_url='http://svn.example.com/project')242 ... svn_branch_url='http://svn.example.com/project')
242 >>> print code_import.review_status.title243 >>> print code_import.review_status.title
243 Pending Review244 Pending Review
@@ -268,7 +269,7 @@
268 ... 'url': 'http://svn.example.com/project/trunk'},269 ... 'url': 'http://svn.example.com/project/trunk'},
269 ... nopriv)270 ... nopriv)
270 >>> print_emails(group_similar=True)271 >>> print_emails(group_similar=True)
271 From: No Privileges Person <no-priv@canonical.com>272 From: Code Import Person <import@example.com>
272 To: david.allouche@canonical.com, ...273 To: david.allouche@canonical.com, ...
273 Subject: Code import product.../name... status: Reviewed274 Subject: Code import product.../name... status: Reviewed
274 <BLANKLINE>275 <BLANKLINE>
@@ -286,8 +287,8 @@
286 team.287 team.
287 <BLANKLINE>288 <BLANKLINE>
288 ----------------------------------------289 ----------------------------------------
289 From: No Privileges Person <no-priv@canonical.com>290 From: Code Import Person <import@example.com>
290 To: no-priv@canonical.com291 To: import@example.com
291 Subject: Code import product.../name... status: Reviewed292 Subject: Code import product.../name... status: Reviewed
292 <BLANKLINE>293 <BLANKLINE>
293 The import has been approved and an import will start shortly.294 The import has been approved and an import will start shortly.
@@ -324,7 +325,7 @@
324 Subject: Code import product.../name... status: Reviewed325 Subject: Code import product.../name... status: Reviewed
325 ...326 ...
326 From: noreply@launchpad.net327 From: noreply@launchpad.net
327 To: no-priv@canonical.com328 To: import@example.com
328 Subject: Code import product.../name... status: Reviewed329 Subject: Code import product.../name... status: Reviewed
329 ...330 ...
330331
@@ -473,9 +474,9 @@
473only over the API.474only over the API.
474475
475 >>> print canonical_url(svn_import.branch)476 >>> print canonical_url(svn_import.branch)
476 http://code.launchpad.dev/~no-priv/firefox/trunk-svn477 http://code.launchpad.dev/~import-person/widget/trunk-svn
477 >>> print canonical_url(svn_import)478 >>> print canonical_url(svn_import)
478 http://code.launchpad.dev/~no-priv/firefox/trunk-svn/+code-import479 http://code.launchpad.dev/~import-person/widget/trunk-svn/+code-import
479480
480481
481Modifying CodeImports482Modifying CodeImports
@@ -532,7 +533,7 @@
532 >>> modify_event = cvs_import.updateFromData(data, nopriv)533 >>> modify_event = cvs_import.updateFromData(data, nopriv)
533 >>> print make_email_body_for_code_import_update(534 >>> print make_email_body_for_code_import_update(
534 ... cvs_import, modify_event, None)535 ... cvs_import, modify_event, None)
535 ~no-priv/firefox/trunk-cvs is now being imported from:536 ~import-person/widget/trunk-cvs is now being imported from:
536 hello from :pserver:anoncvs@cvs.example.com:/var/cvsroot537 hello from :pserver:anoncvs@cvs.example.com:/var/cvsroot
537 instead of:538 instead of:
538 hello from :pserver:anonymous@cvs.example.com:/cvsroot539 hello from :pserver:anonymous@cvs.example.com:/cvsroot
@@ -543,7 +544,7 @@
543 >>> modify_event = git_import.updateFromData(data, nopriv)544 >>> modify_event = git_import.updateFromData(data, nopriv)
544 >>> print make_email_body_for_code_import_update(545 >>> print make_email_body_for_code_import_update(
545 ... git_import, modify_event, None)546 ... git_import, modify_event, None)
546 ~no-priv/firefox/trunk-git is now being imported from:547 ~import-person/widget/trunk-git is now being imported from:
547 git://git.example.com/goodbye.git548 git://git.example.com/goodbye.git
548 instead of:549 instead of:
549 git://git.example.com/hello.git550 git://git.example.com/hello.git
@@ -554,7 +555,7 @@
554 >>> modify_event = bzr_svn_import.updateFromData(data, nopriv)555 >>> modify_event = bzr_svn_import.updateFromData(data, nopriv)
555 >>> print make_email_body_for_code_import_update(556 >>> print make_email_body_for_code_import_update(
556 ... bzr_svn_import, modify_event, None)557 ... bzr_svn_import, modify_event, None)
557 ~no-priv/firefox/trunk-bzr-svn is now being imported from:558 ~import-person/widget/trunk-bzr-svn is now being imported from:
558 http://svn.example.com/for-bzr-svn/trunk559 http://svn.example.com/for-bzr-svn/trunk
559 instead of:560 instead of:
560 svn://svn.example.com/for-bzr-svn/trunk561 svn://svn.example.com/for-bzr-svn/trunk
@@ -565,7 +566,7 @@
565 >>> modify_event = hg_import.updateFromData(data, nopriv)566 >>> modify_event = hg_import.updateFromData(data, nopriv)
566 >>> print make_email_body_for_code_import_update(567 >>> print make_email_body_for_code_import_update(
567 ... hg_import, modify_event, None)568 ... hg_import, modify_event, None)
568 ~no-priv/firefox/trunk-hg is now being imported from:569 ~import-person/widget/trunk-hg is now being imported from:
569 http://metal.example.com/byebye.hg570 http://metal.example.com/byebye.hg
570 instead of:571 instead of:
571 http://hg.example.com/metallic572 http://hg.example.com/metallic
572573
=== modified file 'lib/lp/code/interfaces/codeimport.py'
--- lib/lp/code/interfaces/codeimport.py 2010-03-20 22:14:06 +0000
+++ lib/lp/code/interfaces/codeimport.py 2010-03-20 22:14:44 +0000
@@ -178,9 +178,12 @@
178class ICodeImportSet(Interface):178class ICodeImportSet(Interface):
179 """Interface representing the set of code imports."""179 """Interface representing the set of code imports."""
180180
181 def new(registrant, product, branch_name, rcs_type, url=None,181 def new(registrant, target, branch_name, rcs_type, url=None,
182 cvs_root=None, cvs_module=None, review_status=None):182 cvs_root=None, cvs_module=None, review_status=None):
183 """Create a new CodeImport."""183 """Create a new CodeImport.
184
185 :param target: An `IBranchTarget` that the code is associated with.
186 """
184187
185 def getActiveImports(text=None):188 def getActiveImports(text=None):
186 """Return an iterable of all 'active' CodeImport objects.189 """Return an iterable of all 'active' CodeImport objects.
187190
=== modified file 'lib/lp/code/mail/tests/test_codeimport.py'
--- lib/lp/code/mail/tests/test_codeimport.py 2010-03-09 07:38:04 +0000
+++ lib/lp/code/mail/tests/test_codeimport.py 2010-03-20 22:14:44 +0000
@@ -25,7 +25,7 @@
25 fooix = self.factory.makeProduct(name='fooix')25 fooix = self.factory.makeProduct(name='fooix')
26 # Eric needs to be logged in for the mail to be sent.26 # Eric needs to be logged in for the mail to be sent.
27 login_person(eric)27 login_person(eric)
28 code_import = self.factory.makeCodeImport(28 code_import = self.factory.makeProductCodeImport(
29 cvs_root=':pserver:anonymouse@cvs.example.com:/cvsroot',29 cvs_root=':pserver:anonymouse@cvs.example.com:/cvsroot',
30 cvs_module='a_module', branch_name='import',30 cvs_module='a_module', branch_name='import',
31 product=fooix, registrant=eric)31 product=fooix, registrant=eric)
@@ -48,7 +48,7 @@
48 fooix = self.factory.makeProduct(name='fooix')48 fooix = self.factory.makeProduct(name='fooix')
49 # Eric needs to be logged in for the mail to be sent.49 # Eric needs to be logged in for the mail to be sent.
50 login_person(eric)50 login_person(eric)
51 code_import = self.factory.makeCodeImport(51 code_import = self.factory.makeProductCodeImport(
52 svn_branch_url='svn://svn.example.com/fooix/trunk',52 svn_branch_url='svn://svn.example.com/fooix/trunk',
53 branch_name='trunk', product=fooix, registrant=eric,53 branch_name='trunk', product=fooix, registrant=eric,
54 rcs_type=RevisionControlSystems.BZR_SVN)54 rcs_type=RevisionControlSystems.BZR_SVN)
@@ -71,7 +71,7 @@
71 fooix = self.factory.makeProduct(name='fooix')71 fooix = self.factory.makeProduct(name='fooix')
72 # Eric needs to be logged in for the mail to be sent.72 # Eric needs to be logged in for the mail to be sent.
73 login_person(eric)73 login_person(eric)
74 code_import = self.factory.makeCodeImport(74 code_import = self.factory.makeProductCodeImport(
75 git_repo_url='git://git.example.com/fooix.git',75 git_repo_url='git://git.example.com/fooix.git',
76 branch_name='master', product=fooix, registrant=eric)76 branch_name='master', product=fooix, registrant=eric)
77 transaction.commit()77 transaction.commit()
@@ -94,7 +94,7 @@
94 fooix = self.factory.makeProduct(name='fooix')94 fooix = self.factory.makeProduct(name='fooix')
95 # Eric needs to be logged in for the mail to be sent.95 # Eric needs to be logged in for the mail to be sent.
96 login_person(eric)96 login_person(eric)
97 code_import = self.factory.makeCodeImport(97 code_import = self.factory.makeProductCodeImport(
98 hg_repo_url='http://hg.example.com/fooix.hg',98 hg_repo_url='http://hg.example.com/fooix.hg',
99 branch_name='master', product=fooix, registrant=eric)99 branch_name='master', product=fooix, registrant=eric)
100 transaction.commit()100 transaction.commit()
101101
=== modified file 'lib/lp/code/model/codeimport.py'
--- lib/lp/code/model/codeimport.py 2010-03-20 22:14:06 +0000
+++ lib/lp/code/model/codeimport.py 2010-03-20 22:14:44 +0000
@@ -205,7 +205,7 @@
205205
206 implements(ICodeImportSet)206 implements(ICodeImportSet)
207207
208 def new(self, registrant, product, branch_name, rcs_type,208 def new(self, registrant, target, branch_name, rcs_type,
209 url=None, cvs_root=None, cvs_module=None, review_status=None):209 url=None, cvs_root=None, cvs_module=None, review_status=None):
210 """See `ICodeImportSet`."""210 """See `ICodeImportSet`."""
211 if rcs_type == RevisionControlSystems.CVS:211 if rcs_type == RevisionControlSystems.CVS:
@@ -229,7 +229,7 @@
229 else:229 else:
230 review_status = CodeImportReviewStatus.NEW230 review_status = CodeImportReviewStatus.NEW
231 # Create the branch for the CodeImport.231 # Create the branch for the CodeImport.
232 namespace = get_branch_namespace(registrant, product)232 namespace = target.getNamespace(registrant)
233 import_branch = namespace.createBranch(233 import_branch = namespace.createBranch(
234 branch_type=BranchType.IMPORTED, name=branch_name,234 branch_type=BranchType.IMPORTED, name=branch_name,
235 registrant=registrant)235 registrant=registrant)
236236
=== modified file 'lib/lp/code/model/tests/test_branchtarget.py'
--- lib/lp/code/model/tests/test_branchtarget.py 2009-11-16 22:53:42 +0000
+++ lib/lp/code/model/tests/test_branchtarget.py 2010-03-20 22:14:44 +0000
@@ -91,7 +91,7 @@
9191
92 def test_adapter(self):92 def test_adapter(self):
93 target = IBranchTarget(self.original)93 target = IBranchTarget(self.original)
94 self.assertIsInstance(self.target, PackageBranchTarget)94 self.assertIsInstance(target, PackageBranchTarget)
9595
96 def test_components(self):96 def test_components(self):
97 target = IBranchTarget(self.original)97 target = IBranchTarget(self.original)
9898
=== modified file 'lib/lp/code/model/tests/test_codeimport.py'
--- lib/lp/code/model/tests/test_codeimport.py 2010-03-20 22:14:06 +0000
+++ lib/lp/code/model/tests/test_codeimport.py 2010-03-20 22:14:44 +0000
@@ -17,6 +17,7 @@
17from lp.code.model.codeimportevent import CodeImportEvent17from lp.code.model.codeimportevent import CodeImportEvent
18from lp.code.model.codeimportjob import CodeImportJob, CodeImportJobSet18from lp.code.model.codeimportjob import CodeImportJob, CodeImportJobSet
19from lp.code.model.codeimportresult import CodeImportResult19from lp.code.model.codeimportresult import CodeImportResult
20from lp.code.interfaces.branchtarget import IBranchTarget
20from lp.code.interfaces.codeimport import ICodeImportSet21from lp.code.interfaces.codeimport import ICodeImportSet
21from lp.registry.interfaces.person import IPersonSet22from lp.registry.interfaces.person import IPersonSet
22from lp.code.enums import (23from lp.code.enums import (
@@ -39,7 +40,7 @@
39 """A new subversion code import should have NEW status."""40 """A new subversion code import should have NEW status."""
40 code_import = CodeImportSet().new(41 code_import = CodeImportSet().new(
41 registrant=self.factory.makePerson(),42 registrant=self.factory.makePerson(),
42 product=self.factory.makeProduct(),43 target=IBranchTarget(self.factory.makeProduct()),
43 branch_name='imported',44 branch_name='imported',
44 rcs_type=RevisionControlSystems.SVN,45 rcs_type=RevisionControlSystems.SVN,
45 url=self.factory.getUniqueURL())46 url=self.factory.getUniqueURL())
@@ -53,7 +54,7 @@
53 """A specific review status can be set for a new import."""54 """A specific review status can be set for a new import."""
54 code_import = CodeImportSet().new(55 code_import = CodeImportSet().new(
55 registrant=self.factory.makePerson(),56 registrant=self.factory.makePerson(),
56 product=self.factory.makeProduct(),57 target=IBranchTarget(self.factory.makeProduct()),
57 branch_name='imported',58 branch_name='imported',
58 rcs_type=RevisionControlSystems.SVN,59 rcs_type=RevisionControlSystems.SVN,
59 url=self.factory.getUniqueURL(),60 url=self.factory.getUniqueURL(),
@@ -68,7 +69,7 @@
68 """A new CVS code import should have NEW status."""69 """A new CVS code import should have NEW status."""
69 code_import = CodeImportSet().new(70 code_import = CodeImportSet().new(
70 registrant=self.factory.makePerson(),71 registrant=self.factory.makePerson(),
71 product=self.factory.makeProduct(),72 target=IBranchTarget(self.factory.makeProduct()),
72 branch_name='imported',73 branch_name='imported',
73 rcs_type=RevisionControlSystems.CVS,74 rcs_type=RevisionControlSystems.CVS,
74 cvs_root=self.factory.getUniqueURL(),75 cvs_root=self.factory.getUniqueURL(),
@@ -83,7 +84,7 @@
83 """A specific review status can be set for a new import."""84 """A specific review status can be set for a new import."""
84 code_import = CodeImportSet().new(85 code_import = CodeImportSet().new(
85 registrant=self.factory.makePerson(),86 registrant=self.factory.makePerson(),
86 product=self.factory.makeProduct(),87 target=IBranchTarget(self.factory.makeProduct()),
87 branch_name='imported',88 branch_name='imported',
88 rcs_type=RevisionControlSystems.CVS,89 rcs_type=RevisionControlSystems.CVS,
89 cvs_root=self.factory.getUniqueURL(),90 cvs_root=self.factory.getUniqueURL(),
@@ -99,7 +100,7 @@
99 """A new git import is always reviewed by default."""100 """A new git import is always reviewed by default."""
100 code_import = CodeImportSet().new(101 code_import = CodeImportSet().new(
101 registrant=self.factory.makePerson(),102 registrant=self.factory.makePerson(),
102 product=self.factory.makeProduct(),103 target=IBranchTarget(self.factory.makeProduct()),
103 branch_name='imported',104 branch_name='imported',
104 rcs_type=RevisionControlSystems.GIT,105 rcs_type=RevisionControlSystems.GIT,
105 url=self.factory.getUniqueURL(),106 url=self.factory.getUniqueURL(),
@@ -114,7 +115,7 @@
114 """A new hg import is always reviewed by default."""115 """A new hg import is always reviewed by default."""
115 code_import = CodeImportSet().new(116 code_import = CodeImportSet().new(
116 registrant=self.factory.makePerson(),117 registrant=self.factory.makePerson(),
117 product=self.factory.makeProduct(),118 target=IBranchTarget(self.factory.makeProduct()),
118 branch_name='imported',119 branch_name='imported',
119 rcs_type=RevisionControlSystems.HG,120 rcs_type=RevisionControlSystems.HG,
120 url=self.factory.getUniqueURL(),121 url=self.factory.getUniqueURL(),
@@ -565,7 +566,7 @@
565 project = None566 project = None
566 product = factory.makeProduct(567 product = factory.makeProduct(
567 name=product_name, displayname=product_name, project=project)568 name=product_name, displayname=product_name, project=project)
568 code_import = factory.makeCodeImport(569 code_import = factory.makeProductCodeImport(
569 product=product, branch_name=branch_name,570 product=product, branch_name=branch_name,
570 svn_branch_url=svn_branch_url, cvs_root=cvs_root,571 svn_branch_url=svn_branch_url, cvs_root=cvs_root,
571 cvs_module=cvs_module, git_repo_url=git_repo_url,572 cvs_module=cvs_module, git_repo_url=git_repo_url,
@@ -662,7 +663,7 @@
662 self.factory, product_name='prod1', branch_name='a')663 self.factory, product_name='prod1', branch_name='a')
663 prod2_a = make_active_import(664 prod2_a = make_active_import(
664 self.factory, product_name='prod2', branch_name='a')665 self.factory, product_name='prod2', branch_name='a')
665 prod1_b = self.factory.makeCodeImport(666 prod1_b = self.factory.makeProductCodeImport(
666 product=prod1_a.branch.product, branch_name='b')667 product=prod1_a.branch.product, branch_name='b')
667 make_import_active(self.factory, prod1_b)668 make_import_active(self.factory, prod1_b)
668 results = getUtility(ICodeImportSet).getActiveImports()669 results = getUtility(ICodeImportSet).getActiveImports()
669670
=== modified file 'lib/lp/code/stories/branches/xx-branch-edit.txt'
--- lib/lp/code/stories/branches/xx-branch-edit.txt 2010-03-09 16:58:30 +0000
+++ lib/lp/code/stories/branches/xx-branch-edit.txt 2010-03-20 22:14:44 +0000
@@ -216,7 +216,7 @@
216 >>> sample_person = getUtility(IPersonSet).getByName('name12')216 >>> sample_person = getUtility(IPersonSet).getByName('name12')
217 >>> foogoo = factory.makeProduct(217 >>> foogoo = factory.makeProduct(
218 ... name='foogoo', owner=sample_person)218 ... name='foogoo', owner=sample_person)
219 >>> foogoo_svn_import = factory.makeCodeImport(219 >>> foogoo_svn_import = factory.makeProductCodeImport(
220 ... svn_branch_url='http://foogoo.example.com',220 ... svn_branch_url='http://foogoo.example.com',
221 ... branch_name='foogoo-svn', product=foogoo, registrant=sample_person)221 ... branch_name='foogoo-svn', product=foogoo, registrant=sample_person)
222 >>> foogoo_svn = foogoo_svn_import.branch222 >>> foogoo_svn = foogoo_svn_import.branch
223223
=== modified file 'lib/lp/code/stories/codeimport/xx-admin-codeimport.txt'
--- lib/lp/code/stories/codeimport/xx-admin-codeimport.txt 2010-01-22 03:16:44 +0000
+++ lib/lp/code/stories/codeimport/xx-admin-codeimport.txt 2010-03-20 22:14:44 +0000
@@ -10,30 +10,30 @@
10 >>> from lp.testing import ANONYMOUS, login, logout10 >>> from lp.testing import ANONYMOUS, login, logout
11 >>> login('test@canonical.com')11 >>> login('test@canonical.com')
1212
13 >>> svn_import = factory.makeCodeImport(13 >>> svn_import = factory.makeProductCodeImport(
14 ... svn_branch_url='svn://svn.example.com/fooix/trunk')14 ... svn_branch_url='svn://svn.example.com/fooix/trunk')
15 >>> from canonical.launchpad.webapp import canonical_url15 >>> from canonical.launchpad.webapp import canonical_url
16 >>> svn_import_location = str(canonical_url(svn_import.branch))16 >>> svn_import_location = str(canonical_url(svn_import.branch))
17 >>> svn_import_branch_unique_name = svn_import.branch.unique_name17 >>> svn_import_branch_unique_name = svn_import.branch.unique_name
1818
19 >>> bzr_svn_import = factory.makeCodeImport(19 >>> bzr_svn_import = factory.makeProductCodeImport(
20 ... svn_branch_url='svn://svn.example.com/bzr-svn/trunk',20 ... svn_branch_url='svn://svn.example.com/bzr-svn/trunk',
21 ... rcs_type=RevisionControlSystems.BZR_SVN)21 ... rcs_type=RevisionControlSystems.BZR_SVN)
22 >>> bzr_svn_import_location = str(canonical_url(bzr_svn_import.branch))22 >>> bzr_svn_import_location = str(canonical_url(bzr_svn_import.branch))
23 >>> bzr_svn_import_branch_unique_name = bzr_svn_import.branch.unique_name23 >>> bzr_svn_import_branch_unique_name = bzr_svn_import.branch.unique_name
2424
25 >>> cvs_import = factory.makeCodeImport(25 >>> cvs_import = factory.makeProductCodeImport(
26 ... cvs_root=":pserver:anonymous@cvs.example.com:/fooix",26 ... cvs_root=":pserver:anonymous@cvs.example.com:/fooix",
27 ... cvs_module="fooix")27 ... cvs_module="fooix")
28 >>> cvs_import_location = str(canonical_url(cvs_import.branch))28 >>> cvs_import_location = str(canonical_url(cvs_import.branch))
29 >>> cvs_import_branch_unique_name = cvs_import.branch.unique_name29 >>> cvs_import_branch_unique_name = cvs_import.branch.unique_name
3030
31 >>> git_import = factory.makeCodeImport(31 >>> git_import = factory.makeProductCodeImport(
32 ... git_repo_url="git://git.example.org/fooix")32 ... git_repo_url="git://git.example.org/fooix")
33 >>> git_import_location = str(canonical_url(git_import.branch))33 >>> git_import_location = str(canonical_url(git_import.branch))
34 >>> git_import_branch_unique_name = git_import.branch.unique_name34 >>> git_import_branch_unique_name = git_import.branch.unique_name
3535
36 >>> hg_import = factory.makeCodeImport(36 >>> hg_import = factory.makeProductCodeImport(
37 ... hg_repo_url="http://hg.example.org/bar")37 ... hg_repo_url="http://hg.example.org/bar")
38 >>> hg_import_location = str(canonical_url(hg_import.branch))38 >>> hg_import_location = str(canonical_url(hg_import.branch))
39 >>> hg_import_branch_unique_name = hg_import.branch.unique_name39 >>> hg_import_branch_unique_name = hg_import.branch.unique_name
4040
=== modified file 'lib/lp/code/stories/codeimport/xx-edit-codeimport.txt'
--- lib/lp/code/stories/codeimport/xx-edit-codeimport.txt 2010-03-11 20:54:36 +0000
+++ lib/lp/code/stories/codeimport/xx-edit-codeimport.txt 2010-03-20 22:14:44 +0000
@@ -12,7 +12,7 @@
1212
13 >>> login(ANONYMOUS)13 >>> login(ANONYMOUS)
14 >>> registrant = factory.makePerson(password='test')14 >>> registrant = factory.makePerson(password='test')
15 >>> svn_import = factory.makeCodeImport(15 >>> svn_import = factory.makeProductCodeImport(
16 ... svn_branch_url='svn://svn.example.com/fooix/trunk',16 ... svn_branch_url='svn://svn.example.com/fooix/trunk',
17 ... registrant=registrant)17 ... registrant=registrant)
18 >>> svn_import_location = str(canonical_url(svn_import.branch))18 >>> svn_import_location = str(canonical_url(svn_import.branch))
1919
=== modified file 'lib/lp/code/stories/codeimport/xx-failing-codeimport.txt'
--- lib/lp/code/stories/codeimport/xx-failing-codeimport.txt 2009-10-06 17:44:23 +0000
+++ lib/lp/code/stories/codeimport/xx-failing-codeimport.txt 2010-03-20 22:14:44 +0000
@@ -10,7 +10,7 @@
10 >>> from canonical.config import config10 >>> from canonical.config import config
11 >>> product = factory.makeProduct(name='imported')11 >>> product = factory.makeProduct(name='imported')
12 >>> owner = factory.makePerson(name='import-owner')12 >>> owner = factory.makePerson(name='import-owner')
13 >>> code_import = factory.makeCodeImport(13 >>> code_import = factory.makeProductCodeImport(
14 ... product=product, branch_name='trunk', registrant=owner)14 ... product=product, branch_name='trunk', registrant=owner)
15 >>> for i in range(config.codeimport.consecutive_failure_limit):15 >>> for i in range(config.codeimport.consecutive_failure_limit):
16 ... dummy = make_finished_import(16 ... dummy = make_finished_import(
1717
=== modified file 'lib/lp/code/stories/webservice/xx-code-import.txt'
--- lib/lp/code/stories/webservice/xx-code-import.txt 2010-03-16 19:27:44 +0000
+++ lib/lp/code/stories/webservice/xx-code-import.txt 2010-03-20 22:14:44 +0000
@@ -11,7 +11,7 @@
11 >>> login(ANONYMOUS)11 >>> login(ANONYMOUS)
12 >>> person = factory.makePerson(name='import-owner')12 >>> person = factory.makePerson(name='import-owner')
13 >>> product = factory.makeProduct(name='scruff')13 >>> product = factory.makeProduct(name='scruff')
14 >>> code_import = removeSecurityProxy(factory.makeCodeImport(14 >>> code_import = removeSecurityProxy(factory.makeProductCodeImport(
15 ... registrant=person, product=product, branch_name='import'))15 ... registrant=person, product=product, branch_name='import'))
16 >>> no_import_branch = removeSecurityProxy(factory.makeProductBranch(16 >>> no_import_branch = removeSecurityProxy(factory.makeProductBranch(
17 ... owner=person, product=product, name='no-import'))17 ... owner=person, product=product, name='no-import'))
1818
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2010-03-15 15:12:20 +0000
+++ lib/lp/testing/factory.py 2010-03-20 22:14:44 +0000
@@ -79,6 +79,7 @@
79from lp.code.errors import UnknownBranchTypeError79from lp.code.errors import UnknownBranchTypeError
80from lp.code.interfaces.branchmergequeue import IBranchMergeQueueSet80from lp.code.interfaces.branchmergequeue import IBranchMergeQueueSet
81from lp.code.interfaces.branchnamespace import get_branch_namespace81from lp.code.interfaces.branchnamespace import get_branch_namespace
82from lp.code.interfaces.branchtarget import IBranchTarget
82from lp.code.interfaces.codeimport import ICodeImportSet83from lp.code.interfaces.codeimport import ICodeImportSet
83from lp.code.interfaces.codeimportevent import ICodeImportEventSet84from lp.code.interfaces.codeimportevent import ICodeImportEventSet
84from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet85from lp.code.interfaces.codeimportmachine import ICodeImportMachineSet
@@ -1370,8 +1371,15 @@
1370 return target.newFAQ(1371 return target.newFAQ(
1371 owner=target.owner, title=title, content='content')1372 owner=target.owner, title=title, content='content')
13721373
1374 def makeProductCodeImport(self, product=None, **kwargs):
1375 """Make a code import targetting a product."""
1376 if product is None:
1377 product = self.makeProduct()
1378 target = IBranchTarget(product)
1379 return self.makeCodeImport(target=target, **kwargs)
1380
1373 def makeCodeImport(self, svn_branch_url=None, cvs_root=None,1381 def makeCodeImport(self, svn_branch_url=None, cvs_root=None,
1374 cvs_module=None, product=None, branch_name=None,1382 cvs_module=None, target=None, branch_name=None,
1375 git_repo_url=None, hg_repo_url=None, registrant=None,1383 git_repo_url=None, hg_repo_url=None, registrant=None,
1376 rcs_type=None):1384 rcs_type=None):
1377 """Create and return a new, arbitrary code import.1385 """Create and return a new, arbitrary code import.
@@ -1384,8 +1392,8 @@
1384 hg_repo_url is None):1392 hg_repo_url is None):
1385 svn_branch_url = self.getUniqueURL()1393 svn_branch_url = self.getUniqueURL()
13861394
1387 if product is None:1395 if target is None:
1388 product = self.makeProduct()1396 target = IBranchTarget(self.makeProduct())
1389 if branch_name is None:1397 if branch_name is None:
1390 branch_name = self.getUniqueString('name')1398 branch_name = self.getUniqueString('name')
1391 if registrant is None:1399 if registrant is None:
@@ -1399,23 +1407,23 @@
1399 assert rcs_type in (RevisionControlSystems.SVN,1407 assert rcs_type in (RevisionControlSystems.SVN,
1400 RevisionControlSystems.BZR_SVN)1408 RevisionControlSystems.BZR_SVN)
1401 return code_import_set.new(1409 return code_import_set.new(
1402 registrant, product, branch_name, rcs_type=rcs_type,1410 registrant, target, branch_name, rcs_type=rcs_type,
1403 url=svn_branch_url)1411 url=svn_branch_url)
1404 elif git_repo_url is not None:1412 elif git_repo_url is not None:
1405 assert rcs_type in (None, RevisionControlSystems.GIT)1413 assert rcs_type in (None, RevisionControlSystems.GIT)
1406 return code_import_set.new(1414 return code_import_set.new(
1407 registrant, product, branch_name,1415 registrant, target, branch_name,
1408 rcs_type=RevisionControlSystems.GIT,1416 rcs_type=RevisionControlSystems.GIT,
1409 url=git_repo_url)1417 url=git_repo_url)
1410 elif hg_repo_url is not None:1418 elif hg_repo_url is not None:
1411 return code_import_set.new(1419 return code_import_set.new(
1412 registrant, product, branch_name,1420 registrant, target, branch_name,
1413 rcs_type=RevisionControlSystems.HG,1421 rcs_type=RevisionControlSystems.HG,
1414 url=hg_repo_url)1422 url=hg_repo_url)
1415 else:1423 else:
1416 assert rcs_type in (None, RevisionControlSystems.CVS)1424 assert rcs_type in (None, RevisionControlSystems.CVS)
1417 return code_import_set.new(1425 return code_import_set.new(
1418 registrant, product, branch_name,1426 registrant, target, branch_name,
1419 rcs_type=RevisionControlSystems.CVS,1427 rcs_type=RevisionControlSystems.CVS,
1420 cvs_root=cvs_root, cvs_module=cvs_module)1428 cvs_root=cvs_root, cvs_module=cvs_module)
14211429