1
# Copyright (C) 2008-2012 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
from ....tests import (
38
from ....transport import (
47
def get_transport_scenarios():
49
basis = per_transport.transport_test_permutations()
50
# Keep only the interesting ones for upload
52
t_class = d['transport_class']
53
if t_class in (ftp.FtpTransport, sftp.SFTPTransport):
54
result.append((name, d))
56
import breezy.plugins.local_test_server
57
from breezy.plugins.local_test_server import test_server
59
# XXX: Disable since we can't get chmod working for anonymous
62
{'transport_class': test_server.FtpTransport,
63
'transport_server': test_server.Vsftpd,
65
result.append(scenario)
66
from test_server import ProftpdFeature
67
if ProftpdFeature().available():
68
scenario = ('proftpd',
69
{'transport_class': test_server.FtpTransport,
70
'transport_server': test_server.Proftpd,
72
result.append(scenario)
73
# XXX: add support for pyftpdlib
79
def load_tests(loader, standard_tests, pattern):
80
"""Multiply tests for tranport implementations."""
81
result = loader.suiteClass()
83
# one for each transport implementation
84
t_tests, remaining_tests = tests.split_suite_by_condition(
85
standard_tests, tests.condition_isinstance((
87
TestIncrementalUpload,
88
TestUploadFromRemoteBranch,
90
tests.multiply_tests(t_tests, get_transport_scenarios(), result)
92
# one for each branch format
93
b_tests, remaining_tests = tests.split_suite_by_condition(
94
remaining_tests, tests.condition_isinstance((
95
TestBranchUploadLocations,
97
tests.multiply_tests(b_tests, per_branch.branch_scenarios(),
100
# No parametrization for the remaining tests
101
result.addTests(remaining_tests)
106
class UploadUtilsMixin(object):
107
"""Helper class to write upload tests.
109
This class provides helpers to simplify test writing. The emphasis is on
110
easy test writing, so each tree modification is committed. This doesn't
111
preclude writing tests spawning several revisions to upload more complex
115
upload_dir = 'upload'
116
branch_dir = 'branch'
118
def make_branch_and_working_tree(self):
119
t = transport.get_transport(self.branch_dir)
121
branch = bzrdir.BzrDir.create_branch_convenience(
123
format=bzrdir.format_registry.make_bzrdir('default'),
124
force_new_tree=False)
125
self.tree = branch.bzrdir.create_workingtree()
126
self.tree.commit('initial empty tree')
128
def assertUpFileEqual(self, content, path, base=upload_dir):
129
self.assertFileEqual(content, osutils.pathjoin(base, path))
131
def assertUpPathModeEqual(self, path, expected_mode, base=upload_dir):
132
# FIXME: the tests needing that assertion should depend on the server
133
# ability to handle chmod so that they don't fail (or be skipped)
134
# against servers that can't. Note that some breezy transports define
135
# _can_roundtrip_unix_modebits in a incomplete way, this property
136
# should depend on both the client and the server, not the client only.
137
# But the client will know or can find if the server support chmod so
138
# that's the client that will report it anyway.
139
full_path = osutils.pathjoin(base, path)
140
st = os.stat(full_path)
141
mode = st.st_mode & 0777
142
if expected_mode == mode:
144
raise AssertionError(
145
'For path %s, mode is %s not %s' %
146
(full_path, oct(mode), oct(expected_mode)))
148
def assertUpPathDoesNotExist(self, path, base=upload_dir):
149
self.assertPathDoesNotExist(osutils.pathjoin(base, path))
151
def assertUpPathExists(self, path, base=upload_dir):
152
self.assertPathExists(osutils.pathjoin(base, path))
154
def set_file_content(self, path, content, base=branch_dir):
155
f = file(osutils.pathjoin(base, path), 'wb')
161
def add_file(self, path, content, base=branch_dir):
162
self.set_file_content(path, content, base)
164
self.tree.commit('add file %s' % path)
166
def modify_file(self, path, content, base=branch_dir):
167
self.set_file_content(path, content, base)
168
self.tree.commit('modify file %s' % path)
170
def chmod_file(self, path, mode, base=branch_dir):
171
full_path = osutils.pathjoin(base, path)
172
os.chmod(full_path, mode)
173
self.tree.commit('change file %s mode to %s' % (path, oct(mode)))
175
def delete_any(self, path, base=branch_dir):
176
self.tree.remove([path], keep_files=False)
177
self.tree.commit('delete %s' % path)
179
def add_dir(self, path, base=branch_dir):
180
os.mkdir(osutils.pathjoin(base, path))
182
self.tree.commit('add directory %s' % path)
184
def rename_any(self, old_path, new_path):
185
self.tree.rename_one(old_path, new_path)
186
self.tree.commit('rename %s into %s' % (old_path, new_path))
188
def transform_dir_into_file(self, path, content, base=branch_dir):
189
osutils.delete_any(osutils.pathjoin(base, path))
190
self.set_file_content(path, content, base)
191
self.tree.commit('change %s from dir to file' % path)
193
def transform_file_into_dir(self, path, base=branch_dir):
194
# bzr can't handle that kind change in a single commit without an
195
# intervening bzr status (see bug #205636).
196
self.tree.remove([path], keep_files=False)
197
os.mkdir(osutils.pathjoin(base, path))
199
self.tree.commit('change %s from file to dir' % path)
201
def add_symlink(self, path, target, base=branch_dir):
202
self.requireFeature(features.SymlinkFeature)
203
os.symlink(target, osutils.pathjoin(base, path))
205
self.tree.commit('add symlink %s -> %s' % (path, target))
207
def modify_symlink(self, path, target, base=branch_dir):
208
self.requireFeature(features.SymlinkFeature)
209
full_path = osutils.pathjoin(base, path)
211
os.symlink(target, full_path)
212
self.tree.commit('modify symlink %s -> %s' % (path, target))
214
def _get_cmd_upload(self):
215
cmd = cmds.cmd_upload()
216
# We don't want to use run_bzr here because redirected output are a
217
# pain to debug. But we need to provides a valid outf.
218
# XXX: Should a bug against bzr be filled about that ?
220
# Short story: we don't expect any output so we may just use stdout
221
cmd.outf = sys.stdout
224
def do_full_upload(self, *args, **kwargs):
225
upload = self._get_cmd_upload()
226
up_url = self.get_url(self.upload_dir)
227
if kwargs.get('directory', None) is None:
228
kwargs['directory'] = self.branch_dir
229
kwargs['full'] = True
230
kwargs['quiet'] = True
231
upload.run(up_url, *args, **kwargs)
233
def do_incremental_upload(self, *args, **kwargs):
234
upload = self._get_cmd_upload()
235
up_url = self.get_url(self.upload_dir)
236
if kwargs.get('directory', None) is None:
237
kwargs['directory'] = self.branch_dir
238
kwargs['quiet'] = True
239
upload.run(up_url, *args, **kwargs)
242
class TestUploadMixin(UploadUtilsMixin):
243
"""Helper class to share tests between full and incremental uploads."""
245
def _test_create_file(self, file_name):
246
self.make_branch_and_working_tree()
247
self.do_full_upload()
248
self.add_file(file_name, 'foo')
252
self.assertUpFileEqual('foo', file_name)
254
def test_create_file(self):
255
self._test_create_file('hello')
257
def test_unicode_create_file(self):
258
self.requireFeature(features.UnicodeFilenameFeature)
259
self._test_create_file(u'hell\u00d8')
261
def _test_create_file_in_dir(self, dir_name, file_name):
262
self.make_branch_and_working_tree()
263
self.do_full_upload()
264
self.add_dir(dir_name)
265
fpath = '%s/%s' % (dir_name, file_name)
266
self.add_file(fpath, 'baz')
268
self.assertUpPathDoesNotExist(fpath)
272
self.assertUpFileEqual('baz', fpath)
273
self.assertUpPathModeEqual(dir_name, 0775)
275
def test_create_file_in_dir(self):
276
self._test_create_file_in_dir('dir', 'goodbye')
278
def test_unicode_create_file_in_dir(self):
279
self.requireFeature(features.UnicodeFilenameFeature)
280
self._test_create_file_in_dir(u'dir\u00d8', u'goodbye\u00d8')
282
def test_modify_file(self):
283
self.make_branch_and_working_tree()
284
self.add_file('hello', 'foo')
285
self.do_full_upload()
286
self.modify_file('hello', 'bar')
288
self.assertUpFileEqual('foo', 'hello')
292
self.assertUpFileEqual('bar', 'hello')
294
def _test_rename_one_file(self, old_name, new_name):
295
self.make_branch_and_working_tree()
296
self.add_file(old_name, 'foo')
297
self.do_full_upload()
298
self.rename_any(old_name, new_name)
300
self.assertUpFileEqual('foo', old_name)
304
self.assertUpFileEqual('foo', new_name)
306
def test_rename_one_file(self):
307
self._test_rename_one_file('hello', 'goodbye')
309
def test_unicode_rename_one_file(self):
310
self.requireFeature(features.UnicodeFilenameFeature)
311
self._test_rename_one_file(u'hello\u00d8', u'goodbye\u00d8')
313
def test_rename_and_change_file(self):
314
self.make_branch_and_working_tree()
315
self.add_file('hello', 'foo')
316
self.do_full_upload()
317
self.rename_any('hello', 'goodbye')
318
self.modify_file('goodbye', 'bar')
320
self.assertUpFileEqual('foo', 'hello')
324
self.assertUpFileEqual('bar', 'goodbye')
326
def test_rename_two_files(self):
327
self.make_branch_and_working_tree()
328
self.add_file('a', 'foo')
329
self.add_file('b', 'qux')
330
self.do_full_upload()
331
# We rely on the assumption that bzr will topologically sort the
332
# renames which will cause a -> b to appear *before* b -> c
333
self.rename_any('b', 'c')
334
self.rename_any('a', 'b')
336
self.assertUpFileEqual('foo', 'a')
337
self.assertUpFileEqual('qux', 'b')
341
self.assertUpFileEqual('foo', 'b')
342
self.assertUpFileEqual('qux', 'c')
344
def test_upload_revision(self):
345
self.make_branch_and_working_tree() # rev1
346
self.do_full_upload()
347
self.add_file('hello', 'foo') # rev2
348
self.modify_file('hello', 'bar') # rev3
350
self.assertUpPathDoesNotExist('hello')
352
revspec = revisionspec.RevisionSpec.from_string('2')
353
self.do_upload(revision=[revspec])
355
self.assertUpFileEqual('foo', 'hello')
357
def test_no_upload_when_changes(self):
358
self.make_branch_and_working_tree()
359
self.add_file('a', 'foo')
360
self.set_file_content('a', 'bar')
362
self.assertRaises(errors.UncommittedChanges, self.do_upload)
364
def test_no_upload_when_conflicts(self):
365
self.make_branch_and_working_tree()
366
self.add_file('a', 'foo')
367
self.run_bzr('branch branch other')
368
self.modify_file('a', 'bar')
369
other_tree = workingtree.WorkingTree.open('other')
370
self.set_file_content('a', 'baz', 'other/')
371
other_tree.commit('modify file a')
373
self.run_bzr('merge -d branch other', retcode=1)
375
self.assertRaises(errors.UncommittedChanges, self.do_upload)
377
def _test_change_file_into_dir(self, file_name):
378
self.make_branch_and_working_tree()
379
self.add_file(file_name, 'foo')
380
self.do_full_upload()
381
self.transform_file_into_dir(file_name)
382
fpath = '%s/%s' % (file_name, 'file')
383
self.add_file(fpath, 'bar')
385
self.assertUpFileEqual('foo', file_name)
389
self.assertUpFileEqual('bar', fpath)
391
def test_change_file_into_dir(self):
392
self._test_change_file_into_dir('hello')
394
def test_unicode_change_file_into_dir(self):
395
self.requireFeature(features.UnicodeFilenameFeature)
396
self._test_change_file_into_dir(u'hello\u00d8')
398
def test_change_dir_into_file(self):
399
self.make_branch_and_working_tree()
400
self.add_dir('hello')
401
self.add_file('hello/file', 'foo')
402
self.do_full_upload()
403
self.delete_any('hello/file')
404
self.transform_dir_into_file('hello', 'bar')
406
self.assertUpFileEqual('foo', 'hello/file')
410
self.assertUpFileEqual('bar', 'hello')
412
def _test_make_file_executable(self, file_name):
413
self.make_branch_and_working_tree()
414
self.add_file(file_name, 'foo')
415
self.chmod_file(file_name, 0664)
416
self.do_full_upload()
417
self.chmod_file(file_name, 0755)
419
self.assertUpPathModeEqual(file_name, 0664)
423
self.assertUpPathModeEqual(file_name, 0775)
425
def test_make_file_executable(self):
426
self._test_make_file_executable('hello')
428
def test_unicode_make_file_executable(self):
429
self.requireFeature(features.UnicodeFilenameFeature)
430
self._test_make_file_executable(u'hello\u00d8')
432
def test_create_symlink(self):
433
self.make_branch_and_working_tree()
434
self.do_full_upload()
435
self.add_symlink('link', 'target')
439
self.assertUpPathDoesNotExist('link')
441
def test_rename_symlink(self):
442
self.make_branch_and_working_tree()
443
old_name, new_name = 'old-link', 'new-link'
444
self.add_symlink(old_name, 'target')
445
self.do_full_upload()
446
self.rename_any(old_name, new_name)
450
self.assertUpPathDoesNotExist(old_name)
451
self.assertUpPathDoesNotExist(new_name)
453
def get_upload_auto(self):
454
# We need a fresh branch to check what has been saved on disk
455
b = bzrdir.BzrDir.open(self.tree.basedir).open_branch()
456
return b.get_config_stack().get('upload_auto')
458
def test_upload_auto(self):
459
"""Test that upload --auto sets the upload_auto option"""
460
self.make_branch_and_working_tree()
462
self.add_file('hello', 'foo')
463
self.assertFalse(self.get_upload_auto())
464
self.do_full_upload(auto=True)
465
self.assertUpFileEqual('foo', 'hello')
466
self.assertTrue(self.get_upload_auto())
468
# and check that it stays set until it is unset
469
self.add_file('bye', 'bar')
470
self.do_full_upload()
471
self.assertUpFileEqual('bar', 'bye')
472
self.assertTrue(self.get_upload_auto())
474
def test_upload_noauto(self):
475
"""Test that upload --no-auto unsets the upload_auto option"""
476
self.make_branch_and_working_tree()
478
self.add_file('hello', 'foo')
479
self.do_full_upload(auto=True)
480
self.assertUpFileEqual('foo', 'hello')
481
self.assertTrue(self.get_upload_auto())
483
self.add_file('bye', 'bar')
484
self.do_full_upload(auto=False)
485
self.assertUpFileEqual('bar', 'bye')
486
self.assertFalse(self.get_upload_auto())
488
# and check that it stays unset until it is set
489
self.add_file('again', 'baz')
490
self.do_full_upload()
491
self.assertUpFileEqual('baz', 'again')
492
self.assertFalse(self.get_upload_auto())
494
def test_upload_from_subdir(self):
495
self.make_branch_and_working_tree()
496
self.build_tree(['branch/foo/', 'branch/foo/bar'])
497
self.tree.add(['foo/', 'foo/bar'])
498
self.tree.commit("Add directory")
499
self.do_full_upload(directory='branch/foo')
501
def test_upload_revid_path_in_dir(self):
502
self.make_branch_and_working_tree()
504
self.add_file('dir/goodbye', 'baz')
506
revid_path = 'dir/revid-path'
507
self.tree.branch.get_config_stack(
508
).set('upload_revid_location', revid_path)
509
self.assertUpPathDoesNotExist(revid_path)
511
self.do_full_upload()
513
self.add_file('dir/hello', 'foo')
517
self.assertUpPathExists(revid_path)
518
self.assertUpFileEqual('baz', 'dir/goodbye')
519
self.assertUpFileEqual('foo', 'dir/hello')
521
def test_ignore_file(self):
522
self.make_branch_and_working_tree()
523
self.do_full_upload()
524
self.add_file('.bzrignore-upload', 'foo')
525
self.add_file('foo', 'bar')
529
self.assertUpPathDoesNotExist('foo')
531
def test_ignore_regexp(self):
532
self.make_branch_and_working_tree()
533
self.do_full_upload()
534
self.add_file('.bzrignore-upload', 'f*')
535
self.add_file('foo', 'bar')
539
self.assertUpPathDoesNotExist('foo')
541
def test_ignore_directory(self):
542
self.make_branch_and_working_tree()
543
self.do_full_upload()
544
self.add_file('.bzrignore-upload', 'dir')
549
self.assertUpPathDoesNotExist('dir')
551
def test_ignore_nested_directory(self):
552
self.make_branch_and_working_tree()
553
self.do_full_upload()
554
self.add_file('.bzrignore-upload', 'dir')
556
self.add_dir('dir/foo')
557
self.add_file('dir/foo/bar', 'bar contents')
561
self.assertUpPathDoesNotExist('dir')
562
self.assertUpPathDoesNotExist('dir/foo/bar')
564
def test_ignore_change_file_into_dir(self):
565
self.make_branch_and_working_tree()
566
self.add_file('hello', 'foo')
567
self.do_full_upload()
568
self.add_file('.bzrignore-upload', 'hello')
569
self.transform_file_into_dir('hello')
570
self.add_file('hello/file', 'bar')
572
self.assertUpFileEqual('foo', 'hello')
576
self.assertUpFileEqual('foo', 'hello')
578
def test_ignore_change_dir_into_file(self):
579
self.make_branch_and_working_tree()
580
self.add_dir('hello')
581
self.add_file('hello/file', 'foo')
582
self.do_full_upload()
584
self.add_file('.bzrignore-upload', 'hello')
585
self.delete_any('hello/file')
586
self.transform_dir_into_file('hello', 'bar')
588
self.assertUpFileEqual('foo', 'hello/file')
592
self.assertUpFileEqual('foo', 'hello/file')
594
def test_ignore_delete_dir_in_subdir(self):
595
self.make_branch_and_working_tree()
597
self.add_dir('dir/subdir')
598
self.add_file('dir/subdir/a', 'foo')
599
self.do_full_upload()
600
self.add_file('.bzrignore-upload', 'dir/subdir')
601
self.rename_any('dir/subdir/a', 'dir/a')
602
self.delete_any('dir/subdir')
604
self.assertUpFileEqual('foo', 'dir/subdir/a')
608
# The file in the dir is not ignored. This a bit contrived but
609
# indicates that we may encounter problems when ignored items appear
610
# and disappear... -- vila 100106
611
self.assertUpFileEqual('foo', 'dir/a')
614
class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
616
do_upload = TestUploadMixin.do_full_upload
618
def test_full_upload_empty_tree(self):
619
self.make_branch_and_working_tree()
621
self.do_full_upload()
623
revid_path = self.tree.branch.get_config_stack(
624
).get('upload_revid_location')
625
self.assertUpPathExists(revid_path)
627
def test_invalid_revspec(self):
628
self.make_branch_and_working_tree()
629
rev1 = revisionspec.RevisionSpec.from_string('1')
630
rev2 = revisionspec.RevisionSpec.from_string('2')
632
self.assertRaises(errors.BzrCommandError,
633
self.do_incremental_upload, revision=[rev1, rev2])
635
def test_create_remote_dir_twice(self):
636
self.make_branch_and_working_tree()
638
self.do_full_upload()
639
self.add_file('dir/goodbye', 'baz')
641
self.assertUpPathDoesNotExist('dir/goodbye')
643
self.do_full_upload()
645
self.assertUpFileEqual('baz', 'dir/goodbye')
646
self.assertUpPathModeEqual('dir', 0775)
649
class TestIncrementalUpload(tests.TestCaseWithTransport, TestUploadMixin):
651
do_upload = TestUploadMixin.do_incremental_upload
653
# XXX: full upload doesn't handle deletions....
655
def test_delete_one_file(self):
656
self.make_branch_and_working_tree()
657
self.add_file('hello', 'foo')
658
self.do_full_upload()
659
self.delete_any('hello')
661
self.assertUpFileEqual('foo', 'hello')
665
self.assertUpPathDoesNotExist('hello')
667
def test_delete_dir_and_subdir(self):
668
self.make_branch_and_working_tree()
670
self.add_dir('dir/subdir')
671
self.add_file('dir/subdir/a', 'foo')
672
self.do_full_upload()
673
self.rename_any('dir/subdir/a', 'a')
674
self.delete_any('dir/subdir')
675
self.delete_any('dir')
677
self.assertUpFileEqual('foo', 'dir/subdir/a')
681
self.assertUpPathDoesNotExist('dir/subdir/a')
682
self.assertUpPathDoesNotExist('dir/subdir')
683
self.assertUpPathDoesNotExist('dir')
684
self.assertUpFileEqual('foo', 'a')
686
def test_delete_one_file_rename_to_deleted(self):
687
self.make_branch_and_working_tree()
688
self.add_file('a', 'foo')
689
self.add_file('b', 'bar')
690
self.do_full_upload()
692
self.rename_any('b', 'a')
694
self.assertUpFileEqual('foo', 'a')
698
self.assertUpPathDoesNotExist('b')
699
self.assertUpFileEqual('bar', 'a')
701
def test_rename_outside_dir_delete_dir(self):
702
self.make_branch_and_working_tree()
704
self.add_file('dir/a', 'foo')
705
self.do_full_upload()
706
self.rename_any('dir/a', 'a')
707
self.delete_any('dir')
709
self.assertUpFileEqual('foo', 'dir/a')
713
self.assertUpPathDoesNotExist('dir/a')
714
self.assertUpPathDoesNotExist('dir')
715
self.assertUpFileEqual('foo', 'a')
717
def test_delete_symlink(self):
718
self.make_branch_and_working_tree()
719
self.add_symlink('link', 'target')
720
self.do_full_upload()
721
self.delete_any('link')
725
self.assertUpPathDoesNotExist('link')
727
def test_upload_for_the_first_time_do_a_full_upload(self):
728
self.make_branch_and_working_tree()
729
self.add_file('hello', 'bar')
731
revid_path = self.tree.branch.get_config_stack(
732
).get('upload_revid_location')
733
self.assertUpPathDoesNotExist(revid_path)
737
self.assertUpFileEqual('bar', 'hello')
739
def test_ignore_delete_one_file(self):
740
self.make_branch_and_working_tree()
741
self.add_file('hello', 'foo')
742
self.do_full_upload()
743
self.add_file('.bzrignore-upload', 'hello')
744
self.delete_any('hello')
746
self.assertUpFileEqual('foo', 'hello')
750
self.assertUpFileEqual('foo', 'hello')
753
class TestBranchUploadLocations(per_branch.TestCaseWithBranch):
755
def test_get_upload_location_unset(self):
756
conf = self.get_branch().get_config_stack()
757
self.assertEqual(None, conf.get('upload_location'))
759
def test_get_push_location_exact(self):
760
config.ensure_config_dir_exists()
761
fn = config.locations_config_filename()
762
b = self.get_branch()
763
with open(fn, 'wt') as f:
764
f.write(("[%s]\n" "upload_location=foo\n" % b.base.rstrip("/")))
765
self.assertEqual("foo", b.get_config_stack().get('upload_location'))
767
def test_set_push_location(self):
768
conf = self.get_branch().get_config_stack()
769
conf.set('upload_location', 'foo')
770
self.assertEqual('foo', conf.get('upload_location'))
773
class TestUploadFromRemoteBranch(tests.TestCaseWithTransport, UploadUtilsMixin):
775
remote_branch_dir = 'remote_branch'
778
super(TestUploadFromRemoteBranch, self).setUp()
779
self.remote_branch_url = self.make_remote_branch_without_working_tree()
781
def make_remote_branch_without_working_tree(self):
782
"""Creates a branch without working tree to upload from.
784
It's created from the existing self.branch_dir one which still has its
787
self.make_branch_and_working_tree()
788
self.add_file('hello', 'foo')
790
remote_branch_url = self.get_url(self.remote_branch_dir)
791
if self.transport_server is stub_sftp.SFTPHomeDirServer:
792
# FIXME: Some policy search ends up above the user home directory
793
# and are seen as attemps to escape test isolation
794
raise tests.TestNotApplicable('Escaping test isolation')
795
self.run_bzr(['push', remote_branch_url,
796
'--directory', self.branch_dir])
797
return remote_branch_url
799
def test_no_upload_to_remote_working_tree(self):
800
cmd = self._get_cmd_upload()
801
up_url = self.get_url(self.branch_dir)
802
# Let's try to upload from the just created remote branch into the
803
# branch (which has a working tree).
804
self.assertRaises(cmds.CannotUploadToWorkingTree,
805
cmd.run, up_url, directory=self.remote_branch_url)
807
def test_upload_without_working_tree(self):
808
self.do_full_upload(directory=self.remote_branch_url)
809
self.assertUpFileEqual('foo', 'hello')
812
class TestUploadDiverged(tests.TestCaseWithTransport, UploadUtilsMixin):
815
super(TestUploadDiverged, self).setUp()
816
self.diverged_tree = self.make_diverged_tree_and_upload_location()
818
def make_diverged_tree_and_upload_location(self):
819
tree_a = self.make_branch_and_tree('tree_a')
820
tree_a.commit('message 1', rev_id='rev1')
821
tree_a.commit('message 2', rev_id='rev2a')
822
tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
823
uncommit.uncommit(tree_b.branch, tree=tree_b)
824
tree_b.commit('message 2', rev_id='rev2b')
826
self.do_full_upload(directory=tree_a.basedir)
829
def assertRevidUploaded(self, revid):
830
t = self.get_transport(self.upload_dir)
831
uploaded_revid = t.get_bytes('.bzr-upload.revid')
832
self.assertEqual(revid, uploaded_revid)
834
def test_cant_upload_diverged(self):
835
self.assertRaises(cmds.DivergedUploadedTree,
836
self.do_incremental_upload,
837
directory=self.diverged_tree.basedir)
838
self.assertRevidUploaded('rev2a')
840
def test_upload_diverged_with_overwrite(self):
841
self.do_incremental_upload(directory=self.diverged_tree.basedir,
843
self.assertRevidUploaded('rev2b')
846
class TestUploadBadRemoteReivd(tests.TestCaseWithTransport, UploadUtilsMixin):
848
def test_raises_on_wrong_revid(self):
849
tree = self.make_branch_and_working_tree()
850
self.do_full_upload()
851
# Put a fake revid on the remote branch
852
t = self.get_transport(self.upload_dir)
853
t.put_bytes('.bzr-upload.revid', 'fake')
855
self.add_file('foo', 'bar\n')
856
self.assertRaises(cmds.DivergedUploadedTree, self.do_full_upload)