/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2008-08-20 02:07:36 UTC
  • mfrom: (3640 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20080820020736-g2xe4921zzxtymle
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
17
"""Test branches with inaccessible parents."""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib import branch, errors
 
22
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
23
from bzrlib.tests.http_server import HttpServer
 
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
    """
 
36
 
 
37
    def setUp(self):
 
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
 
58
 
 
59
    def test_get_parent_invalid(self):
 
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()
 
63
        self.assertRaises(errors.InaccessibleParent, branch_b.get_parent)
 
64
 
 
65
    def test_clone_invalid_parent(self):
 
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()
 
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):
 
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()
 
76
        branch_c = branch_b.bzrdir.sprout('c').open_branch()
 
77
        self.assertEqual(branch_b.base, branch_c.get_parent())