~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

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,
37
39
                              Transport,
38
40
                              )
39
41
from bzrlib.transport.memory import MemoryTransport
40
 
from bzrlib.transport.local import LocalTransport
 
42
from bzrlib.transport.local import (LocalTransport,
 
43
                                    EmulatedWin32LocalTransport)
 
44
 
 
45
 
 
46
# TODO: Should possibly split transport-specific tests into their own files.
41
47
 
42
48
 
43
49
class TestTransport(TestCase):
100
106
        finally:
101
107
            _set_protocol_handlers(saved_handlers)
102
108
 
 
109
    def test__combine_paths(self):
 
110
        t = Transport('/')
 
111
        self.assertEqual('/home/sarah/project/foo',
 
112
                         t._combine_paths('/home/sarah', 'project/foo'))
 
113
        self.assertEqual('/etc',
 
114
                         t._combine_paths('/home/sarah', '../../etc'))
 
115
        self.assertEqual('/etc',
 
116
                         t._combine_paths('/home/sarah', '../../../etc'))
 
117
        self.assertEqual('/etc',
 
118
                         t._combine_paths('/home/sarah', '/etc'))
 
119
 
103
120
 
104
121
class TestCoalesceOffsets(TestCase):
105
122
    
179
196
        self.assertEqual("memory:///", transport.base)
180
197
        self.assertEqual("memory:///", transport.abspath('/'))
181
198
 
182
 
    def test_relpath(self):
 
199
    def test_abspath_of_relpath_starting_at_root(self):
183
200
        transport = MemoryTransport()
 
201
        self.assertEqual("memory:///foo", transport.abspath('/foo'))
184
202
 
185
203
    def test_append_and_get(self):
186
204
        transport = MemoryTransport()
219
237
        transport.append_bytes('foo', 'content')
220
238
        self.assertEquals(True, transport.has('foo'))
221
239
 
 
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')
 
246
 
 
247
        self.assertEquals(['dir', 'dirlike', 'foo'], sorted(transport.list_dir('.')))
 
248
        self.assertEquals(['subfoo'], sorted(transport.list_dir('dir')))
 
249
 
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)
259
287
 
260
 
        
 
288
 
 
289
class ChrootDecoratorTransportTest(TestCase):
 
290
    """Chroot decoration specific tests."""
 
291
 
 
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)
 
296
 
 
297
        transport = chroot.ChrootTransportDecorator(
 
298
            'chroot+memory:///path/B', chroot='memory:///path/')
 
299
        self.assertEqual('memory:///path/', transport.chroot_url)
 
300
 
 
301
    def test_append_file(self):
 
302
        transport = get_transport('chroot+memory:///foo/bar')
 
303
        self.assertRaises(PathNotChild, transport.append_file, '/foo', None)
 
304
 
 
305
    def test_append_bytes(self):
 
306
        transport = get_transport('chroot+memory:///foo/bar')
 
307
        self.assertRaises(PathNotChild, transport.append_bytes, '/foo', 'bytes')
 
308
 
 
309
    def test_clone(self):
 
310
        transport = get_transport('chroot+memory:///foo/bar')
 
311
        self.assertRaises(PathNotChild, transport.clone, '/foo')
 
312
 
 
313
    def test_delete(self):
 
314
        transport = get_transport('chroot+memory:///foo/bar')
 
315
        self.assertRaises(PathNotChild, transport.delete, '/foo')
 
316
 
 
317
    def test_delete_tree(self):
 
318
        transport = get_transport('chroot+memory:///foo/bar')
 
319
        self.assertRaises(PathNotChild, transport.delete_tree, '/foo')
 
320
 
 
321
    def test_get(self):
 
322
        transport = get_transport('chroot+memory:///foo/bar')
 
323
        self.assertRaises(PathNotChild, transport.get, '/foo')
 
324
 
 
325
    def test_get_bytes(self):
 
326
        transport = get_transport('chroot+memory:///foo/bar')
 
327
        self.assertRaises(PathNotChild, transport.get_bytes, '/foo')
 
328
 
 
329
    def test_has(self):
 
