~bzr-pqm/bzr/bzr.dev

1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
1
# Copyright (C) 2006 Canonical Ltd
2
#
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.
7
#
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.
12
#
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
16
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
17
"""Test branches with inaccessible parents."""
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
18
19
import os
20
21
from bzrlib import branch, errors
22
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
3102.1.1 by Vincent Ladeuil
Rename bzrlib/test/HTTPTestUtils.py to bzrlib/tests/http_utils.py and fix
23
from bzrlib.tests.http_server import HttpServer
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
24
from bzrlib.transport.local import LocalURLServer
2018.5.104 by Andrew Bennetts
Completely rework chrooted transports.
25
from bzrlib.transport.chroot import TestingChrootServer
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
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
    """
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
36
37
    def setUp(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
38
        super(InaccessibleParentTests, self).setUp()
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
39
        if self.transport_server in (LocalURLServer, None):
40
            self.transport_readonly_server = TestingChrootServer
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
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
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
58
59
    def test_get_parent_invalid(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
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()
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
63
        self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
64
65
    def test_clone_invalid_parent(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
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()
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
69
        branch_c = branch_b.bzrdir.clone('c').open_branch()
70
        self.assertEqual(None, branch_c.get_parent())
71
72
    def test_sprout_invalid_parent(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
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()
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
76
        branch_c = branch_b.bzrdir.sprout('c').open_branch()
77
        self.assertEqual(branch_b.base, branch_c.get_parent())