~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: Robert Collins
  • Date: 2005-08-25 01:13:32 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050825011331-6d549d5de7edcec1
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by 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
 
 
18
 
import os
19
 
import sys
20
 
import stat
21
 
from cStringIO import StringIO
22
 
 
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,
28
 
                              get_transport,
29
 
                              register_lazy_transport,
30
 
                              _set_protocol_handlers,
31
 
                              urlescape,
32
 
                              )
33
 
 
34
 
 
35
 
class TestTransport(TestCase):
36
 
    """Test the non transport-concrete class functionality."""
37
 
 
38
 
    def test_urlescape(self):
39
 
        self.assertEqual('%25', urlescape('%'))
40
 
 
41
 
    def test__get_set_protocol_handlers(self):
42
 
        handlers = _get_protocol_handlers()
43
 
        self.assertNotEqual({}, handlers)
44
 
        try:
45
 
            _set_protocol_handlers({})
46
 
            self.assertEqual({}, _get_protocol_handlers())
47
 
        finally:
48
 
            _set_protocol_handlers(handlers)
49
 
 
50
 
    def test_get_transport_modules(self):
51
 
        handlers = _get_protocol_handlers()
52
 
        class SampleHandler(object):
53
 
            """I exist, isnt that enough?"""
54
 
        try:
55
 
            my_handlers = {}
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())
61
 
        finally:
62
 
            _set_protocol_handlers(handlers)
63
 
            
64
 
 
65
 
class MemoryTransportTest(TestCase):
66
 
    """Memory transport specific tests."""
67
 
 
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())
74
 
        
75
 
        
76
 
class ReadonlyDecoratorTransportTest(TestCase):
77
 
    """Readonly decoration specific tests."""
78
 
 
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())
86
 
 
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
91
 
        server = HttpServer()
92
 
        server.setUp()
93
 
        try:
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())
100
 
        finally:
101
 
            server.tearDown()