~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_directory_service.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2008 Canonical Ltd
2
2
#
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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Test directory service implementation"""
18
18
 
19
 
from bzrlib import (
20
 
    errors,
21
 
    transport,
22
 
    urlutils,
23
 
    )
24
 
from bzrlib.directory_service import (
25
 
    AliasDirectory,
26
 
    DirectoryServiceRegistry,
27
 
    directories,
28
 
    )
 
19
from bzrlib import errors
 
20
from bzrlib.directory_service import DirectoryServiceRegistry, directories
29
21
from bzrlib.tests import TestCase, TestCaseWithTransport
 
22
from bzrlib.transport import get_transport
30
23
 
31
24
 
32
25
class FooService(object):
33
26
    """A directory service that maps the name to a FILE url"""
34
27
 
35
 
    # eg 'file:///foo' on Unix, or 'file:///C:/foo' on Windows
36
 
    base = urlutils.local_path_to_url('/foo')
37
 
 
38
28
    def look_up(self, name, url):
39
 
        return self.base + name
 
29
        return 'file:///foo' + name
40
30
 
41
31
 
42
32
class TestDirectoryLookup(TestCase):
43
33
 
44
34
    def setUp(self):
45
 
        super(TestDirectoryLookup, self).setUp()
 
35
        TestCase.setUp(self)
46
36
        self.registry = DirectoryServiceRegistry()
47
37
        self.registry.register('foo:', FooService, 'Map foo URLs to http urls')
48
38
 
52
42
        self.assertEqual('bar', suffix)
53
43
 
54
44
    def test_dereference(self):
55
 
        self.assertEqual(FooService.base + 'bar',
 
45
        self.assertEqual('file:///foobar',
56
46
                         self.registry.dereference('foo:bar'))
57
47
        self.assertEqual('baz:qux', self.registry.dereference('baz:qux'))
58
48
 
59
49
    def test_get_transport(self):
60
50
        directories.register('foo:', FooService, 'Map foo URLs to http urls')
61
 
        self.addCleanup(directories.remove, 'foo:')
62
 
        self.assertEqual(FooService.base + 'bar/',
63
 
                         transport.get_transport('foo:bar').base)
 
51
        self.addCleanup(lambda: directories.remove('foo:'))
 
52
        self.assertEqual('file:///foobar/', get_transport('foo:bar').base)
64
53
 
65
54
 
66
55
class TestAliasDirectory(TestCaseWithTransport):
67
56
 
68
 
    def setUp(self):
69
 
        super(TestAliasDirectory, self).setUp()
70
 
        self.branch = self.make_branch('.')
71
 
 
72
 
    def assertAliasFromBranch(self, setter, value, alias):
73
 
        setter(value)
74
 
        self.assertEqual(value, directories.dereference(alias))
75
 
 
76
57
    def test_lookup_parent(self):
77
 
        self.assertAliasFromBranch(self.branch.set_parent, 'http://a',
78
 
                                  ':parent')
 
58
        branch = self.make_branch('.')
 
59
        branch.set_parent('http://a')
 
60
        self.assertEqual('http://a', directories.dereference(':parent'))
79
61
 
80
62
    def test_lookup_submit(self):
81
 
        self.assertAliasFromBranch(self.branch.set_submit_branch, 'http://b',
82
 
                                   ':submit')
 
63
        branch = self.make_branch('.')
 
64
        branch.set_submit_branch('http://b')
 
65
        self.assertEqual('http://b', directories.dereference(':submit'))
83
66
 
84
67
    def test_lookup_public(self):
85
 
        self.assertAliasFromBranch(self.branch.set_public_branch, 'http://c',
86
 
                                   ':public')
 
68
        branch = self.make_branch('.')
 
69
        branch.set_public_branch('http://c')
 
70
        self.assertEqual('http://c', directories.dereference(':public'))
87
71
 
88
72
    def test_lookup_bound(self):
89
 
        self.assertAliasFromBranch(self.branch.set_bound_location, 'http://d',
90
 
                                   ':bound')
 
73
        branch = self.make_branch('.')
 
74
        branch.set_bound_location('http://d')
 
75
        self.assertEqual('http://d', directories.dereference(':bound'))
91
76
 
92
77
    def test_lookup_push(self):
93
 
        self.assertAliasFromBranch(self.branch.set_push_location, 'http://e',
94
 
                                   ':push')
 
78
        branch = self.make_branch('.')
 
79
        branch.set_push_location('http://e')
 
80
        self.assertEqual('http://e', directories.dereference(':push'))
95
81
 
96
82
    def test_lookup_this(self):
97
 
        self.assertEqual(self.branch.base, directories.dereference(':this'))
98
 
 
99
 
    def test_extra_path(self):
100
 
        self.assertEqual(urlutils.join(self.branch.base, 'arg'),
101
 
                         directories.dereference(':this/arg'))
 
83
        branch = self.make_branch('.')
 
84
        self.assertEqual(branch.base, directories.dereference(':this'))
102
85
 
103
86
    def test_lookup_badname(self):
 
87
        branch = self.make_branch('.')
104
88
        e = self.assertRaises(errors.InvalidLocationAlias,
105
89
                              directories.dereference, ':booga')
106
90
        self.assertEqual('":booga" is not a valid location alias.',
107
91
                         str(e))
108
92
 
109
93
    def test_lookup_badvalue(self):
 
94
        branch = self.make_branch('.')
110
95
        e = self.assertRaises(errors.UnsetLocationAlias,
111
96
                              directories.dereference, ':parent')
112
97
        self.assertEqual('No parent location assigned.', str(e))
113
 
 
114
 
    def test_register_location_alias(self):
115
 
        self.addCleanup(AliasDirectory.branch_aliases.remove, "booga")
116
 
        AliasDirectory.branch_aliases.register("booga",
117
 
            lambda b: "UHH?", help="Nobody knows")
118
 
        self.assertEqual("UHH?", directories.dereference(":booga"))
119
 
 
120
 
 
121
 
class TestColocatedDirectory(TestCaseWithTransport):
122
 
 
123
 
    def test_lookup_non_default(self):
124
 
        default = self.make_branch('.')
125
 
        non_default = default.bzrdir.create_branch(name='nondefault')
126
 
        self.assertEqual(non_default.base, directories.dereference('co:nondefault'))
127
 
 
128
 
    def test_lookup_default(self):
129
 
        default = self.make_branch('.')
130
 
        non_default = default.bzrdir.create_branch(name='nondefault')
131
 
        self.assertEqual(urlutils.join_segment_parameters(default.bzrdir.user_url,
132
 
            {"branch": ""}), directories.dereference('co:'))
133
 
 
134
 
    def test_no_such_branch(self):
135
 
        # No error is raised in this case, that is up to the code that actually
136
 
        # opens the branch.
137
 
        default = self.make_branch('.')
138
 
        self.assertEqual(urlutils.join_segment_parameters(default.bzrdir.user_url,
139
 
            {"branch": "foo"}), directories.dereference('co:foo'))