~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_directory_service.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-10 15:38:03 UTC
  • mfrom: (3251.3.6 bzr.ab.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080310153803-uy09bhh0ls8tavcx
Add support for directory services (abentley)

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.directory_service import DirectoryServiceRegistry, directories
 
20
from bzrlib.tests import TestCase
 
21
from bzrlib.transport import get_transport
 
22
 
 
23
 
 
24
class FooService(object):
 
25
    """A directory service that maps the name to a FILE url"""
 
26
 
 
27
    def look_up(self, name, url):
 
28
        return 'file:///foo' + name
 
29
 
 
30
 
 
31
class TestDirectoryLookup(TestCase):
 
32
 
 
33
    def setUp(self):
 
34
        TestCase.setUp(self)
 
35
        self.registry = DirectoryServiceRegistry()
 
36
        self.registry.register('foo:', FooService, 'Map foo URLs to http urls')
 
37
 
 
38
    def test_get_directory_service(self):
 
39
        directory, suffix = self.registry.get_prefix('foo:bar')
 
40
        self.assertIs(FooService, directory)
 
41
        self.assertEqual('bar', suffix)
 
42
 
 
43
    def test_dereference(self):
 
44
        self.assertEqual('file:///foobar',
 
45
                         self.registry.dereference('foo:bar'))
 
46
        self.assertEqual('baz:qux', self.registry.dereference('baz:qux'))
 
47
 
 
48
    def test_get_transport(self):
 
49
        directories.register('foo:', FooService, 'Map foo URLs to http urls')
 
50
        self.addCleanup(lambda: directories.remove('foo:'))
 
51
        self.assertEqual('file:///foobar/', get_transport('foo:bar').base)