~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/xmlrpc/tests/test_codehosting.py

Tests for expected behaviour of translate path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
from lp.code.interfaces.branchtarget import IBranchTarget
42
42
from lp.code.interfaces.codehosting import (
43
43
    BRANCH_ALIAS_PREFIX,
 
44
    BRANCH_ID_ALIAS_PREFIX,
44
45
    BRANCH_TRANSPORT,
45
46
    CONTROL_TRANSPORT,
46
47
    )
991
992
        requester = self.factory.makePerson()
992
993
        self.assertNotFound(requester, '/%s/.bzr' % BRANCH_ALIAS_PREFIX)
993
994
 
 
995
    def test_translatePath_branch_id_alias_bzrdir_content(self):
 
996
        # translatePath('/+branch-id/.bzr/.*') *must* return not found, otherwise
 
997
        # bzr will look for it and we don't have a global bzr dir.
 
998
        requester = self.factory.makePerson()
 
999
        self.assertNotFound(
 
1000
            requester, '/%s/.bzr/branch-format' % BRANCH_ID_ALIAS_PREFIX)
 
1001
 
 
1002
    def test_translatePath_branch_id_alias_bzrdir(self):
 
1003
        # translatePath('/+branch-id/.bzr') *must* return not found, otherwise
 
1004
        # bzr will look for it and we don't have a global bzr dir.
 
1005
        requester = self.factory.makePerson()
 
1006
        self.assertNotFound(requester, '/%s/.bzr' % BRANCH_ID_ALIAS_PREFIX)
 
1007
 
 
1008
    def test_translatePath_branch_id_alias_owned(self):
 
1009
        # Even if the the requester is the owner, the branch is read only.
 
1010
        requester = self.factory.makePerson()
 
1011
        branch = self.factory.makeAnyBranch(
 
1012
            branch_type=BranchType.HOSTED, owner=requester)
 
1013
        path = escape(u'/%s/%s' % (BRANCH_ID_ALIAS_PREFIX, branch.id))
 
1014
        translation = self.codehosting_api.translatePath(requester.id, path)
 
1015
        self.assertEqual(
 
1016
            (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''),
 
1017
            translation)
 
1018
 
 
1019
    def test_translatePath_branch_id_alias_private_branch(self):
 
1020
        requester = self.factory.makePerson()
 
1021
        branch = removeSecurityProxy(
 
1022
            self.factory.makeAnyBranch(
 
1023
                branch_type=BranchType.HOSTED, private=True, owner=requester))
 
1024
        path = escape(u'/%s/%s' % (BRANCH_ID_ALIAS_PREFIX, branch.id))
 
1025
        translation = self.codehosting_api.translatePath(requester.id, path)
 
1026
        self.assertEqual(
 
1027
            (BRANCH_TRANSPORT, {'id': branch.id, 'writable': False}, ''),
 
1028
            translation)
 
1029
 
 
1030
    def test_translatePath_branch_id_alias_private_branch_no_access(self):
 
1031
        requester = self.factory.makePerson()
 
1032
        branch = removeSecurityProxy(
 
1033
            self.factory.makeAnyBranch(
 
1034
                branch_type=BranchType.HOSTED, private=True))
 
1035
        path = escape(u'/%s/%s' % (BRANCH_ID_ALIAS_PREFIX, branch.id))
 
1036
        self.assertPermissionDenied(requester, path)
 
1037
 
994
1038
    def assertTranslationIsControlDirectory(self, translation,
995
1039
                                            default_stacked_on,
996
1040
                                            trailing_path):