Beispiel #1
0
 def test_getByPath(self):
     branch = self.factory.makeProductBranch()
     self.assertEqual(branch, BranchSet().getByPath(branch.shortened_path))
     product = removeSecurityProxy(branch.product)
     ICanHasLinkedBranch(product).setBranch(branch)
     clear_property_cache(branch)
     self.assertEqual(product.name, branch.shortened_path)
     self.assertEqual(branch, BranchSet().getByPath(branch.shortened_path))
     self.assertIsNone(BranchSet().getByPath('nonexistent'))
Beispiel #2
0
 def test_getBranchVisibilityInfo_empty_branch_names(self):
     """Test the test_getBranchVisibilityInfo API with no branch names."""
     person = self.factory.makePerson(name='fred')
     info = BranchSet().getBranchVisibilityInfo(
         person, person, branch_names=[])
     self.assertEqual('Fred', info['person_name'])
     self.assertEqual([], info['visible_branches'])
Beispiel #3
0
 def test_getByUrls(self):
     # getByUrls returns a list of branches matching the list of URLs that
     # it's given.
     a = self.factory.makeAnyBranch()
     b = self.factory.makeAnyBranch()
     branches = BranchSet().getByUrls(
         [a.bzr_identity, b.bzr_identity])
     self.assertEqual({a.bzr_identity: a, b.bzr_identity: b}, branches)
Beispiel #4
0
    def test_getBranchVisibilityInfo_anonymous(self):
        """Test the test_getBranchVisibilityInfo API.

        Anonymous users are not allowed to see any branch visibility info,
        even if the branch they are querying about is public.
        """
        person = self.factory.makePerson(name='fred')
        owner = self.factory.makePerson()
        visible_branch = self.factory.makeBranch(owner=owner)
        branches = [visible_branch.unique_name]

        login_person(owner)
        info = BranchSet().getBranchVisibilityInfo(
            None, person, branch_names=branches)
        self.assertEqual({}, info)
Beispiel #5
0
    def test_getBranchVisibilityInfo(self):
        """Test the test_getBranchVisibilityInfo API."""
        person = self.factory.makePerson(name='fred')
        owner = self.factory.makePerson()
        visible_branch = self.factory.makeBranch()
        invisible_branch = self.factory.makeBranch(
            owner=owner, information_type=InformationType.USERDATA)
        invisible_name = removeSecurityProxy(invisible_branch).unique_name
        branches = [
            visible_branch.unique_name,
            invisible_name]

        login_person(owner)
        info = BranchSet().getBranchVisibilityInfo(
            owner, person, branch_names=branches)
        self.assertEqual('Fred', info['person_name'])
        self.assertEqual(
            [visible_branch.unique_name], info['visible_branches'])
Beispiel #6
0
    def test_getBranchVisibilityInfo_invalid_branch_name(self):
        """Test the test_getBranchVisibilityInfo API.

        If there is an invalid branch name specified, it is not included.
        """
        person = self.factory.makePerson(name='fred')
        owner = self.factory.makePerson()
        visible_branch = self.factory.makeBranch(owner=owner)
        branches = [
            visible_branch.unique_name,
            'invalid_branch_name']

        login_person(owner)
        info = BranchSet().getBranchVisibilityInfo(
            owner, person, branch_names=branches)
        self.assertEqual('Fred', info['person_name'])
        self.assertEqual(
            [visible_branch.unique_name], info['visible_branches'])
Beispiel #7
0
    def test_getBranchVisibilityInfo_unauthorised_user(self):
        """Test the test_getBranchVisibilityInfo API.

        If the user making the API request cannot see one of the branches,
        that branch is not included in the results.
        """
        person = self.factory.makePerson(name='fred')
        owner = self.factory.makePerson()
        visible_branch = self.factory.makeBranch()
        invisible_branch = self.factory.makeBranch(
            owner=owner, information_type=InformationType.USERDATA)
        invisible_name = removeSecurityProxy(invisible_branch).unique_name
        branches = [
            visible_branch.unique_name,
            invisible_name]

        someone = self.factory.makePerson()
        login_person(someone)
        info = BranchSet().getBranchVisibilityInfo(
            someone, person, branch_names=branches)
        self.assertEqual('Fred', info['person_name'])
        self.assertEqual(
            [visible_branch.unique_name], info['visible_branches'])
Beispiel #8
0
 def test_getByUrls_cant_find_url(self):
     # If a branch cannot be found for a URL, then None appears in the list
     # in place of the branch.
     url = 'http://example.com/doesntexist'
     branches = BranchSet().getByUrls([url])
     self.assertEqual({url: None}, branches)
Beispiel #9
0
 def test_provides_IBranchSet(self):
     # BranchSet instances provide IBranchSet.
     self.assertProvides(BranchSet(), IBranchSet)