/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/test_directory_service.py

Merge with serialize-transform

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 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 directory service implementation"""
 
18
 
 
19
from bzrlib import errors
 
20
from bzrlib.directory_service import DirectoryServiceRegistry, directories
 
21
from bzrlib.tests import TestCase, TestCaseWithTransport
 
22
from bzrlib.transport import get_transport
 
23
from bzrlib import urlutils
 
24
 
 
25
 
 
26
class FooService(object):
 
27
    """A directory service that maps the name to a FILE url"""
 
28
 
 
29
    def look_up(self, name, url):
 
30
        return 'file:///foo' + name
 
31
 
 
32
 
 
33
class TestDirectoryLookup(TestCase):
 
34
 
 
35
    def setUp(self):
 
36
        TestCase.setUp(self)
 
37
        self.registry = DirectoryServiceRegistry()
 
38
        self.registry.register('foo:', FooService, 'Map foo URLs to http urls')
 
39
 
 
40
    def test_get_directory_service(self):
 
41
        directory, suffix = self.registry.get_prefix('foo:bar')
 
42
        self.assertIs(FooService, directory)
 
43
        self.assertEqual('bar', suffix)
 
44
 
 
45
    def test_dereference(self):
 
46
        self.assertEqual('file:///foobar',
 
47
                         self.registry.dereference('foo:bar'))
 
48
        self.assertEqual('baz:qux', self.registry.dereference('baz:qux'))
 
49
 
 
50
    def test_get_transport(self):
 
51
        directories.register('foo:', FooService, 'Map foo URLs to http urls')
 
52
        self.addCleanup(lambda: directories.remove('foo:'))
 
53
        self.assertEqual('file:///foobar/', get_transport('foo:bar').base)
 
54
 
 
55
 
 
56
class TestAliasDirectory(TestCaseWithTransport):
 
57
 
 
58
    def test_lookup_parent(self):
 
59
        branch = self.make_branch('.')
 
60
        branch.set_parent('http://a')
 
61
        self.assertEqual('http://a', directories.dereference(':parent'))
 
62
 
 
63
    def test_lookup_submit(self):
 
64
        branch = self.make_branch('.')
 
65
        branch.set_submit_branch('http://b')
 
66
        self.assertEqual('http://b', directories.dereference(':submit'))
 
67
 
 
68
    def test_lookup_public(self):
 
69
        branch = self.make_branch('.')
 
70
        branch.set_public_branch('http://c')
 
71
        self.assertEqual('http://c', directories.dereference(':public'))
 
72
 
 
73
    def test_lookup_bound(self):
 
74
        branch = self.make_branch('.')
 
75
        branch.set_bound_location('http://d')
 
76
        self.assertEqual('http://d', directories.dereference(':bound'))
 
77
 
 
78
    def test_lookup_push(self):
 
79
        branch = self.make_branch('.')
 
80
        branch.set_push_location('http://e')
 
81
        self.assertEqual('http://e', directories.dereference(':push'))
 
82
 
 
83
    def test_lookup_this(self):
 
84
        branch = self.make_branch('.')
 
85
        self.assertEqual(branch.base, directories.dereference(':this'))
 
86
 
 
87
    def test_extra_path(self):
 
88
        branch = self.make_branch('.')
 
89
        self.assertEqual(urlutils.join(branch.base, 'arg'),
 
90
                         directories.dereference(':this/arg'))
 
91
 
 
92
    def test_lookup_badname(self):
 
93
        branch = self.make_branch('.')
 
94
        e = self.assertRaises(errors.InvalidLocationAlias,
 
95
                              directories.dereference, ':booga')
 
96
        self.assertEqual('":booga" is not a valid location alias.',
 
97
                         str(e))
 
98
 
 
99
    def test_lookup_badvalue(self):
 
100
        branch = self.make_branch('.')
 
101
        e = self.assertRaises(errors.UnsetLocationAlias,
 
102
                              directories.dereference, ':parent')
 
103
        self.assertEqual('No parent location assigned.', str(e))