330
        transport = get_transport('chroot+memory:///foo/bar')
 
331
        self.assertRaises(PathNotChild, transport.has, '/foo')
 
332
 
 
333
    def test_list_dir(self):
 
334
        transport = get_transport('chroot+memory:///foo/bar')
 
335
        self.assertRaises(PathNotChild, transport.list_dir, '/foo')
 
336
 
 
337
    def test_lock_read(self):
 
338
        transport = get_transport('chroot+memory:///foo/bar')
 
339
        self.assertRaises(PathNotChild, transport.lock_read, '/foo')
 
340
 
 
341
    def test_lock_write(self):
 
342
        transport = get_transport('chroot+memory:///foo/bar')
 
343
        self.assertRaises(PathNotChild, transport.lock_write, '/foo')
 
344
 
 
345
    def test_mkdir(self):
 
346
        transport = get_transport('chroot+memory:///foo/bar')
 
347
        self.assertRaises(PathNotChild, transport.mkdir, '/foo')
 
348
 
 
349
    def test_put_bytes(self):
 
350
        transport = get_transport('chroot+memory:///foo/bar')
 
351
        self.assertRaises(PathNotChild, transport.put_bytes, '/foo', 'bytes')
 
352
 
 
353
    def test_put_file(self):
 
354
        transport = get_transport('chroot+memory:///foo/bar')
 
355
        self.assertRaises(PathNotChild, transport.put_file, '/foo', None)
 
356
 
 
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')
 
361
 
 
362
    def test_rmdir(self):
 
363
        transport = get_transport('chroot+memory:///foo/bar')
 
364
        self.assertRaises(PathNotChild, transport.rmdir, '/foo')
 
365
 
 
366
    def test_stat(self):
 
367
        transport = get_transport('chroot+memory:///foo/bar')
 
368
        self.assertRaises(PathNotChild, transport.stat, '/foo')
 
369
 
 
370
 
261
371
class ReadonlyDecoratorTransportTest(TestCase):
262
372
    """Readonly decoration specific tests."""
263
373
 
270
380
        self.assertEqual(True, transport.is_readonly())
271
381
 
272
382
    def test_http_parameters(self):
 
383
        from bzrlib.tests.HttpServer import HttpServer
273
384
        import bzrlib.transport.readonly as readonly
274
 
        from bzrlib.transport.http import HttpServer
275
385
        # connect to . via http which is not listable
276
386
        server = HttpServer()
277
387
        server.setUp()
305
415
    def test_http_parameters(self):
306
416
        # the listable, should_cache and is_readonly parameters
307
417
        # are not changed by the fakenfs decorator
308
 
        from bzrlib.transport.http import HttpServer
 
418
        from bzrlib.tests.HttpServer import HttpServer
309
419
        # connect to . via http which is not listable
310
420
        server = HttpServer()
311
421
        server.setUp()
325
435
        server = fakenfs.FakeNFSServer()
326
436
        server.setUp()
327
437
        try:
328
 
            # the server should be a relpath localhost server
329
 
            self.assertEqual(server.get_url(), 'fakenfs+.')
 
438
            # the url should be decorated appropriately
 
439
            self.assertStartsWith(server.get_url(), 'fakenfs+')
330
440
            # and we should be able to get a transport for it
331
441
            transport = get_transport(server.get_url())
332
442
            # which must be a FakeNFSTransportDecorator instance.
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)
422
532
        return t
 
533
 
 
534
 
 
535
class TestLocalTransports(TestCase):
 
536
 
 
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) + '/')
 
542
 
 
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('.') + '/')
 
548
 
 
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)
 
555
 
 
556
 
 
557
class TestWin32LocalTransport(TestCase):
 
558
 
 
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
 
562
        # not on \\
 
563
        t = EmulatedWin32LocalTransport('file://HOST/path/to/some/dir/')
 
564
        for i in xrange(4):
 
565
            t = t.clone('..')
 
566
        self.assertEquals(t.base, 'file://HOST/')
 
567
        # make sure we reach the root
 
568
        t = t.clone('..')
 
569
        self.assertEquals(t.base, 'file://HOST/')