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