1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from bzrlib.branch import Branch
23
20
import bzrlib.errors
24
from bzrlib.osutils import abspath, realpath, getcwd
25
from bzrlib.urlutils import local_path_from_url, local_path_to_url, escape
21
from bzrlib.osutils import getcwd
26
22
from bzrlib.tests import TestCaseWithTransport
23
from bzrlib import urlutils
29
26
"""Tests for Branch parent URL"""
39
36
def test_set_get_parent(self):
40
37
"""Set, re-get and reset the parent"""
41
b = self.make_branch('.')
38
b = self.make_branch('subdir')
42
39
url = 'http://bazaar-vcs.org/bzr/bzr.dev'
44
41
self.assertEqual(url, b.get_parent())
45
self.assertEqual(url, b.control_files.get('parent').read().strip('\n'))
42
self.assertEqual(url, b._get_parent_location())
48
45
self.assertEqual(None, b.get_parent())
50
47
b.set_parent('../other_branch')
52
self.assertEqual(local_path_to_url('../other_branch'), b.get_parent())
53
path = local_path_to_url('../yanb')
49
expected_parent = urlutils.join(self.get_url('subdir'),
51
self.assertEqual(expected_parent, b.get_parent())
52
path = urlutils.join(self.get_url('subdir'), '../yanb')
55
self.assertEqual('../yanb',
56
b.control_files.get('parent').read().strip('\n'))
54
self.assertEqual('../yanb', b._get_parent_location())
57
55
self.assertEqual(path, b.get_parent())
60
58
self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5')
61
b.set_parent(escape(u'\xb5'))
62
self.assertEqual('%C2%B5',
63
b.control_files.get('parent').read().strip('\n'))
59
b.set_parent(urlutils.escape(u'\xb5'))
60
self.assertEqual('%C2%B5', b._get_parent_location())
65
62
self.assertEqual(b.base + '%C2%B5', b.get_parent())
70
67
# paths as well? Nobody has complained about it.
73
b.control_files.put('parent', cStringIO.StringIO('/local/abs/path'))
70
b._set_parent_location('/local/abs/path')
74
71
self.assertEqual('file:///local/abs/path', b.get_parent())
76
73
def test_get_invalid_parent(self):
82
79
# Force the relative path to be something invalid
83
80
# This should attempt to go outside the filesystem
84
81
path = ('../'*(n_dirs+5)) + 'foo'
85
b.control_files.put('parent', cStringIO.StringIO(path))
82
b._set_parent_location(path)
87
84
# With an invalid branch parent, just return None
88
85
self.assertRaises(bzrlib.errors.InaccessibleParent, b.get_parent)