14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test branch responses when accessed over http"""
17
"""Test branches with inaccessible parents."""
21
21
from bzrlib import branch, errors
22
22
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
23
23
from bzrlib.tests.HttpServer import HttpServer
26
class HTTPBranchTests(TestCaseWithBranch):
27
"""Tests that use an HTTP server against each branch implementation"""
24
from bzrlib.transport.local import LocalURLServer
25
from bzrlib.transport.chroot import TestingChrootServer
28
class InaccessibleParentTests(TestCaseWithBranch):
29
"""Tests with branches with "inaccessible" parents.
31
An "inaccessible" parent location is one that cannot be represented, e.g. if
32
a child branch says its parent is at "../../my-parent", but that child is at
33
"http://host/one" then that parent location is inaccessible. These
34
branches' get_parent method will raise InaccessibleParent.
30
super(HTTPBranchTests, self).setUp()
31
self.transport_readonly_server = HttpServer
33
def get_parent_and_child(self):
34
os.makedirs('parent/path/to')
35
wt_a = self.make_branch_and_tree('parent/path/to/a')
36
self.build_tree(['parent/path/to/a/one'])
38
wt_a.commit('commit one', rev_id='1')
40
os.makedirs('child/path/to')
41
branch_b = wt_a.bzrdir.sprout('child/path/to/b', revision_id='1').open_branch()
42
self.assertEqual(wt_a.branch.base, branch_b.get_parent())
44
return wt_a.branch, branch_b
38
super(InaccessibleParentTests, self).setUp()
39
if self.transport_server in (LocalURLServer, None):
40
self.transport_readonly_server = TestingChrootServer
42
def get_branch_with_invalid_parent(self):
43
"""Get a branch whose get_parent will raise InaccessibleParent."""
45
['parent/', 'parent/path/', 'parent/path/to/',
46
'child/', 'child/path/', 'child/path/to/'],
47
transport=self.get_transport())
48
self.make_branch('parent/path/to/a').bzrdir.sprout(self.get_url('child/path/to/b'))
50
# The child branch internally will have recorded that its parent is at
51
# "../../../../parent/path/to/a" or similar. So we move the child
52
# branch up several directories, so that its parent path will point to
53
# somewhere outside the directory served by the HTTP server. Thus its
54
# parent is now inaccessible.
55
self.get_transport().rename('child/path/to/b', 'b')
56
branch_b = branch.Branch.open(self.get_readonly_url('b'))
46
59
def test_get_parent_invalid(self):
47
self.get_parent_and_child()
49
# Now change directory, and access the child through http
50
os.chdir('child/path/to')
51
branch_b = branch.Branch.open(self.get_readonly_url('b'))
60
# When you have a branch whose parent URL cannot be calculated, this
61
# exception will be raised.
62
branch_b = self.get_branch_with_invalid_parent()
52
63
self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
54
65
def test_clone_invalid_parent(self):
55
self.get_parent_and_child()
57
# Now change directory, and access the child through http
58
os.chdir('child/path/to')
59
branch_b = branch.Branch.open(self.get_readonly_url('b'))
66
# If clone can't determine the location of the parent of the branch
67
# being cloned, then the new branch will have no parent set.
68
branch_b = self.get_branch_with_invalid_parent()
61
69
branch_c = branch_b.bzrdir.clone('c').open_branch()
62
70
self.assertEqual(None, branch_c.get_parent())
64
72
def test_sprout_invalid_parent(self):
65
self.get_parent_and_child()
67
# Now change directory, and access the child through http
68
os.chdir('child/path/to')
69
branch_b = branch.Branch.open(self.get_readonly_url('b'))
73
# A sprouted branch will have a parent of the branch it was sprouted
74
# from, even if that branch has an invalid parent.
75
branch_b = self.get_branch_with_invalid_parent()
71
76
branch_c = branch_b.bzrdir.sprout('c').open_branch()
72
77
self.assertEqual(branch_b.base, branch_c.get_parent())