219
237
transport.append_bytes('foo', 'content')
220
238
self.assertEquals(True, transport.has('foo'))
240
def test_list_dir(self):
241
transport = MemoryTransport()
242
transport.put_bytes('foo', 'content')
243
transport.mkdir('dir')
244
transport.put_bytes('dir/subfoo', 'content')
245
transport.put_bytes('dirlike', 'content')
247
self.assertEquals(['dir', 'dirlike', 'foo'], sorted(transport.list_dir('.')))
248
self.assertEquals(['subfoo'], sorted(transport.list_dir('dir')))
222
250
def test_mkdir(self):
223
251
transport = MemoryTransport()
224
252
transport.mkdir('dir')
257
285
self.assertEqual(7, transport.stat('foo').st_size)
258
286
self.assertEqual(6, transport.stat('bar').st_size)
289
class ChrootDecoratorTransportTest(TestCase):
290
"""Chroot decoration specific tests."""
292
def test_construct(self):
293
from bzrlib.transport import chroot
294
transport = chroot.ChrootTransportDecorator('chroot+memory:///pathA/')
295
self.assertEqual('memory:///pathA/', transport.chroot_url)
297
transport = chroot.ChrootTransportDecorator(
298
'chroot+memory:///path/B', chroot='memory:///path/')
299
self.assertEqual('memory:///path/', transport.chroot_url)
301
def test_append_file(self):
302
transport = get_transport('chroot+memory:///foo/bar')
303
self.assertRaises(PathNotChild, transport.append_file, '/foo', None)
305
def test_append_bytes(self):
306
transport = get_transport('chroot+memory:///foo/bar')
307
self.assertRaises(PathNotChild, transport.append_bytes, '/foo', 'bytes')
309
def test_clone(self):
310
transport = get_transport('chroot+memory:///foo/bar')
311
self.assertRaises(PathNotChild, transport.clone, '/foo')
313
def test_delete(self):
314
transport = get_transport('chroot+memory:///foo/bar')
315
self.assertRaises(PathNotChild, transport.delete, '/foo')
317
def test_delete_tree(self):
318
transport = get_transport('chroot+memory:///foo/bar')
319
self.assertRaises(PathNotChild, transport.delete_tree, '/foo')
322
transport = get_transport('chroot+memory:///foo/bar')
323
self.assertRaises(PathNotChild, transport.get, '/foo')
325
def test_get_bytes(self):
326
transport = get_transport('chroot+memory:///foo/bar')
327
self.assertRaises(PathNotChild, transport.get_bytes, '/foo')
330
transport = get_transport('chroot+memory:///foo/bar')
331
self.assertRaises(PathNotChild, transport.has, '/foo')
333
def test_list_dir(self):
334
transport = get_transport('chroot+memory:///foo/bar')
335
self.assertRaises(PathNotChild, transport.list_dir, '/foo')
337
def test_lock_read(self):
338
transport = get_transport('chroot+memory:///foo/bar')
339
self.assertRaises(PathNotChild, transport.lock_read, '/foo')
341
def test_lock_write(self):
342
transport = get_transport('chroot+memory:///foo/bar')
343
self.assertRaises(PathNotChild, transport.lock_write, '/foo')
345
def test_mkdir(self):
346
transport = get_transport('chroot+memory:///foo/bar')
347
self.assertRaises(PathNotChild, transport.mkdir, '/foo')
349
def test_put_bytes(self):
350
transport = get_transport('chroot+memory:///foo/bar')
351
self.assertRaises(PathNotChild, transport.put_bytes, '/foo', 'bytes')
353
def test_put_file(self):
354
transport = get_transport('chroot+memory:///foo/bar')
355
self.assertRaises(PathNotChild, transport.put_file, '/foo', None)
357
def test_rename(self):
358
transport = get_transport('chroot+memory:///foo/bar')
359
self.assertRaises(PathNotChild, transport.rename, '/aaa', 'bbb')
360
self.assertRaises(PathNotChild, transport.rename, 'ccc', '/d')
362
def test_rmdir(self):
363
transport = get_transport('chroot+memory:///foo/bar')
364
self.assertRaises(PathNotChild, transport.rmdir, '/foo')
367
transport = get_transport('chroot+memory:///foo/bar')
368
self.assertRaises(PathNotChild, transport.stat, '/foo')
261
371
class ReadonlyDecoratorTransportTest(TestCase):
262
372
"""Readonly decoration specific tests."""
415
525
base_url = self._server.get_url()
416
526
# try getting the transport via the regular interface:
417
527
t = get_transport(base_url)
418
if not isinstance(t, self.transport_class):
528
if not isinstance(t, self.transport_class):
419
529
# we did not get the correct transport class type. Override the
420
530
# regular connection behaviour by direct construction.
421
531
t = self.transport_class(base_url)
535
class TestLocalTransports(TestCase):
537
def test_get_transport_from_abspath(self):
538
here = os.path.abspath('.')
539
t = get_transport(here)
540
self.assertIsInstance(t, LocalTransport)
541
self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
543
def test_get_transport_from_relpath(self):
544
here = os.path.abspath('.')
545
t = get_transport('.')
546
self.assertIsInstance(t, LocalTransport)
547
self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
549
def test_get_transport_from_local_url(self):
550
here = os.path.abspath('.')
551
here_url = urlutils.local_path_to_url(here) + '/'
552
t = get_transport(here_url)
553
self.assertIsInstance(t, LocalTransport)
554
self.assertEquals(t.base, here_url)
557
class TestWin32LocalTransport(TestCase):
559
def test_unc_clone_to_root(self):
560
# Win32 UNC path like \\HOST\path
561
# clone to root should stop at least at \\HOST part
563
t = EmulatedWin32LocalTransport('file://HOST/path/to/some/dir/')
566
self.assertEquals(t.base, 'file://HOST/')
567
# make sure we reach the root
569
self.assertEquals(t.base, 'file://HOST/')