~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 by 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
25
24
from bzrlib.errors import (NoSuchFile, FileExists,
26
25
                           TransportNotPossible,
27
26
                           ConnectionError,
28
27
                           DependencyNotPresent,
29
28
                           UnsupportedProtocol,
30
 
                           PathNotChild,
31
29
                           )
32
30
from bzrlib.tests import TestCase, TestCaseInTempDir
33
31
from bzrlib.transport import (_CoalescedOffset,
39
37
                              Transport,
40
38
                              )
41
39
from bzrlib.transport.memory import MemoryTransport
42
 
from bzrlib.transport.local import (LocalTransport,
43
 
                                    EmulatedWin32LocalTransport)
44
 
 
45
 
 
46
 
# TODO: Should possibly split transport-specific tests into their own files.
 
40
from bzrlib.transport.local import LocalTransport
47
41
 
48
42
 
49
43
class TestTransport(TestCase):
112
106
                         t._combine_paths('/home/sarah', 'project/foo'))
113
107
        self.assertEqual('/etc',
114
108
                         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
109
 
120
110
 
121
111
class TestCoalesceOffsets(TestCase):
196
186
        self.assertEqual("memory:///", transport.base)
197
187
        self.assertEqual("memory:///", transport.abspath('/'))
198
188
 
199
 
    def test_abspath_of_relpath_starting_at_root(self):
 
189
    def test_relpath(self):
200
190
        transport = MemoryTransport()
201
 
        self.assertEqual("memory:///foo", transport.abspath('/foo'))
202
191
 
203
192
    def test_append_and_get(self):
204
193
        transport = MemoryTransport()
237
226
        transport.append_bytes('foo', 'content')
238
227
        self.assertEquals(True, transport.has('foo'))
239
228
 
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
 
 
250
229
    def test_mkdir(self):
251
230
        transport = MemoryTransport()
252
231
        transport.mkdir('dir')
285
264
        self.assertEqual(7, transport.stat('foo').st_size)
286
265
        self.assertEqual(6, transport.stat('bar').st_size)
287
266
 
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
 
 
 
267
        
371
268
class ReadonlyDecoratorTransportTest(TestCase):
372
269
    """Readonly decoration specific tests."""
373
270
 
380
277
        self.assertEqual(True, transport.is_readonly())
381
278
 
382
279
    def test_http_parameters(self):
383
 
        from bzrlib.tests.HttpServer import HttpServer
384
280
        import bzrlib.transport.readonly as readonly
 
281
        from bzrlib.transport.http import HttpServer
385
282
        # connect to . via http which is not listable
386
283
        server = HttpServer()
387
284
        server.setUp()
415
312
    def test_http_parameters(self):
416
313
        # the listable, should_cache and is_readonly parameters
417
314
        # are not changed by the fakenfs decorator
418
 
        from bzrlib.tests.HttpServer import HttpServer
 
315
        from bzrlib.transport.http import HttpServer
419
316
        # connect to . via http which is not listable
420
317
        server = HttpServer()
421
318
        server.setUp()
435
332
        server = fakenfs.FakeNFSServer()
436
333
        server.setUp()
437
334
        try:
438
 
            # the url should be decorated appropriately
439
 
            self.assertStartsWith(server.get_url(), 'fakenfs+')
 
335
            # the server should be a relpath localhost server
 
336
            self.assertEqual(server.get_url(), 'fakenfs+.')
440
337
            # and we should be able to get a transport for it
441
338
            transport = get_transport(server.get_url())
442
339
            # which must be a FakeNFSTransportDecorator instance.
530
427
            # regular connection behaviour by direct construction.
531
428
            t = self.transport_class(base_url)
532
429
        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/')