4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
|
3251.3.1
by Aaron Bentley
Add support for directory services |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
3251.3.1
by Aaron Bentley
Add support for directory services |
16 |
|
17 |
"""Test directory service implementation"""
|
|
18 |
||
4789.13.1
by John Arbash Meinel
Change the DirectoryService tests a little bit. |
19 |
from bzrlib import ( |
20 |
errors, |
|
5273.1.7
by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through |
21 |
transport, |
4789.13.1
by John Arbash Meinel
Change the DirectoryService tests a little bit. |
22 |
urlutils, |
23 |
)
|
|
3251.3.1
by Aaron Bentley
Add support for directory services |
24 |
from bzrlib.directory_service import DirectoryServiceRegistry, directories |
3512.2.1
by Aaron Bentley
Add support for branch-associated locations |
25 |
from bzrlib.tests import TestCase, TestCaseWithTransport |
3625.1.2
by Michael Hudson
import urlutils and write urlutils.join rather than join |
26 |
|
3251.3.1
by Aaron Bentley
Add support for directory services |
27 |
|
28 |
class FooService(object): |
|
29 |
"""A directory service that maps the name to a FILE url"""
|
|
30 |
||
5278.1.2
by Martin Pool
Don't say 'Linux' except when specifically talking about the kernel |
31 |
# eg 'file:///foo' on Unix, or 'file:///C:/foo' on Windows
|
4789.13.1
by John Arbash Meinel
Change the DirectoryService tests a little bit. |
32 |
base = urlutils.local_path_to_url('/foo') |
33 |
||
3251.3.1
by Aaron Bentley
Add support for directory services |
34 |
def look_up(self, name, url): |
4789.13.1
by John Arbash Meinel
Change the DirectoryService tests a little bit. |
35 |
return self.base + name |
3251.3.1
by Aaron Bentley
Add support for directory services |
36 |
|
37 |
||
38 |
class TestDirectoryLookup(TestCase): |
|
39 |
||
40 |
def setUp(self): |
|
41 |
TestCase.setUp(self) |
|
42 |
self.registry = DirectoryServiceRegistry() |
|
43 |
self.registry.register('foo:', FooService, 'Map foo URLs to http urls') |
|
44 |
||
45 |
def test_get_directory_service(self): |
|
46 |
directory, suffix = self.registry.get_prefix('foo:bar') |
|
47 |
self.assertIs(FooService, directory) |
|
48 |
self.assertEqual('bar', suffix) |
|
49 |
||
50 |
def test_dereference(self): |
|
4789.13.1
by John Arbash Meinel
Change the DirectoryService tests a little bit. |
51 |
self.assertEqual(FooService.base + 'bar', |
3251.3.1
by Aaron Bentley
Add support for directory services |
52 |
self.registry.dereference('foo:bar')) |
53 |
self.assertEqual('baz:qux', self.registry.dereference('baz:qux')) |
|
54 |
||
55 |
def test_get_transport(self): |
|
56 |
directories.register('foo:', FooService, 'Map foo URLs to http urls') |
|
4985.2.1
by Vincent Ladeuil
Deploy addAttrCleanup on the whole test suite. |
57 |
self.addCleanup(directories.remove, 'foo:') |
4789.13.1
by John Arbash Meinel
Change the DirectoryService tests a little bit. |
58 |
self.assertEqual(FooService.base + 'bar/', |
5273.1.7
by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through |
59 |
transport.get_transport('foo:bar').base) |
3512.2.1
by Aaron Bentley
Add support for branch-associated locations |
60 |
|
61 |
||
62 |
class TestAliasDirectory(TestCaseWithTransport): |
|
63 |
||
64 |
def test_lookup_parent(self): |
|
65 |
branch = self.make_branch('.') |
|
66 |
branch.set_parent('http://a') |
|
67 |
self.assertEqual('http://a', directories.dereference(':parent')) |
|
68 |
||
69 |
def test_lookup_submit(self): |
|
70 |
branch = self.make_branch('.') |
|
71 |
branch.set_submit_branch('http://b') |
|
72 |
self.assertEqual('http://b', directories.dereference(':submit')) |
|
73 |
||
74 |
def test_lookup_public(self): |
|
75 |
branch = self.make_branch('.') |
|
76 |
branch.set_public_branch('http://c') |
|
77 |
self.assertEqual('http://c', directories.dereference(':public')) |
|
78 |
||
79 |
def test_lookup_bound(self): |
|
80 |
branch = self.make_branch('.') |
|
81 |
branch.set_bound_location('http://d') |
|
82 |
self.assertEqual('http://d', directories.dereference(':bound')) |
|
83 |
||
3512.2.2
by Aaron Bentley
Add :push and :this |
84 |
def test_lookup_push(self): |
85 |
branch = self.make_branch('.') |
|
86 |
branch.set_push_location('http://e') |
|
87 |
self.assertEqual('http://e', directories.dereference(':push')) |
|
88 |
||
89 |
def test_lookup_this(self): |
|
90 |
branch = self.make_branch('.') |
|
91 |
self.assertEqual(branch.base, directories.dereference(':this')) |
|
92 |
||
3625.1.1
by Michael Hudson
Allow appending path segments to the :<name> style aliases. |
93 |
def test_extra_path(self): |
94 |
branch = self.make_branch('.') |
|
3625.1.2
by Michael Hudson
import urlutils and write urlutils.join rather than join |
95 |
self.assertEqual(urlutils.join(branch.base, 'arg'), |
96 |
directories.dereference(':this/arg')) |
|
3625.1.1
by Michael Hudson
Allow appending path segments to the :<name> style aliases. |
97 |
|
3512.2.1
by Aaron Bentley
Add support for branch-associated locations |
98 |
def test_lookup_badname(self): |
99 |
branch = self.make_branch('.') |
|
100 |
e = self.assertRaises(errors.InvalidLocationAlias, |
|
101 |
directories.dereference, ':booga') |
|
102 |
self.assertEqual('":booga" is not a valid location alias.', |
|
103 |
str(e)) |
|
104 |
||
105 |
def test_lookup_badvalue(self): |
|
106 |
branch = self.make_branch('.') |
|
107 |
e = self.assertRaises(errors.UnsetLocationAlias, |
|
108 |
directories.dereference, ':parent') |
|
109 |
self.assertEqual('No parent location assigned.', str(e)) |