16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20
from cStringIO import StringIO
21
22
from bzrlib import (
26
from bzrlib.controldir import ControlDir
27
28
from bzrlib.bundle import serializer
28
29
from bzrlib.transport import memory
29
from bzrlib.tests import (
32
from bzrlib.tests.matchers import ContainsNoVfsCalls
35
load_tests = scenarios.load_tests_apply_scenarios
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)
38
56
class TestSendMixin(object):
64
82
super(TestSend, self).setUp()
65
grandparent_tree = ControlDir.create_standalone_workingtree(
83
grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
67
85
self.build_tree_contents([('grandparent/file1', 'grandparent')])
68
86
grandparent_tree.add('file1')
189
207
def test_note_revisions(self):
190
208
stderr = self.run_send([])[1]
191
self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
209
self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
193
211
def test_mailto_option(self):
194
212
b = branch.Branch.open('branch')
195
b.get_config_stack().set('mail_client', 'editor')
213
b.get_config().set_user_option('mail_client', 'editor')
196
214
self.run_bzr_error(
197
215
('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
198
216
), 'send -f branch')
199
b.get_config_stack().set('mail_client', 'bogus')
217
b.get_config().set_user_option('mail_client', 'bogus')
200
218
self.run_send([])
201
self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
219
self.run_bzr_error(('Unknown mail client: bogus',),
202
220
'send -f branch --mail-to jrandom@example.org')
203
b.get_config_stack().set('submit_to', 'jrandom@example.org')
204
self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
221
b.get_config().set_user_option('submit_to', 'jrandom@example.org')
222
self.run_bzr_error(('Unknown mail client: bogus',),
205
223
'send -f branch')
207
225
def test_mailto_child_option(self):
208
226
"""Make sure that child_submit_to is used."""
209
227
b = branch.Branch.open('branch')
210
b.get_config_stack().set('mail_client', 'bogus')
228
b.get_config().set_user_option('mail_client', 'bogus')
211
229
parent = branch.Branch.open('parent')
212
parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
213
self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
230
parent.get_config().set_user_option('child_submit_to',
231
'somebody@example.org')
232
self.run_bzr_error(('Unknown mail client: bogus',),
216
235
def test_format(self):
217
236
md = self.get_MD(['--format=4'])
229
248
'send -f branch -o- --format=0.999')[0]
231
250
def test_format_child_option(self):
232
br = branch.Branch.open('parent')
233
conf = br.get_config_stack()
234
conf.set('child_submit_format', '4')
251
parent_config = branch.Branch.open('parent').get_config()
252
parent_config.set_user_option('child_submit_format', '4')
235
253
md = self.get_MD([])
236
254
self.assertIs(merge_directive.MergeDirective2, md.__class__)
238
conf.set('child_submit_format', '0.9')
256
parent_config.set_user_option('child_submit_format', '0.9')
239
257
md = self.get_MD([])
240
258
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
243
261
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
244
262
self.assertIs(merge_directive.MergeDirective, md.__class__)
246
conf.set('child_submit_format', '0.999')
264
parent_config.set_user_option('child_submit_format', '0.999')
247
265
self.run_bzr_error(["No such send format '0.999'"],
248
266
'send -f branch -o-')[0]
275
293
def make_parent_and_local_branches(self):
276
294
# Create a 'parent' branch as the base
277
self.parent_tree = ControlDir.create_standalone_workingtree('parent')
295
self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
278
296
self.build_tree_contents([('parent/file', 'parent')])
279
297
self.parent_tree.add('file')
280
298
self.parent_tree.commit('first commit', rev_id='parent')
293
311
_default_additional_warning = 'Uncommitted changes will not be sent.'
295
313
def set_config_send_strict(self, value):
296
br = branch.Branch.open('local')
297
br.get_config_stack().set('send_strict', value)
314
# set config var (any of bazaar.conf, locations.conf, branch.conf
316
conf = self.local_tree.branch.get_config()
317
conf.set_user_option('send_strict', value)
299
319
def assertSendFails(self, args):
300
320
out, err = self.run_send(args, rc=3, err_re=self._default_errors)
309
329
revs = self._default_sent_revs
310
330
out, err = self.run_send(args, err_re=err_re)
312
bundling_revs = 'Bundling %d revision.\n'% len(revs)
314
bundling_revs = 'Bundling %d revisions.\n' % len(revs)
331
bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
316
333
self.assertContainsRe(err, self._default_additional_warning)
317
334
self.assertEndsWith(err, bundling_revs)
319
self.assertEqual(bundling_revs, err)
336
self.assertEquals(bundling_revs, err)
320
337
md = merge_directive.MergeDirective.from_lines(StringIO(out))
321
338
self.assertEqual('parent', md.base_revision_id)
322
339
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
330
347
super(TestSendStrictWithoutChanges, self).setUp()
331
348
self.make_parent_and_local_branches()
333
def test_send_without_workingtree(self):
334
ControlDir.open("local").destroy_workingtree()
335
self.assertSendSucceeds([])
337
350
def test_send_default(self):
338
351
self.assertSendSucceeds([])
355
368
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
356
TestSendStrictMixin):
358
# These are textually the same as test_push.strict_push_change_scenarios,
359
# but since the functions are reimplemented here, the definitions are left
363
dict(_changes_type='_uncommitted_changes')),
365
dict(_changes_type='_pending_merges')),
366
('out-of-sync-trees',
367
dict(_changes_type='_out_of_sync_trees')),
369
TestSendStrictMixin):
370
371
_changes_type = None # Set by load_tests
440
441
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
442
443
_default_command = ['bundle-revisions', '../parent']
445
class TestSmartServerSend(tests.TestCaseWithTransport):
448
self.setup_smart_server_with_call_log()
449
t = self.make_branch_and_tree('branch')
450
self.build_tree_contents([('branch/foo', 'thecontents')])
453
local = t.bzrdir.sprout('local-branch').open_workingtree()
454
self.build_tree_contents([('branch/foo', 'thenewcontents')])
455
local.commit("anothermessage")
456
self.reset_smart_call_log()
457
out, err = self.run_bzr(
458
['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
459
# This figure represent the amount of work to perform this use case. It
460
# is entirely ok to reduce this number if a test fails due to rpc_count
461
# being too low. If rpc_count increases, more network roundtrips have
462
# become necessary for this use case. Please do not adjust this number
463
# upwards without agreement from bzr's network support maintainers.
464
self.assertLength(7, self.hpss_calls)
465
self.assertLength(1, self.hpss_connections)
466
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)