~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/browser/tests/test_branch.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
from lp.code.enums import (
47
47
    BranchLifecycleStatus,
48
48
    BranchType,
 
49
    BranchVisibilityRule,
49
50
    )
50
51
from lp.code.interfaces.branchtarget import IBranchTarget
51
52
from lp.testing import (
56
57
    person_logged_in,
57
58
    TestCaseWithFactory,
58
59
    )
59
 
from lp.testing.matchers import BrowsesWithQueryLimit
 
60
from lp.testing.matchers import (
 
61
    BrowsesWithQueryLimit,
 
62
    Contains,
 
63
    )
60
64
from lp.testing.views import create_initialized_view
61
65
 
62
66
 
844
848
        branch = self.factory.makeProductBranch()
845
849
        root_context = IRootContext(branch)
846
850
        self.assertEqual(branch.product, root_context)
 
851
 
 
852
 
 
853
class TestBranchEditView(TestCaseWithFactory):
 
854
 
 
855
    layer = DatabaseFunctionalLayer
 
856
 
 
857
    def test_allowed_owner_is_ok(self):
 
858
        # A branch's owner can be changed to a team permitted by the
 
859
        # visibility policy.
 
860
        person = self.factory.makePerson()
 
861
        branch = self.factory.makeProductBranch(owner=person)
 
862
        team = self.factory.makeTeam(
 
863
            owner=person, displayname="Permitted team")
 
864
        branch.product.setBranchVisibilityTeamPolicy(
 
865
            None, BranchVisibilityRule.FORBIDDEN)
 
866
        branch.product.setBranchVisibilityTeamPolicy(
 
867
            team, BranchVisibilityRule.PRIVATE)
 
868
        browser = self.getUserBrowser(
 
869
            canonical_url(branch) + '/+edit', user=person)
 
870
        browser.getControl("Owner").displayValue = ["Permitted team"]
 
871
        browser.getControl("Change Branch").click()
 
872
        with person_logged_in(person):
 
873
            self.assertEquals(team, branch.owner)
 
874
 
 
875
    def test_forbidden_owner_is_error(self):
 
876
        # An error is displayed if a branch's owner is changed to
 
877
        # a value forbidden by the visibility policy.
 
878
        product = self.factory.makeProduct(displayname='Some Product')
 
879
        person = self.factory.makePerson()
 
880
        branch = self.factory.makeBranch(product=product, owner=person)
 
881
        self.factory.makeTeam(
 
882
            owner=person, displayname="Forbidden team")
 
883
        branch.product.setBranchVisibilityTeamPolicy(
 
884
            None, BranchVisibilityRule.FORBIDDEN)
 
885
        branch.product.setBranchVisibilityTeamPolicy(
 
886
            person, BranchVisibilityRule.PRIVATE)
 
887
        browser = self.getUserBrowser(
 
888
            canonical_url(branch) + '/+edit', user=person)
 
889
        browser.getControl("Owner").displayValue = ["Forbidden team"]
 
890
        browser.getControl("Change Branch").click()
 
891
        self.assertThat(
 
892
            browser.contents,
 
893
            Contains(
 
894
                'Forbidden team is not allowed to own branches in '
 
895
                'Some Product.'))
 
896
        with person_logged_in(person):
 
897
            self.assertEquals(person, branch.owner)