launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12073
[Merge] lp:~wallyworld/launchpad/branch-setTarget-validation into lp:launchpad
Ian Booth has proposed merging lp:~wallyworld/launchpad/branch-setTarget-validation into lp:launchpad.
Requested reviews:
Curtis Hovey (sinzui)
For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/branch-setTarget-validation/+merge/124691
== Implementation ==
This branch follows on from previous work to add a widget to re-target a branch.
When setTarget() is called, a check is done to see if the branch information type is in the allowed types for the new target. If not, an error is raised.
== Tests ==
Add a new test to TestBranchSetTarget
bin/test -vvct TestBranchSetTarget
== Lint ==
Linting changed files:
lib/lp/code/model/branch.py
lib/lp/code/model/tests/test_branch.py
--
https://code.launchpad.net/~wallyworld/launchpad/branch-setTarget-validation/+merge/124691
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2012-09-14 01:21:13 +0000
+++ lib/lp/code/model/branch.py 2012-09-17 14:00:26 +0000
@@ -369,6 +369,10 @@
raise BranchTargetError(
'Only private teams may have personal private branches.')
namespace = target.getNamespace(self.owner)
+ if self.information_type not in namespace.getAllowedInformationTypes():
+ raise BranchTargetError(
+ '%s branches are not allowed for target %s' % (
+ self.information_type.title, self.target.displayname))
namespace.moveBranch(self, user, rename_if_necessary=True)
self._reconcileAccess()
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2012-08-30 21:59:39 +0000
+++ lib/lp/code/model/tests/test_branch.py 2012-09-17 14:00:26 +0000
@@ -3009,6 +3009,21 @@
self.assertEqual(
owner, get_policies_for_artifact(branch)[0].person)
+ def test_public_branch_to_proprietary_only_project(self):
+ # A branch cannot be moved to a target where the sharing policy does
+ # not allow it.
+ owner = self.factory.makePerson()
+ commercial_product = self.factory.makeProduct(
+ owner=owner,
+ branch_sharing_policy=BranchSharingPolicy.PROPRIETARY)
+ branch = self.factory.makeBranch(
+ owner=owner,
+ information_type=InformationType.PUBLIC)
+ with admin_logged_in():
+ self.assertRaises(
+ BranchTargetError, branch.setTarget, branch.owner,
+ commercial_product)
+
def make_proposal_and_branch_revision(factory, revno, revision_id,
userdata_target=False):
Follow ups