1
# Copyright (C) 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test branch responses when accessed over http"""
21
from bzrlib import branch, errors
22
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
23
from bzrlib.transport.http import HttpServer
26
class HTTPBranchTests(TestCaseWithBranch):
27
"""Tests that use an HTTP server against each branch implementation"""
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
46
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'))
52
self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
54
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'))
61
branch_c = branch_b.bzrdir.clone('c').open_branch()
62
self.assertEqual(None, branch_c.get_parent())
64
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'))
71
branch_c = branch_b.bzrdir.sprout('c').open_branch()
72
self.assertEqual(branch_b.base, branch_c.get_parent())