/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

[merge] bzr.dev 2255, resolve conflicts, update copyrights

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
from cStringIO import StringIO
22
22
 
23
23
import bzrlib
 
24
from bzrlib import urlutils
24
25
from bzrlib.errors import (NoSuchFile, FileExists,
25
26
                           TransportNotPossible,
26
27
                           ConnectionError,
27
28
                           DependencyNotPresent,
28
29
                           UnsupportedProtocol,
 
30
                           PathNotChild,
29
31
                           )
30
32
from bzrlib.tests import TestCase, TestCaseInTempDir
31
33
from bzrlib.transport import (_CoalescedOffset,
40
42
from bzrlib.transport.local import LocalTransport
41
43
 
42
44
 
 
45
# TODO: Should possibly split transport-specific tests into their own files.
 
46
 
 
47
 
43
48
class TestTransport(TestCase):
44
49
    """Test the non transport-concrete class functionality."""
45
50
 
100
105
        finally:
101
106
            _set_protocol_handlers(saved_handlers)
102
107
 
 
108
    def test__combine_paths(self):
 
109
        t = Transport('/')
 
110
        self.assertEqual('/home/sarah/project/foo',
 
111
                         t._combine_paths('/home/sarah', 'project/foo'))
 
112
        self.assertEqual('/etc',
 
113
                         t._combine_paths('/home/sarah', '../../etc'))
 
114
        self.assertEqual('/etc',
 
115
                         t._combine_paths('/home/sarah', '../../../etc'))
 
116
        self.assertEqual('/etc',
 
117
                         t._combine_paths('/home/sarah', '/etc'))
 
118
 
103
119
 
104
120
class TestCoalesceOffsets(TestCase):
105
121
    
179
195
        self.assertEqual("memory:///", transport.base)
180
196
        self.assertEqual("memory:///", transport.abspath('/'))
181
197
 
182
 
    def test_relpath(self):
 
198
    def test_abspath_of_relpath_starting_at_root(self):
183
199
        transport = MemoryTransport()
 
200
        self.assertEqual("memory:///foo", transport.abspath('/foo'))
184
201
 
185
202
    def test_append_and_get(self):
186
203
        transport = MemoryTransport()
219
236
        transport.append_bytes('foo', 'content')
220
237
        self.assertEquals(True, transport.has('foo'))
221
238
 
 
239
    def test_list_dir(self):
 
240
        transport = MemoryTransport()
 
241
        transport.put_bytes('foo', 'content')
 
242
        transport.mkdir('dir')
 
243
        transport.put_bytes('dir/subfoo', 'content')
 
244
        transport.put_bytes('dirlike', 'content')
 
245
 
 
246
        self.assertEquals(['dir', 'dirlike', 'foo'], sorted(transport.list_dir('.')))
 
247
        self.assertEquals(['subfoo'], sorted(transport.list_dir('dir')))
 
248
 
222
249
    def test_mkdir(self):
223
250
        transport = MemoryTransport()
224
251
        transport.mkdir('dir')
257
284
        self.assertEqual(7, transport.stat('foo').st_size)
258
285
        self.assertEqual(6, transport.stat('bar').st_size)
259
286
 
260
 
        
 
287
 
 
288
class ChrootDecoratorTransportTest(TestCase):
 
289
    """Chroot decoration specific tests."""
 
290
 
 
291
    def test_construct(self):
 
292
        from bzrlib.transport import chroot
 
293
        transport = chroot.ChrootTransportDecorator('chroot+memory:///pathA/')
 
294
        self.assertEqual('memory:///pathA/', transport.chroot_url)
 
295
 
 
296
        transport = chroot.ChrootTransportDecorator(
 
297
            'chroot+memory:///path/B', chroot='memory:///path/')
 
298
        self.assertEqual('memory:///path/', transport.chroot_url)
 
299
 
 
300
    def test_append_file(self):
 
301
        transport = get_transport('chroot+memory:///foo/bar')
 
302
        self.assertRaises(PathNotChild, transport.append_file, '/foo', None)
 
303
 
 
304
    def test_append_bytes(self):
 
305
        transport = get_transport('chroot+memory:///foo/bar')
 
306
        self.assertRaises(PathNotChild, transport.append_bytes, '/foo', 'bytes')
 
307
 
 
308
    def test_clone(self):
 
309
        transport = get_transport('chroot+memory:///foo/bar')
 
310
        self.assertRaises(PathNotChild, transport.clone, '/foo')
 
311
 
 
312
    def test_delete(self):
 
313
        transport = get_transport('chroot+memory:///foo/bar')
 
314
        self.assertRaises(PathNotChild, transport.delete, '/foo')
 
315
 
 
316
    def test_delete_tree(self):
 
317
        transport = get_transport('chroot+memory:///foo/bar')
 
318
        self.assertRaises(PathNotChild, transport.delete_tree, '/foo')
 
319
 
 
320
    def test_get(self):
 
321
        transport = get_transport('chroot+memory:///foo/bar')
 
322
        self.assertRaises(PathNotChild, transport.get, '/foo')
 
323
 
 
324
    def test_get_bytes(self):
 
325
        transport = get_transport('chroot+memory:///foo/bar')
 
326
        self.assertRaises(PathNotChild, transport.get_bytes, '/foo')
 
327
 
 
328
    def test_has(self):
 
329
        transport = get_transport('chroot+memory:///foo/bar')
 
330
        self.assertRaises(PathNotChild, transport.has, '/foo')
 
331
 
 
332
    def test_list_dir(self):
 
333
        transport = get_transport('chroot+memory:///foo/bar')
 
334
        self.assertRaises(PathNotChild, transport.list_dir, '/foo')
 
335
 
 
336
    def test_lock_read(self):
 
337
        transport = get_transport('chroot+memory:///foo/bar')
 
338
        self.assertRaises(PathNotChild, transport.lock_read, '/foo')
 
339
 
 
340
    def test_lock_write(self):
 
341
        transport = get_transport('chroot+memory:///foo/bar')
 
342
        self.assertRaises(PathNotChild, transport.lock_write, '/foo')
 
343
 
 
344
    def test_mkdir(self):
 
345
        transport = get_transport('chroot+memory:///foo/bar')
 
346
        self.assertRaises(PathNotChild, transport.mkdir, '/foo')
 
347
 
 
348
    def test_put_bytes(self):
 
349
        transport = get_transport('chroot+memory:///foo/bar')
 
350
        self.assertRaises(PathNotChild, transport.put_bytes, '/foo', 'bytes')
 
351
 
 
352
    def test_put_file(self):
 
353
        transport = get_transport('chroot+memory:///foo/bar')
 
354
        self.assertRaises(PathNotChild, transport.put_file, '/foo', None)
 
355
 
 
356
    def test_rename(self):
 
357
        transport = get_transport('chroot+memory:///foo/bar')
 
358
        self.assertRaises(PathNotChild, transport.rename, '/aaa', 'bbb')
 
359
        self.assertRaises(PathNotChild, transport.rename, 'ccc', '/d')
 
360
 
 
361
    def test_rmdir(self):
 
362
        transport = get_transport('chroot+memory:///foo/bar')
 
363
        self.assertRaises(PathNotChild, transport.rmdir, '/foo')
 
364
 
 
365
    def test_stat(self):
 
366
        transport = get_transport('chroot+memory:///foo/bar')
 
367
        self.assertRaises(PathNotChild, transport.stat, '/foo')
 
368
 
 
369
 
261
370
class ReadonlyDecoratorTransportTest(TestCase):
262
371
    """Readonly decoration specific tests."""
263
372
 
270
379
        self.assertEqual(True, transport.is_readonly())
271
380
 
272
381
    def test_http_parameters(self):
 
382
        from bzrlib.tests.HttpServer import HttpServer
273
383
        import bzrlib.transport.readonly as readonly
274
 
        from bzrlib.transport.http import HttpServer
275
384
        # connect to . via http which is not listable
276
385
        server = HttpServer()
277
386
        server.setUp()
305
414
    def test_http_parameters(self):
306
415
        # the listable, should_cache and is_readonly parameters
307
416
        # are not changed by the fakenfs decorator
308
 
        from bzrlib.transport.http import HttpServer
 
417
        from bzrlib.tests.HttpServer import HttpServer
309
418
        # connect to . via http which is not listable
310
419
        server = HttpServer()
311
420
        server.setUp()
325
434
        server = fakenfs.FakeNFSServer()
326
435
        server.setUp()
327
436
        try:
328
 
            # the server should be a relpath localhost server
329
 
            self.assertEqual(server.get_url(), 'fakenfs+.')
 
437
            # the url should be decorated appropriately
 
438
            self.assertStartsWith(server.get_url(), 'fakenfs+')
330
439
            # and we should be able to get a transport for it
331
440
            transport = get_transport(server.get_url())
332
441
            # which must be a FakeNFSTransportDecorator instance.
420
529
            # regular connection behaviour by direct construction.
421
530
            t = self.transport_class(base_url)
422
531
        return t
 
532
 
 
533
 
 
534
class TestLocalTransports(TestCase):
 
535
 
 
536
    def test_get_transport_from_abspath(self):
 
537
        here = os.path.abspath('.')
 
538
        t = get_transport(here)
 
539
        self.assertIsInstance(t, LocalTransport)
 
540
        self.assertEquals(t.base, urlutils.local_path_to_url(here) + '/')
 
541
 
 
542
    def test_get_transport_from_relpath(self):
 
543
        here = os.path.abspath('.')
 
544
        t = get_transport('.')
 
545
        self.assertIsInstance(t, LocalTransport)
 
546
        self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
 
547
 
 
548
    def test_get_transport_from_local_url(self):
 
549
        here = os.path.abspath('.')
 
550
        here_url = urlutils.local_path_to_url(here) + '/'
 
551
        t = get_transport(here_url)
 
552
        self.assertIsInstance(t, LocalTransport)
 
553
        self.assertEquals(t.base, here_url)