25
25
ILinkedBranchTraverser,
27
27
from lp.code.interfaces.branchnamespace import get_branch_namespace
28
from lp.code.interfaces.codehosting import BRANCH_ID_ALIAS_PREFIX
28
from lp.code.interfaces.codehosting import (
30
BRANCH_ID_ALIAS_PREFIX,
29
32
from lp.code.interfaces.linkedbranch import ICanHasLinkedBranch
30
33
from lp.registry.errors import (
31
34
NoSuchDistroSeries,
137
140
owner = self.factory.makePerson()
138
141
branch = self.factory.makeAnyBranch(owner=owner, private=True)
139
142
with person_logged_in(owner):
140
path = '/%s/%s' % (BRANCH_ID_ALIAS_PREFIX, branch.id)
143
path = branch_id_alias(branch)
141
144
result = self.branch_set.getIdAndTrailingPath(path)
142
145
self.assertEqual((None, None), result)
144
147
def test_branch_id_alias_public(self):
145
148
# Public branches can be accessed.
146
149
branch = self.factory.makeAnyBranch()
147
path = '/%s/%s' % (BRANCH_ID_ALIAS_PREFIX, branch.id)
150
path = branch_id_alias(branch)
148
151
result = self.branch_set.getIdAndTrailingPath(path)
149
152
self.assertEqual((branch.id, ''), result)
151
154
def test_branch_id_alias_public_slash(self):
152
155
# A trailing slash is returned as the extra path.
153
156
branch = self.factory.makeAnyBranch()
154
path = '/%s/%s/' % (BRANCH_ID_ALIAS_PREFIX, branch.id)
157
path = '%s/' % branch_id_alias(branch)
155
158
result = self.branch_set.getIdAndTrailingPath(path)
156
159
self.assertEqual((branch.id, '/'), result)
158
161
def test_branch_id_alias_public_with_path(self):
159
162
# All the path after the number is returned as the trailing path.
160
163
branch = self.factory.makeAnyBranch()
161
path = '/%s/%s/foo' % (BRANCH_ID_ALIAS_PREFIX, branch.id)
164
path = '%s/foo' % branch_id_alias(branch)
162
165
result = self.branch_set.getIdAndTrailingPath(path)
163
166
self.assertEqual((branch.id, '/foo'), result)