363
363
def test_abspath(self):
364
364
# The abspath is always relative to the chroot_url.
365
365
server = ChrootServer(get_transport('memory:///foo/bar/'))
366
self.start_server(server)
367
367
transport = get_transport(server.get_url())
368
368
self.assertEqual(server.get_url(), transport.abspath('/'))
370
370
subdir_transport = transport.clone('subdir')
371
371
self.assertEqual(server.get_url(), subdir_transport.abspath('/'))
373
374
def test_clone(self):
374
375
server = ChrootServer(get_transport('memory:///foo/bar/'))
375
self.start_server(server)
376
377
transport = get_transport(server.get_url())
377
378
# relpath from root and root path are the same
378
379
relpath_cloned = transport.clone('foo')
379
380
abspath_cloned = transport.clone('/foo')
380
381
self.assertEqual(server, relpath_cloned.server)
381
382
self.assertEqual(server, abspath_cloned.server)
383
385
def test_chroot_url_preserves_chroot(self):
384
386
"""Calling get_transport on a chroot transport's base should produce a
391
393
new_transport = get_transport(parent_url)
393
395
server = ChrootServer(get_transport('memory:///path/subpath'))
394
self.start_server(server)
395
397
transport = get_transport(server.get_url())
396
398
new_transport = get_transport(transport.base)
397
399
self.assertEqual(transport.server, new_transport.server)
398
400
self.assertEqual(transport.base, new_transport.base)
400
403
def test_urljoin_preserves_chroot(self):
401
404
"""Using urlutils.join(url, '..') on a chroot URL should not produce a
407
410
new_transport = get_transport(parent_url)
409
412
server = ChrootServer(get_transport('memory:///path/'))
410
self.start_server(server)
411
414
transport = get_transport(server.get_url())
412
415
self.assertRaises(
413
416
InvalidURLJoin, urlutils.join, transport.base, '..')
416
420
class ChrootServerTest(TestCase):
424
428
backing_transport = MemoryTransport()
425
429
server = ChrootServer(backing_transport)
428
self.assertTrue(server.scheme in _get_protocol_handlers().keys())
431
self.assertTrue(server.scheme in _get_protocol_handlers().keys())
432
433
def test_tearDown(self):
433
434
backing_transport = MemoryTransport()
440
441
backing_transport = MemoryTransport()
441
442
server = ChrootServer(backing_transport)
444
self.assertEqual('chroot-%d:///' % id(server), server.get_url())
444
self.assertEqual('chroot-%d:///' % id(server), server.get_url())
449
448
class ReadonlyDecoratorTransportTest(TestCase):
461
460
import bzrlib.transport.readonly as readonly
462
461
# connect to '.' via http which is not listable
463
462
server = HttpServer()
464
self.start_server(server)
465
transport = get_transport('readonly+' + server.get_url())
466
self.failUnless(isinstance(transport,
467
readonly.ReadonlyTransportDecorator))
468
self.assertEqual(False, transport.listable())
469
self.assertEqual(True, transport.is_readonly())
465
transport = get_transport('readonly+' + server.get_url())
466
self.failUnless(isinstance(transport,
467
readonly.ReadonlyTransportDecorator))
468
self.assertEqual(False, transport.listable())
469
self.assertEqual(True, transport.is_readonly())
472
474
class FakeNFSDecoratorTests(TestCaseInTempDir):
490
492
from bzrlib.tests.http_server import HttpServer
491
493
# connect to '.' via http which is not listable
492
494
server = HttpServer()
493
self.start_server(server)
494
transport = self.get_nfs_transport(server.get_url())
495
self.assertIsInstance(
496
transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
497
self.assertEqual(False, transport.listable())
498
self.assertEqual(True, transport.is_readonly())
497
transport = self.get_nfs_transport(server.get_url())
498
self.assertIsInstance(
499
transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
500
self.assertEqual(False, transport.listable())
501
self.assertEqual(True, transport.is_readonly())
500
505
def test_fakenfs_server_default(self):
501
506
# a FakeNFSServer() should bring up a local relpath server for itself
502
507
import bzrlib.transport.fakenfs as fakenfs
503
508
server = fakenfs.FakeNFSServer()
504
self.start_server(server)
505
# the url should be decorated appropriately
506
self.assertStartsWith(server.get_url(), 'fakenfs+')
507
# and we should be able to get a transport for it
508
transport = get_transport(server.get_url())
509
# which must be a FakeNFSTransportDecorator instance.
510
self.assertIsInstance(transport, fakenfs.FakeNFSTransportDecorator)
511
# the url should be decorated appropriately
512
self.assertStartsWith(server.get_url(), 'fakenfs+')
513
# and we should be able to get a transport for it
514
transport = get_transport(server.get_url())
515
# which must be a FakeNFSTransportDecorator instance.
516
self.assertIsInstance(
517
transport, fakenfs.FakeNFSTransportDecorator)
512
521
def test_fakenfs_rename_semantics(self):
513
522
# a FakeNFS transport must mangle the way rename errors occur to
579
588
super(TestTransportImplementation, self).setUp()
580
589
self._server = self.transport_server()
581
self.start_server(self._server)
591
self.addCleanup(self._server.tearDown)
583
593
def get_transport(self, relpath=None):
584
594
"""Return a connected transport to the local directory.