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