~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_http.py

  • Committer: Martin Pool
  • Date: 2007-04-04 01:22:11 UTC
  • mfrom: (2393.1.1 bzr.docs)
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: mbp@sourcefrog.net-20070404012211-sq269me6bai9m6xk
merge trunk and doc fix from elliot

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
17
 
"""Test branch responses when accessed over http"""
 
17
"""Test branches with inaccessible parents."""
18
18
 
19
19
import os
20
20
 
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
24
 
 
25
 
 
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
 
26
 
 
27
 
 
28
class InaccessibleParentTests(TestCaseWithBranch):
 
29
    """Tests with branches with "inaccessible" parents.
 
30
    
 
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.
 
35
    """
28
36
 
29
37
    def setUp(self):
30
 
        super(HTTPBranchTests, self).setUp()
31
 
        self.transport_readonly_server = HttpServer
32
 
 
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'])
37
 
        wt_a.add(['one'])
38
 
        wt_a.commit('commit one', rev_id='1')
39
 
 
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())
43
 
 
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
 
41
 
 
42
    def get_branch_with_invalid_parent(self):
 
43
        """Get a branch whose get_parent will raise InaccessibleParent."""
 
44
        self.build_tree(
 
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'))
 
49
 
 
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'))
 
57
        return branch_b
45
58
 
46
59
    def test_get_parent_invalid(self):
47
 
        self.get_parent_and_child()
48
 
 
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)
53
64
 
54
65
    def test_clone_invalid_parent(self):
55
 
        self.get_parent_and_child()
56
 
 
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'))
60
 
 
 
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())
63
71
 
64
72
    def test_sprout_invalid_parent(self):
65
 
        self.get_parent_and_child()
66
 
 
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'))
70
 
 
 
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())