~bzr-pqm/bzr/bzr.dev

4988.10.5 by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS
1
# Copyright (C) 2006-2010 Canonical Ltd
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
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
5010.2.15 by Vincent Ladeuil
Fix imports in per_branch/test_http.py.
19
from bzrlib import (
20
    branch,
21
    errors,
22
    )
5017.3.30 by Vincent Ladeuil
-s bt.per_branch.test_http passing
23
from bzrlib.tests import (
24
    per_branch,
25
    test_server,
5010.2.15 by Vincent Ladeuil
Fix imports in per_branch/test_http.py.
26
    )
27
28
29
class InaccessibleParentTests(per_branch.TestCaseWithBranch):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
30
    """Tests with branches with "inaccessible" parents.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
31
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
32
    An "inaccessible" parent location is one that cannot be represented, e.g. if
33
    a child branch says its parent is at "../../my-parent", but that child is at
34
    "http://host/one" then that parent location is inaccessible.  These
35
    branches' get_parent method will raise InaccessibleParent.
36
    """
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
37
38
    def setUp(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
39
        super(InaccessibleParentTests, self).setUp()
5017.3.30 by Vincent Ladeuil
-s bt.per_branch.test_http passing
40
        if self.transport_server in (test_server.LocalURLServer, None):
41
            self.transport_readonly_server = test_server.TestingChrootServer
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
42
43
    def get_branch_with_invalid_parent(self):
44
        """Get a branch whose get_parent will raise InaccessibleParent."""
45
        self.build_tree(
46
            ['parent/', 'parent/path/', 'parent/path/to/',
47
             'child/', 'child/path/', 'child/path/to/'],
48
            transport=self.get_transport())
49
        self.make_branch('parent/path/to/a').bzrdir.sprout(self.get_url('child/path/to/b'))
50
51
        # The child branch internally will have recorded that its parent is at
52
        # "../../../../parent/path/to/a" or similar.  So we move the child
53
        # branch up several directories, so that its parent path will point to
54
        # somewhere outside the directory served by the HTTP server.  Thus its
55
        # parent is now inaccessible.
56
        self.get_transport().rename('child/path/to/b', 'b')
57
        branch_b = branch.Branch.open(self.get_readonly_url('b'))
58
        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
59
60
    def test_get_parent_invalid(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
61
        # When you have a branch whose parent URL cannot be calculated, this
62
        # exception will be raised.
63
        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
64
        self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
65
66
    def test_clone_invalid_parent(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
67
        # If clone can't determine the location of the parent of the branch
68
        # being cloned, then the new branch will have no parent set.
69
        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
70
        branch_c = branch_b.bzrdir.clone('c').open_branch()
71
        self.assertEqual(None, branch_c.get_parent())
72
73
    def test_sprout_invalid_parent(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
74
        # A sprouted branch will have a parent of the branch it was sprouted
75
        # from, even if that branch has an invalid parent.
76
        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
77
        branch_c = branch_b.bzrdir.sprout('c').open_branch()
78
        self.assertEqual(branch_b.base, branch_c.get_parent())