169
175
# against servers that can't. Note that some bzrlib transports define
170
176
# _can_roundtrip_unix_modebits in a incomplete way, this property
171
177
# should depend on both the client and the server, not the client only.
172
st = os.stat(base + path)
178
full_path = osutils.pathjoin(base, path)
179
st = os.stat(full_path)
173
180
mode = st.st_mode & 0777
174
181
if expected_mode == mode:
176
183
raise AssertionError(
177
184
'For path %s, mode is %s not %s' %
178
(base + path, oct(mode), oct(expected_mode)))
185
(full_path, oct(mode), oct(expected_mode)))
180
187
def failIfUpFileExists(self, path, base=upload_dir):
181
self.failIfExists(base + path)
188
self.failIfExists(osutils.pathjoin(base, path))
183
190
def failUnlessUpFileExists(self, path, base=upload_dir):
184
self.failUnlessExists(base + path)
191
self.failUnlessExists(osutils.pathjoin(base, path))
186
def set_file_content(self, name, content, base=branch_dir):
187
f = file(base + name, 'wb')
193
def set_file_content(self, path, content, base=branch_dir):
194
f = file(osutils.pathjoin(base, path), 'wb')
193
def add_file(self, name, content, base=branch_dir):
194
self.set_file_content(name, content, base)
196
self.tree.commit('add file %s' % name)
198
def modify_file(self, name, content, base=branch_dir):
199
self.set_file_content(name, content, base)
200
self.tree.commit('modify file %s' % name)
202
def chmod_file(self, name, mode, base=branch_dir):
205
self.tree.commit('change file %s mode to %s' % (name, oct(mode)))
207
def delete_any(self, name, base=branch_dir):
208
self.tree.remove([name], keep_files=False)
209
self.tree.commit('delete %s' % name)
211
def add_dir(self, name, base=branch_dir):
212
os.mkdir(base + name)
214
self.tree.commit('add directory %s' % name)
216
def rename_any(self, old_name, new_name):
217
self.tree.rename_one(old_name, new_name)
218
self.tree.commit('rename %s into %s' % (old_name, new_name))
220
def transform_dir_into_file(self, name, content, base=branch_dir):
221
osutils.delete_any(base + name)
222
self.set_file_content(name, content, base)
223
self.tree.commit('change %s from dir to file' % name)
225
def transform_file_into_dir(self, name, base=branch_dir):
200
def add_file(self, path, content, base=branch_dir):
201
self.set_file_content(path, content, base)
203
self.tree.commit('add file %s' % path)
205
def modify_file(self, path, content, base=branch_dir):
206
self.set_file_content(path, content, base)
207
self.tree.commit('modify file %s' % path)
209
def chmod_file(self, path, mode, base=branch_dir):
210
full_path = osutils.pathjoin(base, path)
211
os.chmod(full_path, mode)
212
self.tree.commit('change file %s mode to %s' % (path, oct(mode)))
214
def delete_any(self, path, base=branch_dir):
215
self.tree.remove([path], keep_files=False)
216
self.tree.commit('delete %s' % path)
218
def add_dir(self, path, base=branch_dir):
219
os.mkdir(osutils.pathjoin(base, path))
221
self.tree.commit('add directory %s' % path)
223
def rename_any(self, old_path, new_path):
224
self.tree.rename_one(old_path, new_path)
225
self.tree.commit('rename %s into %s' % (old_path, new_path))
227
def transform_dir_into_file(self, path, content, base=branch_dir):
228
osutils.delete_any(osutils.pathjoin(base, path))
229
self.set_file_content(path, content, base)
230
self.tree.commit('change %s from dir to file' % path)
232
def transform_file_into_dir(self, path, base=branch_dir):
226
233
# bzr can't handle that kind change in a single commit without an
227
234
# intervening bzr status (see bug #205636).
228
self.tree.remove([name], keep_files=False)
229
os.mkdir(base + name)
231
self.tree.commit('change %s from file to dir' % name)
235
self.tree.remove([path], keep_files=False)
236
os.mkdir(osutils.pathjoin(base, path))
238
self.tree.commit('change %s from file to dir' % path)
233
240
def _get_cmd_upload(self):
234
241
upload = cmd_upload()
241
248
def do_full_upload(self, *args, **kwargs):
242
249
upload = self._get_cmd_upload()
243
up_url = self.get_transport(self.upload_dir).external_url()
250
up_url = self.get_url(self.upload_dir)
244
251
if kwargs.get('directory', None) is None:
245
kwargs['directory'] = 'branch'
252
kwargs['directory'] = self.branch_dir
246
253
kwargs['full'] = True
247
254
kwargs['quiet'] = True
248
255
upload.run(up_url, *args, **kwargs)
250
257
def do_incremental_upload(self, *args, **kwargs):
251
258
upload = self._get_cmd_upload()
252
up_url = self.get_transport(self.upload_dir).external_url()
259
up_url = self.get_url(self.upload_dir)
253
260
if kwargs.get('directory', None) is None:
254
kwargs['directory'] = 'branch'
261
kwargs['directory'] = self.branch_dir
255
262
kwargs['quiet'] = True
256
263
upload.run(up_url, *args, **kwargs)
266
class TestUploadMixin(UploadUtilsMixin):
267
"""Helper class to share tests between full and incremental uploads."""
258
269
def test_create_file(self):
259
self.make_local_branch()
270
self.make_branch_and_working_tree()
260
271
self.do_full_upload()
261
272
self.add_file('hello', 'foo')
406
417
self.assertUpPathModeEqual('hello', 0775)
419
def get_upload_auto(self):
420
return get_upload_auto(self.tree.branch)
408
422
def test_upload_auto(self):
409
423
"""Test that upload --auto sets the upload_auto option"""
410
self.make_local_branch()
424
self.make_branch_and_working_tree()
411
426
self.add_file('hello', 'foo')
412
self.assertFalse(get_upload_auto(self.tree.branch))
427
self.assertFalse(self.get_upload_auto())
413
428
self.do_full_upload(auto=True)
414
429
self.assertUpFileEqual('foo', 'hello')
415
self.assertTrue(get_upload_auto(self.tree.branch))
430
self.assertTrue(self.get_upload_auto())
416
432
# and check that it stays set until it is unset
417
433
self.add_file('bye', 'bar')
418
434
self.do_full_upload()
419
435
self.assertUpFileEqual('bar', 'bye')
420
self.assertTrue(get_upload_auto(self.tree.branch))
436
self.assertTrue(self.get_upload_auto())
422
438
def test_upload_noauto(self):
423
439
"""Test that upload --no-auto unsets the upload_auto option"""
424
self.make_local_branch()
440
self.make_branch_and_working_tree()
425
442
self.add_file('hello', 'foo')
426
self.assertFalse(get_upload_auto(self.tree.branch))
427
443
self.do_full_upload(auto=True)
428
444
self.assertUpFileEqual('foo', 'hello')
429
self.assertTrue(get_upload_auto(self.tree.branch))
445
self.assertTrue(self.get_upload_auto())
430
447
self.add_file('bye', 'bar')
431
448
self.do_full_upload(auto=False)
432
449
self.assertUpFileEqual('bar', 'bye')
433
self.assertFalse(get_upload_auto(self.tree.branch))
450
self.assertFalse(self.get_upload_auto())
434
452
# and check that it stays unset until it is set
435
453
self.add_file('again', 'baz')
436
454
self.do_full_upload()
437
455
self.assertUpFileEqual('baz', 'again')
438
self.assertFalse(get_upload_auto(self.tree.branch))
456
self.assertFalse(self.get_upload_auto())
440
458
def test_upload_from_subdir(self):
441
self.make_local_branch()
459
self.make_branch_and_working_tree()
442
460
self.build_tree(['branch/foo/', 'branch/foo/bar'])
443
461
self.tree.add(['foo/', 'foo/bar'])
444
462
self.tree.commit("Add directory")
580
598
config.set_user_option('upload_location', 'foo')
581
599
self.assertEqual('foo', config.get_user_option('upload_location'))
602
class TestUploadFromRemoteBranch(tests.TestCaseWithTransport,
605
remote_branch_dir = 'remote_branch'
607
def make_remote_branch_without_working_tree(self):
608
"""Creates a branch without working tree to upload from.
610
It's created from the existing self.branch_dir one which still has its
613
self.make_branch_and_working_tree()
614
self.add_file('hello', 'foo')
616
remote_branch_url = self.get_url(self.remote_branch_dir)
617
self.run_bzr(['push', remote_branch_url,
618
'--directory', self.branch_dir])
619
return remote_branch_url
621
def test_no_upload_to_remote_working_tree(self):
622
remote_branch_url = self.make_remote_branch_without_working_tree()
623
upload = self._get_cmd_upload()
624
up_url = self.get_url(self.branch_dir)
625
# Let's try to upload from the just created remote branch into the
626
# branch (with has a working tree).
627
self.assertRaises(CannotUploadToWorkingTreeError,
628
upload.run, up_url, directory=remote_branch_url)
630
def test_upload_without_working_tree(self):
631
remote_branch_url = self.make_remote_branch_without_working_tree()
632
self.do_full_upload(directory=remote_branch_url)
633
self.assertUpFileEqual('foo', 'hello')