231
230
self.assertRaises(NoSuchFile, t.get_bytes, 'c')
234
t = self.get_transport()
239
self.applyDeprecated(zero_eleven, t.put, 'a', 'string\ncontents\n')
240
self.check_transport_contents('string\ncontents\n', t, 'a')
242
self.applyDeprecated(zero_eleven,
243
t.put, 'b', StringIO('file-like\ncontents\n'))
244
self.check_transport_contents('file-like\ncontents\n', t, 'b')
246
self.assertRaises(NoSuchFile,
247
self.applyDeprecated,
249
t.put, 'path/doesnt/exist/c', StringIO('contents'))
251
232
def test_put_bytes(self):
252
233
t = self.get_transport()
436
417
# Yes, you can put a file such that it becomes readonly
437
418
t.put_file('mode400', StringIO('test text\n'), mode=0400)
438
419
self.assertTransportMode(t, 'mode400', 0400)
440
# XXX: put_multi is deprecated, so do we really care anymore?
441
self.applyDeprecated(zero_eleven, t.put_multi,
442
[('mmode644', StringIO('text\n'))], mode=0644)
443
self.assertTransportMode(t, 'mmode644', 0644)
445
420
# The default permissions should be based on the current umask
446
421
umask = osutils.get_umask()
447
422
t.put_file('nomode', StringIO('test text\n'), mode=None)
511
486
unicode_file = pyStringIO(u'\u1234')
512
487
self.assertRaises(UnicodeEncodeError, t.put_file, 'foo', unicode_file)
514
def test_put_multi(self):
515
t = self.get_transport()
519
self.assertEqual(2, self.applyDeprecated(zero_eleven,
520
t.put_multi, [('a', StringIO('new\ncontents for\na\n')),
521
('d', StringIO('contents\nfor d\n'))]
523
self.assertEqual(list(t.has_multi(['a', 'b', 'c', 'd'])),
524
[True, False, False, True])
525
self.check_transport_contents('new\ncontents for\na\n', t, 'a')
526
self.check_transport_contents('contents\nfor d\n', t, 'd')
528
self.assertEqual(2, self.applyDeprecated(zero_eleven,
529
t.put_multi, iter([('a', StringIO('diff\ncontents for\na\n')),
530
('d', StringIO('another contents\nfor d\n'))])
532
self.check_transport_contents('diff\ncontents for\na\n', t, 'a')
533
self.check_transport_contents('another contents\nfor d\n', t, 'd')
535
def test_put_permissions(self):
536
t = self.get_transport()
540
if not t._can_roundtrip_unix_modebits():
541
# Can't roundtrip, so no need to run this test
543
self.applyDeprecated(zero_eleven, t.put, 'mode644',
544
StringIO('test text\n'), mode=0644)
545
self.assertTransportMode(t, 'mode644', 0644)
546
self.applyDeprecated(zero_eleven, t.put, 'mode666',
547
StringIO('test text\n'), mode=0666)
548
self.assertTransportMode(t, 'mode666', 0666)
549
self.applyDeprecated(zero_eleven, t.put, 'mode600',
550
StringIO('test text\n'), mode=0600)
551
self.assertTransportMode(t, 'mode600', 0600)
552
# Yes, you can put a file such that it becomes readonly
553
self.applyDeprecated(zero_eleven, t.put, 'mode400',
554
StringIO('test text\n'), mode=0400)
555
self.assertTransportMode(t, 'mode400', 0400)
556
self.applyDeprecated(zero_eleven, t.put_multi,
557
[('mmode644', StringIO('text\n'))], mode=0644)
558
self.assertTransportMode(t, 'mmode644', 0644)
560
# The default permissions should be based on the current umask
561
umask = osutils.get_umask()
562
self.applyDeprecated(zero_eleven, t.put, 'nomode',
563
StringIO('test text\n'), mode=None)
564
self.assertTransportMode(t, 'nomode', 0666 & ~umask)
566
489
def test_mkdir(self):
567
490
t = self.get_transport()
684
607
self.assertTransportMode(temp_transport, f, mode)
686
def test_append(self):
687
t = self.get_transport()
691
t.put_bytes('a', 'diff\ncontents for\na\n')
692
t.put_bytes('b', 'contents\nfor b\n')
694
self.assertEqual(20, self.applyDeprecated(zero_eleven,
695
t.append, 'a', StringIO('add\nsome\nmore\ncontents\n')))
697
self.check_transport_contents(
698
'diff\ncontents for\na\nadd\nsome\nmore\ncontents\n',
701
# And we can create new files, too
702
self.assertEqual(0, self.applyDeprecated(zero_eleven,
703
t.append, 'c', StringIO('some text\nfor a missing file\n')))
704
self.check_transport_contents('some text\nfor a missing file\n',
706
609
def test_append_file(self):
707
610
t = self.get_transport()