256
260
max_size=1*1024*1024*1024)
263
class TestMemoryServer(TestCase):
265
def test_create_server(self):
266
server = memory.MemoryServer()
267
server.start_server()
268
url = server.get_url()
269
self.assertTrue(url in _mod_transport.transport_list_registry)
270
t = _mod_transport.get_transport(url)
273
self.assertFalse(url in _mod_transport.transport_list_registry)
274
self.assertRaises(errors.UnsupportedProtocol,
275
_mod_transport.get_transport, url)
259
278
class TestMemoryTransport(TestCase):
261
280
def test_get_transport(self):
281
memory.MemoryTransport()
264
283
def test_clone(self):
265
transport = MemoryTransport()
266
self.assertTrue(isinstance(transport, MemoryTransport))
284
transport = memory.MemoryTransport()
285
self.assertTrue(isinstance(transport, memory.MemoryTransport))
267
286
self.assertEqual("memory:///", transport.clone("/").base)
269
288
def test_abspath(self):
270
transport = MemoryTransport()
289
transport = memory.MemoryTransport()
271
290
self.assertEqual("memory:///relpath", transport.abspath('relpath'))
273
292
def test_abspath_of_root(self):
274
transport = MemoryTransport()
293
transport = memory.MemoryTransport()
275
294
self.assertEqual("memory:///", transport.base)
276
295
self.assertEqual("memory:///", transport.abspath('/'))
278
297
def test_abspath_of_relpath_starting_at_root(self):
279
transport = MemoryTransport()
298
transport = memory.MemoryTransport()
280
299
self.assertEqual("memory:///foo", transport.abspath('/foo'))
282
301
def test_append_and_get(self):
283
transport = MemoryTransport()
302
transport = memory.MemoryTransport()
284
303
transport.append_bytes('path', 'content')
285
304
self.assertEqual(transport.get('path').read(), 'content')
286
305
transport.append_file('path', StringIO('content'))
287
306
self.assertEqual(transport.get('path').read(), 'contentcontent')
289
308
def test_put_and_get(self):
290
transport = MemoryTransport()
309
transport = memory.MemoryTransport()
291
310
transport.put_file('path', StringIO('content'))
292
311
self.assertEqual(transport.get('path').read(), 'content')
293
312
transport.put_bytes('path', 'content')
294
313
self.assertEqual(transport.get('path').read(), 'content')
296
315
def test_append_without_dir_fails(self):
297
transport = MemoryTransport()
316
transport = memory.MemoryTransport()
298
317
self.assertRaises(NoSuchFile,
299
318
transport.append_bytes, 'dir/path', 'content')
301
320
def test_put_without_dir_fails(self):
302
transport = MemoryTransport()
321
transport = memory.MemoryTransport()
303
322
self.assertRaises(NoSuchFile,
304
323
transport.put_file, 'dir/path', StringIO('content'))
306
325
def test_get_missing(self):
307
transport = MemoryTransport()
326
transport = memory.MemoryTransport()
308
327
self.assertRaises(NoSuchFile, transport.get, 'foo')
310
329
def test_has_missing(self):
311
transport = MemoryTransport()
330
transport = memory.MemoryTransport()
312
331
self.assertEquals(False, transport.has('foo'))
314
333
def test_has_present(self):
315
transport = MemoryTransport()
334
transport = memory.MemoryTransport()
316
335
transport.append_bytes('foo', 'content')
317
336
self.assertEquals(True, transport.has('foo'))
319
338
def test_list_dir(self):
320
transport = MemoryTransport()
339
transport = memory.MemoryTransport()
321
340
transport.put_bytes('foo', 'content')
322
341
transport.mkdir('dir')
323
342
transport.put_bytes('dir/subfoo', 'content')
327
346
self.assertEquals(['subfoo'], sorted(transport.list_dir('dir')))
329
348
def test_mkdir(self):
330
transport = MemoryTransport()
349
transport = memory.MemoryTransport()
331
350
transport.mkdir('dir')
332
351
transport.append_bytes('dir/path', 'content')
333
352
self.assertEqual(transport.get('dir/path').read(), 'content')
335
354
def test_mkdir_missing_parent(self):
336
transport = MemoryTransport()
355
transport = memory.MemoryTransport()
337
356
self.assertRaises(NoSuchFile,
338
357
transport.mkdir, 'dir/dir')
340
359
def test_mkdir_twice(self):
341
transport = MemoryTransport()
360
transport = memory.MemoryTransport()
342
361
transport.mkdir('dir')
343
362
self.assertRaises(FileExists, transport.mkdir, 'dir')
345
364
def test_parameters(self):
346
transport = MemoryTransport()
365
transport = memory.MemoryTransport()
347
366
self.assertEqual(True, transport.listable())
348
367
self.assertEqual(False, transport.is_readonly())
350
369
def test_iter_files_recursive(self):
351
transport = MemoryTransport()
370
transport = memory.MemoryTransport()
352
371
transport.mkdir('dir')
353
372
transport.put_bytes('dir/foo', 'content')
354
373
transport.put_bytes('dir/bar', 'content')
423
442
class ChrootServerTest(TestCase):
425
444
def test_construct(self):
426
backing_transport = MemoryTransport()
445
backing_transport = memory.MemoryTransport()
427
446
server = ChrootServer(backing_transport)
428
447
self.assertEqual(backing_transport, server.backing_transport)
430
449
def test_setUp(self):
431
backing_transport = MemoryTransport()
450
backing_transport = memory.MemoryTransport()
432
451
server = ChrootServer(backing_transport)
452
server.start_server()
435
454
self.assertTrue(server.scheme in _get_protocol_handlers().keys())
439
def test_tearDown(self):
440
backing_transport = MemoryTransport()
458
def test_stop_server(self):
459
backing_transport = memory.MemoryTransport()
441
460
server = ChrootServer(backing_transport)
461
server.start_server()
444
463
self.assertFalse(server.scheme in _get_protocol_handlers().keys())
446
465
def test_get_url(self):
447
backing_transport = MemoryTransport()
466
backing_transport = memory.MemoryTransport()
448
467
server = ChrootServer(backing_transport)
468
server.start_server()
451
470
self.assertEqual('chroot-%d:///' % id(server), server.get_url())
456
475
class PathFilteringDecoratorTransportTest(TestCase):
584
600
self.start_server(server)
585
601
transport = self.get_nfs_transport(server.get_url())
586
602
self.assertIsInstance(
587
transport, bzrlib.transport.fakenfs.FakeNFSTransportDecorator)
603
transport, fakenfs.FakeNFSTransportDecorator)
588
604
self.assertEqual(False, transport.listable())
589
605
self.assertEqual(True, transport.is_readonly())
591
607
def test_fakenfs_server_default(self):
592
608
# a FakeNFSServer() should bring up a local relpath server for itself
593
import bzrlib.transport.fakenfs as fakenfs
594
609
server = fakenfs.FakeNFSServer()
595
610
self.start_server(server)
596
611
# the url should be decorated appropriately