1
# Copyright (C) 2004, 2005 by Canonical Ltd
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.
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.
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
21
from cStringIO import StringIO
23
from bzrlib.errors import (NoSuchFile, FileExists,
24
TransportNotPossible, ConnectionError)
25
from bzrlib.tests import TestCase
26
from bzrlib.transport import (_get_protocol_handlers,
27
_get_transport_modules,
29
register_lazy_transport,
30
_set_protocol_handlers,
35
class TestTransport(TestCase):
36
"""Test the non transport-concrete class functionality."""
38
def test_urlescape(self):
39
self.assertEqual('%25', urlescape('%'))
41
def test__get_set_protocol_handlers(self):
42
handlers = _get_protocol_handlers()
43
self.assertNotEqual({}, handlers)
45
_set_protocol_handlers({})
46
self.assertEqual({}, _get_protocol_handlers())
48
_set_protocol_handlers(handlers)
50
def test_get_transport_modules(self):
51
handlers = _get_protocol_handlers()
52
class SampleHandler(object):
53
"""I exist, isnt that enough?"""
56
_set_protocol_handlers(my_handlers)
57
register_lazy_transport('foo', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
58
register_lazy_transport('bar', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
59
self.assertEqual([SampleHandler.__module__],
60
_get_transport_modules())
62
_set_protocol_handlers(handlers)
65
class MemoryTransportTest(TestCase):
66
"""Memory transport specific tests."""
68
def test_parameters(self):
69
import bzrlib.transport.memory as memory
70
transport = memory.MemoryTransport()
71
self.assertEqual(True, transport.listable())
72
self.assertEqual(False, transport.should_cache())
73
self.assertEqual(False, transport.is_readonly())
76
class ReadonlyDecoratorTransportTest(TestCase):
77
"""Readonly decoration specific tests."""
79
def test_local_parameters(self):
80
import bzrlib.transport.readonly as readonly
81
# connect to . in readonly mode
82
transport = readonly.ReadonlyTransportDecorator('readonly+.')
83
self.assertEqual(True, transport.listable())
84
self.assertEqual(False, transport.should_cache())
85
self.assertEqual(True, transport.is_readonly())
87
def test_http_parameters(self):
88
import bzrlib.transport.readonly as readonly
89
from bzrlib.transport.http import HttpServer
90
# connect to . via http which is not listable
94
transport = get_transport('readonly+' + server.get_url())
95
self.failUnless(isinstance(transport,
96
readonly.ReadonlyTransportDecorator))
97
self.assertEqual(False, transport.listable())
98
self.assertEqual(True, transport.should_cache())
99
self.assertEqual(True, transport.is_readonly())