27
from bzrlib.controldir import ControlDir
28
28
from bzrlib.bundle import serializer
29
29
from bzrlib.transport import memory
32
def load_tests(standard_tests, module, loader):
33
"""Multiply tests for the send command."""
34
result = loader.suiteClass()
36
# one for each king of change
37
changes_tests, remaining_tests = tests.split_suite_by_condition(
38
standard_tests, tests.condition_isinstance((
39
TestSendStrictWithChanges,
43
dict(_changes_type='_uncommitted_changes')),
45
dict(_changes_type='_pending_merges')),
47
dict(_changes_type='_out_of_sync_trees')),
49
tests.multiply_tests(changes_tests, changes_scenarios, result)
50
# No parametrization for the remaining tests
51
result.addTests(remaining_tests)
30
from bzrlib.tests import (
33
from bzrlib.tests.matchers import ContainsNoVfsCalls
36
load_tests = scenarios.load_tests_apply_scenarios
56
39
class TestSendMixin(object):
207
190
def test_note_revisions(self):
208
191
stderr = self.run_send([])[1]
209
self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
192
self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
211
194
def test_mailto_option(self):
212
195
b = branch.Branch.open('branch')
213
b.get_config().set_user_option('mail_client', 'editor')
196
b.get_config_stack().set('mail_client', 'editor')
214
197
self.run_bzr_error(
215
198
('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
216
199
), 'send -f branch')
217
b.get_config().set_user_option('mail_client', 'bogus')
200
b.get_config_stack().set('mail_client', 'bogus')
218
201
self.run_send([])
219
self.run_bzr_error(('Unknown mail client: bogus',),
202
self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
220
203
'send -f branch --mail-to jrandom@example.org')
221
b.get_config().set_user_option('submit_to', 'jrandom@example.org')
222
self.run_bzr_error(('Unknown mail client: bogus',),
204
b.get_config_stack().set('submit_to', 'jrandom@example.org')
205
self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
223
206
'send -f branch')
225
208
def test_mailto_child_option(self):
226
209
"""Make sure that child_submit_to is used."""
227
210
b = branch.Branch.open('branch')
228
b.get_config().set_user_option('mail_client', 'bogus')
211
b.get_config_stack().set('mail_client', 'bogus')
229
212
parent = branch.Branch.open('parent')
230
parent.get_config().set_user_option('child_submit_to',
231
'somebody@example.org')
232
self.run_bzr_error(('Unknown mail client: bogus',),
213
parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
214
self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
235
217
def test_format(self):
236
218
md = self.get_MD(['--format=4'])
248
230
'send -f branch -o- --format=0.999')[0]
250
232
def test_format_child_option(self):
251
parent_config = branch.Branch.open('parent').get_config()
252
parent_config.set_user_option('child_submit_format', '4')
233
br = branch.Branch.open('parent')
234
conf = br.get_config_stack()
235
conf.set('child_submit_format', '4')
253
236
md = self.get_MD([])
254
237
self.assertIs(merge_directive.MergeDirective2, md.__class__)
256
parent_config.set_user_option('child_submit_format', '0.9')
239
conf.set('child_submit_format', '0.9')
257
240
md = self.get_MD([])
258
241
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
261
244
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
262
245
self.assertIs(merge_directive.MergeDirective, md.__class__)
264
parent_config.set_user_option('child_submit_format', '0.999')
247
conf.set('child_submit_format', '0.999')
265
248
self.run_bzr_error(["No such send format '0.999'"],
266
249
'send -f branch -o-')[0]
307
290
_default_sent_revs = ['local']
308
291
_default_errors = ['Working tree ".*/local/" has uncommitted '
309
292
'changes \(See bzr status\)\.',]
293
_default_additional_error = 'Use --no-strict to force the send.\n'
294
_default_additional_warning = 'Uncommitted changes will not be sent.'
311
296
def set_config_send_strict(self, value):
312
# set config var (any of bazaar.conf, locations.conf, branch.conf
314
conf = self.local_tree.branch.get_config()
315
conf.set_user_option('send_strict', value)
297
br = branch.Branch.open('local')
298
br.get_config_stack().set('send_strict', value)
317
300
def assertSendFails(self, args):
318
self.run_send(args, rc=3, err_re=self._default_errors)
301
out, err = self.run_send(args, rc=3, err_re=self._default_errors)
302
self.assertContainsRe(err, self._default_additional_error)
320
def assertSendSucceeds(self, args, revs=None):
304
def assertSendSucceeds(self, args, revs=None, with_warning=False):
306
err_re = self._default_errors
322
310
revs = self._default_sent_revs
323
out, err = self.run_send(args)
325
'Bundling %d revision(s).\n' % len(revs), err)
311
out, err = self.run_send(args, err_re=err_re)
313
bundling_revs = 'Bundling %d revision.\n'% len(revs)
315
bundling_revs = 'Bundling %d revisions.\n' % len(revs)
317
self.assertContainsRe(err, self._default_additional_warning)
318
self.assertEndsWith(err, bundling_revs)
320
self.assertEquals(bundling_revs, err)
326
321
md = merge_directive.MergeDirective.from_lines(StringIO(out))
327
322
self.assertEqual('parent', md.base_revision_id)
328
323
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
336
331
super(TestSendStrictWithoutChanges, self).setUp()
337
332
self.make_parent_and_local_branches()
334
def test_send_without_workingtree(self):
335
ControlDir.open("local").destroy_workingtree()
336
self.assertSendSucceeds([])
339
338
def test_send_default(self):
340
339
self.assertSendSucceeds([])
357
356
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
358
TestSendStrictMixin):
357
TestSendStrictMixin):
359
# These are textually the same as test_push.strict_push_change_scenarios,
360
# but since the functions are reimplemented here, the definitions are left
364
dict(_changes_type='_uncommitted_changes')),
366
dict(_changes_type='_pending_merges')),
367
('out-of-sync-trees',
368
dict(_changes_type='_out_of_sync_trees')),
360
371
_changes_type = None # Set by load_tests
396
407
self._default_sent_revs = ['modified-in-local', 'local']
398
409
def test_send_default(self):
399
self.assertSendFails([])
410
self.assertSendSucceeds([], with_warning=True)
401
412
def test_send_with_revision(self):
402
413
self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
412
423
self.assertSendFails([])
413
424
self.assertSendSucceeds(['--no-strict'])
416
426
def test_send_bogus_config_var_ignored(self):
417
427
self.set_config_send_strict("I'm unsure")
418
self.assertSendFails([])
428
self.assertSendSucceeds([], with_warning=True)
421
430
def test_send_no_strict_command_line_override_config(self):
422
431
self.set_config_send_strict('true')
432
441
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
434
443
_default_command = ['bundle-revisions', '../parent']
446
class TestSmartServerSend(tests.TestCaseWithTransport):
449
self.setup_smart_server_with_call_log()
450
t = self.make_branch_and_tree('branch')
451
self.build_tree_contents([('branch/foo', 'thecontents')])
454
local = t.bzrdir.sprout('local-branch').open_workingtree()
455
self.build_tree_contents([('branch/foo', 'thenewcontents')])
456
local.commit("anothermessage")
457
self.reset_smart_call_log()
458
out, err = self.run_bzr(
459
['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
460
# This figure represent the amount of work to perform this use case. It
461
# is entirely ok to reduce this number if a test fails due to rpc_count
462
# being too low. If rpc_count increases, more network roundtrips have
463
# become necessary for this use case. Please do not adjust this number
464
# upwards without agreement from bzr's network support maintainers.
465
self.assertLength(7, self.hpss_calls)
466
self.assertLength(1, self.hpss_connections)
467
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)