/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
5010.2.15 by Vincent Ladeuil
Fix imports in per_branch/test_http.py.
20
    branch,
21
    errors,
22
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy.tests import (
5017.3.30 by Vincent Ladeuil
-s bt.per_branch.test_http passing
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())
7143.15.2 by Jelmer Vernooij
Run autopep8.
49
        self.make_branch(
50
            'parent/path/to/a').controldir.sprout(self.get_url('child/path/to/b'))
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
51
52
        # The child branch internally will have recorded that its parent is at
53
        # "../../../../parent/path/to/a" or similar.  So we move the child
54
        # branch up several directories, so that its parent path will point to
55
        # somewhere outside the directory served by the HTTP server.  Thus its
56
        # parent is now inaccessible.
57
        self.get_transport().rename('child/path/to/b', 'b')
58
        branch_b = branch.Branch.open(self.get_readonly_url('b'))
59
        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
60
61
    def test_get_parent_invalid(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
62
        # When you have a branch whose parent URL cannot be calculated, this
63
        # exception will be raised.
64
        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
65
        self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
66
67
    def test_clone_invalid_parent(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
68
        # If clone can't determine the location of the parent of the branch
69
        # being cloned, then the new branch will have no parent set.
70
        branch_b = self.get_branch_with_invalid_parent()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
71
        branch_c = branch_b.controldir.clone('c').open_branch()
1864.7.3 by John Arbash Meinel
Test that the right thing happens when clone/sprout is done with an invalid parent
72
        self.assertEqual(None, branch_c.get_parent())
73
74
    def test_sprout_invalid_parent(self):
2018.5.102 by Andrew Bennetts
Make branch_implementations/test_http.py a little clearer.
75
        # A sprouted branch will have a parent of the branch it was sprouted
76
        # from, even if that branch has an invalid parent.
77
        branch_b = self.get_branch_with_invalid_parent()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
78
        branch_c = branch_b.controldir.sprout('c').open_branch()
6874.1.2 by Jelmer Vernooij
Consistently use Branch.user_url.
79
        self.assertEqual(branch_b.user_url, branch_c.get_parent())