1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
|
# Copyright (C) 2008-2012 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
import sys
from bzrlib import (
bzrdir,
config,
errors,
osutils,
revisionspec,
tests,
transport,
workingtree,
uncommit,
)
from bzrlib.tests import (
features,
per_branch,
per_transport,
stub_sftp,
)
from bzrlib.transport import (
ftp,
sftp,
)
from bzrlib.plugins.upload import (
cmds,
)
def get_transport_scenarios():
result = []
basis = per_transport.transport_test_permutations()
# Keep only the interesting ones for upload
for name, d in basis:
t_class = d['transport_class']
if t_class in (ftp.FtpTransport, sftp.SFTPTransport):
result.append((name, d))
try:
import bzrlib.plugins.local_test_server
from bzrlib.plugins.local_test_server import test_server
if False:
# XXX: Disable since we can't get chmod working for anonymous
# user
scenario = ('vsftpd',
{'transport_class': test_server.FtpTransport,
'transport_server': test_server.Vsftpd,
})
result.append(scenario)
from test_server import ProftpdFeature
if ProftpdFeature().available():
scenario = ('proftpd',
{'transport_class': test_server.FtpTransport,
'transport_server': test_server.Proftpd,
})
result.append(scenario)
# XXX: add support for pyftpdlib
except ImportError:
pass
return result
def load_tests(standard_tests, module, loader):
"""Multiply tests for tranport implementations."""
result = loader.suiteClass()
# one for each transport implementation
t_tests, remaining_tests = tests.split_suite_by_condition(
standard_tests, tests.condition_isinstance((
TestFullUpload,
TestIncrementalUpload,
TestUploadFromRemoteBranch,
)))
tests.multiply_tests(t_tests, get_transport_scenarios(), result)
# one for each branch format
b_tests, remaining_tests = tests.split_suite_by_condition(
remaining_tests, tests.condition_isinstance((
TestBranchUploadLocations,
)))
tests.multiply_tests(b_tests, per_branch.branch_scenarios(),
result)
# No parametrization for the remaining tests
result.addTests(remaining_tests)
return result
class UploadUtilsMixin(object):
"""Helper class to write upload tests.
This class provides helpers to simplify test writing. The emphasis is on
easy test writing, so each tree modification is committed. This doesn't
preclude writing tests spawning several revisions to upload more complex
changes.
"""
upload_dir = 'upload'
branch_dir = 'branch'
def make_branch_and_working_tree(self):
t = transport.get_transport(self.branch_dir)
t.ensure_base()
branch = bzrdir.BzrDir.create_branch_convenience(
t.base,
format=bzrdir.format_registry.make_bzrdir('default'),
force_new_tree=False)
self.tree = branch.bzrdir.create_workingtree()
self.tree.commit('initial empty tree')
def assertUpFileEqual(self, content, path, base=upload_dir):
self.assertFileEqual(content, osutils.pathjoin(base, path))
def assertUpPathModeEqual(self, path, expected_mode, base=upload_dir):
# FIXME: the tests needing that assertion should depend on the server
# ability to handle chmod so that they don't fail (or be skipped)
# against servers that can't. Note that some bzrlib transports define
# _can_roundtrip_unix_modebits in a incomplete way, this property
# should depend on both the client and the server, not the client only.
# But the client will know or can find if the server support chmod so
# that's the client that will report it anyway.
full_path = osutils.pathjoin(base, path)
st = os.stat(full_path)
mode = st.st_mode & 0777
if expected_mode == mode:
return
raise AssertionError(
'For path %s, mode is %s not %s' %
(full_path, oct(mode), oct(expected_mode)))
def assertUpPathDoesNotExist(self, path, base=upload_dir):
self.assertPathDoesNotExist(osutils.pathjoin(base, path))
def assertUpPathExists(self, path, base=upload_dir):
self.assertPathExists(osutils.pathjoin(base, path))
def set_file_content(self, path, content, base=branch_dir):
f = file(osutils.pathjoin(base, path), 'wb')
try:
f.write(content)
finally:
f.close()
def add_file(self, path, content, base=branch_dir):
self.set_file_content(path, content, base)
self.tree.add(path)
self.tree.commit('add file %s' % path)
def modify_file(self, path, content, base=branch_dir):
self.set_file_content(path, content, base)
self.tree.commit('modify file %s' % path)
def chmod_file(self, path, mode, base=branch_dir):
full_path = osutils.pathjoin(base, path)
os.chmod(full_path, mode)
self.tree.commit('change file %s mode to %s' % (path, oct(mode)))
def delete_any(self, path, base=branch_dir):
self.tree.remove([path], keep_files=False)
self.tree.commit('delete %s' % path)
def add_dir(self, path, base=branch_dir):
os.mkdir(osutils.pathjoin(base, path))
self.tree.add(path)
self.tree.commit('add directory %s' % path)
def rename_any(self, old_path, new_path):
self.tree.rename_one(old_path, new_path)
self.tree.commit('rename %s into %s' % (old_path, new_path))
def transform_dir_into_file(self, path, content, base=branch_dir):
osutils.delete_any(osutils.pathjoin(base, path))
self.set_file_content(path, content, base)
self.tree.commit('change %s from dir to file' % path)
def transform_file_into_dir(self, path, base=branch_dir):
# bzr can't handle that kind change in a single commit without an
# intervening bzr status (see bug #205636).
self.tree.remove([path], keep_files=False)
os.mkdir(osutils.pathjoin(base, path))
self.tree.add(path)
self.tree.commit('change %s from file to dir' % path)
def add_symlink(self, path, target, base=branch_dir):
self.requireFeature(features.SymlinkFeature)
os.symlink(target, osutils.pathjoin(base, path))
self.tree.add(path)
self.tree.commit('add symlink %s -> %s' % (path, target))
def modify_symlink(self, path, target, base=branch_dir):
self.requireFeature(features.SymlinkFeature)
full_path = osutils.pathjoin(base, path)
os.unlink(full_path)
os.symlink(target, full_path)
self.tree.commit('modify symlink %s -> %s' % (path, target))
def _get_cmd_upload(self):
cmd = cmds.cmd_upload()
# We don't want to use run_bzr here because redirected output are a
# pain to debug. But we need to provides a valid outf.
# XXX: Should a bug against bzr be filled about that ?
# Short story: we don't expect any output so we may just use stdout
cmd.outf = sys.stdout
return cmd
def do_full_upload(self, *args, **kwargs):
upload = self._get_cmd_upload()
up_url = self.get_url(self.upload_dir)
if kwargs.get('directory', None) is None:
kwargs['directory'] = self.branch_dir
kwargs['full'] = True
kwargs['quiet'] = True
upload.run(up_url, *args, **kwargs)
def do_incremental_upload(self, *args, **kwargs):
upload = self._get_cmd_upload()
up_url = self.get_url(self.upload_dir)
if kwargs.get('directory', None) is None:
kwargs['directory'] = self.branch_dir
kwargs['quiet'] = True
upload.run(up_url, *args, **kwargs)
class TestUploadMixin(UploadUtilsMixin):
"""Helper class to share tests between full and incremental uploads."""
def _test_create_file(self, file_name):
self.make_branch_and_working_tree()
self.do_full_upload()
self.add_file(file_name, 'foo')
self.do_upload()
self.assertUpFileEqual('foo', file_name)
def test_create_file(self):
self._test_create_file('hello')
def test_unicode_create_file(self):
self.requireFeature(features.UnicodeFilenameFeature)
self._test_create_file(u'hell\u00d8')
def _test_create_file_in_dir(self, dir_name, file_name):
self.make_branch_and_working_tree()
self.do_full_upload()
self.add_dir(dir_name)
fpath = '%s/%s' % (dir_name, file_name)
self.add_file(fpath, 'baz')
self.assertUpPathDoesNotExist(fpath)
self.do_upload()
self.assertUpFileEqual('baz', fpath)
self.assertUpPathModeEqual(dir_name, 0775)
def test_create_file_in_dir(self):
self._test_create_file_in_dir('dir', 'goodbye')
def test_unicode_create_file_in_dir(self):
self.requireFeature(features.UnicodeFilenameFeature)
self._test_create_file_in_dir(u'dir\u00d8', u'goodbye\u00d8')
def test_modify_file(self):
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
self.do_full_upload()
self.modify_file('hello', 'bar')
self.assertUpFileEqual('foo', 'hello')
self.do_upload()
self.assertUpFileEqual('bar', 'hello')
def _test_rename_one_file(self, old_name, new_name):
self.make_branch_and_working_tree()
self.add_file(old_name, 'foo')
self.do_full_upload()
self.rename_any(old_name, new_name)
self.assertUpFileEqual('foo', old_name)
self.do_upload()
self.assertUpFileEqual('foo', new_name)
def test_rename_one_file(self):
self._test_rename_one_file('hello', 'goodbye')
def test_unicode_rename_one_file(self):
self.requireFeature(features.UnicodeFilenameFeature)
self._test_rename_one_file(u'hello\u00d8', u'goodbye\u00d8')
def test_rename_and_change_file(self):
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
self.do_full_upload()
self.rename_any('hello', 'goodbye')
self.modify_file('goodbye', 'bar')
self.assertUpFileEqual('foo', 'hello')
self.do_upload()
self.assertUpFileEqual('bar', 'goodbye')
def test_rename_two_files(self):
self.make_branch_and_working_tree()
self.add_file('a', 'foo')
self.add_file('b', 'qux')
self.do_full_upload()
# We rely on the assumption that bzr will topologically sort the
# renames which will cause a -> b to appear *before* b -> c
self.rename_any('b', 'c')
self.rename_any('a', 'b')
self.assertUpFileEqual('foo', 'a')
self.assertUpFileEqual('qux', 'b')
self.do_upload()
self.assertUpFileEqual('foo', 'b')
self.assertUpFileEqual('qux', 'c')
def test_upload_revision(self):
self.make_branch_and_working_tree() # rev1
self.do_full_upload()
self.add_file('hello', 'foo') # rev2
self.modify_file('hello', 'bar') # rev3
self.assertUpPathDoesNotExist('hello')
revspec = revisionspec.RevisionSpec.from_string('2')
self.do_upload(revision=[revspec])
self.assertUpFileEqual('foo', 'hello')
def test_no_upload_when_changes(self):
self.make_branch_and_working_tree()
self.add_file('a', 'foo')
self.set_file_content('a', 'bar')
self.assertRaises(errors.UncommittedChanges, self.do_upload)
def test_no_upload_when_conflicts(self):
self.make_branch_and_working_tree()
self.add_file('a', 'foo')
self.run_bzr('branch branch other')
self.modify_file('a', 'bar')
other_tree = workingtree.WorkingTree.open('other')
self.set_file_content('a', 'baz', 'other/')
other_tree.commit('modify file a')
self.run_bzr('merge -d branch other', retcode=1)
self.assertRaises(errors.UncommittedChanges, self.do_upload)
def _test_change_file_into_dir(self, file_name):
self.make_branch_and_working_tree()
self.add_file(file_name, 'foo')
self.do_full_upload()
self.transform_file_into_dir(file_name)
fpath = '%s/%s' % (file_name, 'file')
self.add_file(fpath, 'bar')
self.assertUpFileEqual('foo', file_name)
self.do_upload()
self.assertUpFileEqual('bar', fpath)
def test_change_file_into_dir(self):
self._test_change_file_into_dir('hello')
def test_unicode_change_file_into_dir(self):
self.requireFeature(features.UnicodeFilenameFeature)
self._test_change_file_into_dir(u'hello\u00d8')
def test_change_dir_into_file(self):
self.make_branch_and_working_tree()
self.add_dir('hello')
self.add_file('hello/file', 'foo')
self.do_full_upload()
self.delete_any('hello/file')
self.transform_dir_into_file('hello', 'bar')
self.assertUpFileEqual('foo', 'hello/file')
self.do_upload()
self.assertUpFileEqual('bar', 'hello')
def _test_make_file_executable(self, file_name):
self.make_branch_and_working_tree()
self.add_file(file_name, 'foo')
self.chmod_file(file_name, 0664)
self.do_full_upload()
self.chmod_file(file_name, 0755)
self.assertUpPathModeEqual(file_name, 0664)
self.do_upload()
self.assertUpPathModeEqual(file_name, 0775)
def test_make_file_executable(self):
self._test_make_file_executable('hello')
def test_unicode_make_file_executable(self):
self.requireFeature(features.UnicodeFilenameFeature)
self._test_make_file_executable(u'hello\u00d8')
def test_create_symlink(self):
self.make_branch_and_working_tree()
self.do_full_upload()
self.add_symlink('link', 'target')
self.do_upload()
self.assertUpPathDoesNotExist('link')
def test_rename_symlink(self):
self.make_branch_and_working_tree()
old_name, new_name = 'old-link', 'new-link'
self.add_symlink(old_name, 'target')
self.do_full_upload()
self.rename_any(old_name, new_name)
self.do_upload()
self.assertUpPathDoesNotExist(old_name)
self.assertUpPathDoesNotExist(new_name)
def get_upload_auto(self):
# We need a fresh branch to check what has been saved on disk
b = bzrdir.BzrDir.open(self.tree.basedir).open_branch()
return b.get_config_stack().get('upload_auto')
def test_upload_auto(self):
"""Test that upload --auto sets the upload_auto option"""
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
self.assertFalse(self.get_upload_auto())
self.do_full_upload(auto=True)
self.assertUpFileEqual('foo', 'hello')
self.assertTrue(self.get_upload_auto())
# and check that it stays set until it is unset
self.add_file('bye', 'bar')
self.do_full_upload()
self.assertUpFileEqual('bar', 'bye')
self.assertTrue(self.get_upload_auto())
def test_upload_noauto(self):
"""Test that upload --no-auto unsets the upload_auto option"""
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
self.do_full_upload(auto=True)
self.assertUpFileEqual('foo', 'hello')
self.assertTrue(self.get_upload_auto())
self.add_file('bye', 'bar')
self.do_full_upload(auto=False)
self.assertUpFileEqual('bar', 'bye')
self.assertFalse(self.get_upload_auto())
# and check that it stays unset until it is set
self.add_file('again', 'baz')
self.do_full_upload()
self.assertUpFileEqual('baz', 'again')
self.assertFalse(self.get_upload_auto())
def test_upload_from_subdir(self):
self.make_branch_and_working_tree()
self.build_tree(['branch/foo/', 'branch/foo/bar'])
self.tree.add(['foo/', 'foo/bar'])
self.tree.commit("Add directory")
self.do_full_upload(directory='branch/foo')
def test_upload_revid_path_in_dir(self):
self.make_branch_and_working_tree()
self.add_dir('dir')
self.add_file('dir/goodbye', 'baz')
revid_path = 'dir/revid-path'
self.tree.branch.get_config_stack(
).set('upload_revid_location', revid_path)
self.assertUpPathDoesNotExist(revid_path)
self.do_full_upload()
self.add_file('dir/hello', 'foo')
self.do_upload()
self.assertUpPathExists(revid_path)
self.assertUpFileEqual('baz', 'dir/goodbye')
self.assertUpFileEqual('foo', 'dir/hello')
def test_ignore_file(self):
self.make_branch_and_working_tree()
self.do_full_upload()
self.add_file('.bzrignore-upload', 'foo')
self.add_file('foo', 'bar')
self.do_upload()
self.assertUpPathDoesNotExist('foo')
def test_ignore_regexp(self):
self.make_branch_and_working_tree()
self.do_full_upload()
self.add_file('.bzrignore-upload', 'f*')
self.add_file('foo', 'bar')
self.do_upload()
self.assertUpPathDoesNotExist('foo')
def test_ignore_directory(self):
self.make_branch_and_working_tree()
self.do_full_upload()
self.add_file('.bzrignore-upload', 'dir')
self.add_dir('dir')
self.do_upload()
self.assertUpPathDoesNotExist('dir')
def test_ignore_nested_directory(self):
self.make_branch_and_working_tree()
self.do_full_upload()
self.add_file('.bzrignore-upload', 'dir')
self.add_dir('dir')
self.add_dir('dir/foo')
self.add_file('dir/foo/bar', 'bar contents')
self.do_upload()
self.assertUpPathDoesNotExist('dir')
self.assertUpPathDoesNotExist('dir/foo/bar')
def test_ignore_change_file_into_dir(self):
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
self.do_full_upload()
self.add_file('.bzrignore-upload', 'hello')
self.transform_file_into_dir('hello')
self.add_file('hello/file', 'bar')
self.assertUpFileEqual('foo', 'hello')
self.do_upload()
self.assertUpFileEqual('foo', 'hello')
def test_ignore_change_dir_into_file(self):
self.make_branch_and_working_tree()
self.add_dir('hello')
self.add_file('hello/file', 'foo')
self.do_full_upload()
self.add_file('.bzrignore-upload', 'hello')
self.delete_any('hello/file')
self.transform_dir_into_file('hello', 'bar')
self.assertUpFileEqual('foo', 'hello/file')
self.do_upload()
self.assertUpFileEqual('foo', 'hello/file')
def test_ignore_delete_dir_in_subdir(self):
self.make_branch_and_working_tree()
self.add_dir('dir')
self.add_dir('dir/subdir')
self.add_file('dir/subdir/a', 'foo')
self.do_full_upload()
self.add_file('.bzrignore-upload', 'dir/subdir')
self.rename_any('dir/subdir/a', 'dir/a')
self.delete_any('dir/subdir')
self.assertUpFileEqual('foo', 'dir/subdir/a')
self.do_upload()
# The file in the dir is not ignored. This a bit contrived but
# indicates that we may encounter problems when ignored items appear
# and disappear... -- vila 100106
self.assertUpFileEqual('foo', 'dir/a')
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
do_upload = TestUploadMixin.do_full_upload
def test_full_upload_empty_tree(self):
self.make_branch_and_working_tree()
self.do_full_upload()
revid_path = self.tree.branch.get_config_stack(
).get('upload_revid_location')
self.assertUpPathExists(revid_path)
def test_invalid_revspec(self):
self.make_branch_and_working_tree()
rev1 = revisionspec.RevisionSpec.from_string('1')
rev2 = revisionspec.RevisionSpec.from_string('2')
self.assertRaises(errors.BzrCommandError,
self.do_incremental_upload, revision=[rev1, rev2])
def test_create_remote_dir_twice(self):
self.make_branch_and_working_tree()
self.add_dir('dir')
self.do_full_upload()
self.add_file('dir/goodbye', 'baz')
self.assertUpPathDoesNotExist('dir/goodbye')
self.do_full_upload()
self.assertUpFileEqual('baz', 'dir/goodbye')
self.assertUpPathModeEqual('dir', 0775)
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
do_upload = TestUploadMixin.do_incremental_upload
# XXX: full upload doesn't handle deletions....
def test_delete_one_file(self):
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
self.do_full_upload()
self.delete_any('hello')
self.assertUpFileEqual('foo', 'hello')
self.do_upload()
self.assertUpPathDoesNotExist('hello')
def test_delete_dir_and_subdir(self):
self.make_branch_and_working_tree()
self.add_dir('dir')
self.add_dir('dir/subdir')
self.add_file('dir/subdir/a', 'foo')
self.do_full_upload()
self.rename_any('dir/subdir/a', 'a')
self.delete_any('dir/subdir')
self.delete_any('dir')
self.assertUpFileEqual('foo', 'dir/subdir/a')
self.do_upload()
self.assertUpPathDoesNotExist('dir/subdir/a')
self.assertUpPathDoesNotExist('dir/subdir')
self.assertUpPathDoesNotExist('dir')
self.assertUpFileEqual('foo', 'a')
def test_delete_one_file_rename_to_deleted(self):
self.make_branch_and_working_tree()
self.add_file('a', 'foo')
self.add_file('b', 'bar')
self.do_full_upload()
self.delete_any('a')
self.rename_any('b', 'a')
self.assertUpFileEqual('foo', 'a')
self.do_upload()
self.assertUpPathDoesNotExist('b')
self.assertUpFileEqual('bar', 'a')
def test_rename_outside_dir_delete_dir(self):
self.make_branch_and_working_tree()
self.add_dir('dir')
self.add_file('dir/a', 'foo')
self.do_full_upload()
self.rename_any('dir/a', 'a')
self.delete_any('dir')
self.assertUpFileEqual('foo', 'dir/a')
self.do_upload()
self.assertUpPathDoesNotExist('dir/a')
self.assertUpPathDoesNotExist('dir')
self.assertUpFileEqual('foo', 'a')
def test_delete_symlink(self):
self.make_branch_and_working_tree()
self.add_symlink('link', 'target')
self.do_full_upload()
self.delete_any('link')
self.do_upload()
self.assertUpPathDoesNotExist('link')
def test_upload_for_the_first_time_do_a_full_upload(self):
self.make_branch_and_working_tree()
self.add_file('hello', 'bar')
revid_path = self.tree.branch.get_config_stack(
).get('upload_revid_location')
self.assertUpPathDoesNotExist(revid_path)
self.do_upload()
self.assertUpFileEqual('bar', 'hello')
def test_ignore_delete_one_file(self):
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
self.do_full_upload()
self.add_file('.bzrignore-upload', 'hello')
self.delete_any('hello')
self.assertUpFileEqual('foo', 'hello')
self.do_upload()
self.assertUpFileEqual('foo', 'hello')
class TestBranchUploadLocations(per_branch.TestCaseWithBranch):
def test_get_upload_location_unset(self):
conf = self.get_branch().get_config_stack()
self.assertEqual(None, conf.get('upload_location'))
def test_get_push_location_exact(self):
config.ensure_config_dir_exists()
fn = config.locations_config_filename()
b = self.get_branch()
with open(fn, 'wt') as f:
f.write(("[%s]\n" "upload_location=foo\n" % b.base.rstrip("/")))
self.assertEqual("foo", b.get_config_stack().get('upload_location'))
def test_set_push_location(self):
conf = self.get_branch().get_config_stack()
conf.set('upload_location', 'foo')
self.assertEqual('foo', conf.get('upload_location'))
class TestUploadFromRemoteBranch(tests.TestCaseWithTransport, UploadUtilsMixin):
remote_branch_dir = 'remote_branch'
def setUp(self):
super(TestUploadFromRemoteBranch, self).setUp()
self.remote_branch_url = self.make_remote_branch_without_working_tree()
def make_remote_branch_without_working_tree(self):
"""Creates a branch without working tree to upload from.
It's created from the existing self.branch_dir one which still has its
working tree.
"""
self.make_branch_and_working_tree()
self.add_file('hello', 'foo')
remote_branch_url = self.get_url(self.remote_branch_dir)
if self.transport_server is stub_sftp.SFTPHomeDirServer:
# FIXME: Some policy search ends up above the user home directory
# and are seen as attemps to escape test isolation
raise tests.TestNotApplicable('Escaping test isolation')
self.run_bzr(['push', remote_branch_url,
'--directory', self.branch_dir])
return remote_branch_url
def test_no_upload_to_remote_working_tree(self):
cmd = self._get_cmd_upload()
up_url = self.get_url(self.branch_dir)
# Let's try to upload from the just created remote branch into the
# branch (which has a working tree).
self.assertRaises(cmds.CannotUploadToWorkingTree,
cmd.run, up_url, directory=self.remote_branch_url)
def test_upload_without_working_tree(self):
self.do_full_upload(directory=self.remote_branch_url)
self.assertUpFileEqual('foo', 'hello')
class TestUploadDiverged(tests.TestCaseWithTransport, UploadUtilsMixin):
def setUp(self):
super(TestUploadDiverged, self).setUp()
self.diverged_tree = self.make_diverged_tree_and_upload_location()
def make_diverged_tree_and_upload_location(self):
tree_a = self.make_branch_and_tree('tree_a')
tree_a.commit('message 1', rev_id='rev1')
tree_a.commit('message 2', rev_id='rev2a')
tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
uncommit.uncommit(tree_b.branch, tree=tree_b)
tree_b.commit('message 2', rev_id='rev2b')
# upload tree a
self.do_full_upload(directory=tree_a.basedir)
return tree_b
def assertRevidUploaded(self, revid):
t = self.get_transport(self.upload_dir)
uploaded_revid = t.get_bytes('.bzr-upload.revid')
self.assertEqual(revid, uploaded_revid)
def test_cant_upload_diverged(self):
self.assertRaises(cmds.DivergedUploadedTree,
self.do_incremental_upload,
directory=self.diverged_tree.basedir)
self.assertRevidUploaded('rev2a')
def test_upload_diverged_with_overwrite(self):
self.do_incremental_upload(directory=self.diverged_tree.basedir,
overwrite=True)
self.assertRevidUploaded('rev2b')
class TestUploadBadRemoteReivd(tests.TestCaseWithTransport, UploadUtilsMixin):
def test_raises_on_wrong_revid(self):
tree = self.make_branch_and_working_tree()
self.do_full_upload()
# Put a fake revid on the remote branch
t = self.get_transport(self.upload_dir)
t.put_bytes('.bzr-upload.revid', 'fake')
# Make a change
self.add_file('foo', 'bar\n')
self.assertRaises(cmds.DivergedUploadedTree, self.do_full_upload)
|