~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: Robert Collins
  • Date: 2006-04-02 22:42:19 UTC
  • mto: (1634.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1635.
  • Revision ID: robertc@robertcollins.net-20060402224219-d5a818dc987491fe
Refactor the FakeNFS support into a TransportDecorator.
 * Move the existing boilerplate ReadOnly decorator logic in to a base class
   'bzrlib.transport.decorator.TransportDecorator.'
 * Do the same to the ReadOnlyServer to create
   'bzrlib.transport.decorator.DecoratorServer'.
 * Use the new decorator support to create a trivial FakeNFSTransportDecorator
   class in bzrlib.transport.fakenfs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import stat
21
21
from cStringIO import StringIO
22
22
 
 
23
import bzrlib
23
24
from bzrlib.errors import (NoSuchFile, FileExists,
24
25
                           TransportNotPossible,
25
26
                           ConnectionError,
26
27
                           DependencyNotPresent,
27
28
                           )
28
 
from bzrlib.tests import TestCase
 
29
from bzrlib.tests import TestCase, TestCaseInTempDir
29
30
from bzrlib.transport import (_get_protocol_handlers,
30
31
                              _get_transport_modules,
31
32
                              get_transport,
215
216
            server.tearDown()
216
217
 
217
218
 
 
219
class FakeNFSDecoratorTests(TestCaseInTempDir):
 
220
    """NFS decorator specific tests."""
 
221
 
 
222
    def get_nfs_transport(self, url):
 
223
        import bzrlib.transport.fakenfs as fakenfs
 
224
        # connect to url with nfs decoration
 
225
        return fakenfs.FakeNFSTransportDecorator('fakenfs+' + url)
 
226
 
 
227
    def test_local_parameters(self):
 
228
        # the listable, should_cache and is_readonly parameters
 
229
        # are not changed by the fakenfs decorator
 
230
        transport = self.get_nfs_transport('.')
 
231
        self.assertEqual(True, transport.listable())
 
232
        self.assertEqual(False, transport.should_cache())
 
233
        self.assertEqual(False, transport.is_readonly())
 
234
 
 
235
    def test_http_parameters(self):
 
236
        # the listable, should_cache and is_readonly parameters
 
237
        # are not changed by the fakenfs decorator
 
238
        from bzrlib.transport.http import HttpServer
 
239
        # connect to . via http which is not listable
 
240
        server = HttpServer()
 
241
        server.setUp()
 
242
        try:
 
243
            transport = self.get_nfs_transport(server.get_url())
 
244
            self.assertIsInstance(
 
245
                transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
 
246
            self.assertEqual(False, transport.listable())
 
247
            self.assertEqual(True, transport.should_cache())
 
248
            self.assertEqual(True, transport.is_readonly())
 
249
        finally:
 
250
            server.tearDown()
 
251
 
 
252
    def test_fakenfs_server_default(self):
 
253
        # a FakeNFSServer() should bring up a local relpath server for itself
 
254
        import bzrlib.transport.fakenfs as fakenfs
 
255
        server = fakenfs.FakeNFSServer()
 
256
        server.setUp()
 
257
        try:
 
258
            # the server should be a relpath localhost server
 
259
            self.assertEqual(server.get_url(), 'fakenfs+.')
 
260
            # and we should be able to get a transport for it
 
261
            transport = get_transport(server.get_url())
 
262
            # which must be a FakeNFSTransportDecorator instance.
 
263
            self.assertIsInstance(
 
264
                transport, fakenfs.FakeNFSTransportDecorator)
 
265
        finally:
 
266
            server.tearDown()
 
267
 
 
268
    def test_fakenfs_rename_semantics(self):
 
269
        # a FakeNFS transport must mangle the way rename errors occur to
 
270
        # look like NFS problems.
 
271
        transport = self.get_nfs_transport('.')
 
272
        self.build_tree(['from/', 'from/foo', 'to/', 'to/bar'],
 
273
                        transport=transport)
 
274
        self.assertRaises(bzrlib.errors.ResourceBusy,
 
275
                          transport.rename, 'from', 'to')
 
276
 
 
277
 
218
278
class BadTransportHandler(Transport):
219
279
    def __init__(self, base_url):
220
280
        raise DependencyNotPresent('some_lib', 'testing missing dependency')