397
397
request.execute(''))
400
class SetLastRevisionCommonTests(object):
401
"""Mixin class for tests common to Branch.set_last_revision* variants."""
405
def test_not_present_revision_id(self):
406
backing = self.get_transport()
407
request = self.request_class(backing)
408
b = self.make_branch('.')
409
branch_token = b.lock_write()
410
repo_token = b.repository.lock_write()
411
b.repository.unlock()
413
revision_id = 'non-existent revision'
415
SmartServerResponse(('NoSuchRevision', revision_id)),
417
'', branch_token, repo_token,
423
400
class TestSmartServerBranchRequestSetLastRevision(
424
tests.TestCaseWithMemoryTransport, SetLastRevisionCommonTests):
401
tests.TestCaseWithMemoryTransport):
426
403
request_class = smart.branch.SmartServerBranchRequestSetLastRevision
405
def test_not_present_revision_id(self):
406
backing = self.get_transport()
407
request = self.request_class(backing)
408
b = self.make_branch('.')
409
branch_token = b.lock_write()
410
repo_token = b.repository.lock_write()
411
b.repository.unlock()
413
revision_id = 'non-existent revision'
415
SmartServerResponse(('NoSuchRevision', revision_id)),
417
'', branch_token, repo_token,
428
422
def test_revision_id_present2(self):
429
423
backing = self.get_transport()
430
424
request = self.request_class(backing)
477
471
class TestSmartServerBranchRequestSetLastRevisionDescendant(
478
tests.TestCaseWithMemoryTransport, SetLastRevisionCommonTests):
472
tests.TestCaseWithMemoryTransport):
480
474
request_class = \
481
475
smart.branch.SmartServerBranchRequestSetLastRevisionDescendant
488
482
repo_token = b.repository.lock_write()
489
483
b.repository.unlock()
491
self.assertEqual(SmartServerResponse(('ok',)),
485
self.assertEqual(SuccessfulSmartServerResponse(('ok', 0, 'null:')),
493
'', branch_token, repo_token,
487
'', branch_token, repo_token, 'null:', 0, 0))
498
def test_empty(self):
491
def test_not_present_revision_id(self):
499
492
backing = self.get_transport()
500
493
request = self.request_class(backing)
501
494
b = self.make_branch('.')
503
496
repo_token = b.repository.lock_write()
504
497
b.repository.unlock()
506
self.assertEqual(SmartServerResponse(('ok', 0)),
499
revision_id = 'non-existent revision'
501
SmartServerResponse(('NoSuchRevision', revision_id)),
508
'', branch_token, repo_token,
503
'', branch_token, repo_token, revision_id, 0, 0))
513
506
def test_revision_id_present2(self):
514
507
backing = self.get_transport()
515
508
request = self.request_class(backing)
526
519
tree.branch.repository.unlock()
528
521
self.assertEqual(
529
SuccessfulSmartServerResponse(('ok', 1)),
522
SuccessfulSmartServerResponse(('ok', 1, rev_id_utf8)),
531
'', branch_token, repo_token,
524
'', branch_token, repo_token, rev_id_utf8, 0, 0))
533
525
self.assertEqual([rev_id_utf8], tree.branch.revision_history())
535
527
tree.branch.unlock()
537
def test_revision_id_previous(self):
538
backing = self.get_transport()
539
request = self.request_class(backing)
540
tree = self.make_branch_and_memory_tree('.')
543
rev_id_utf8 = u'\xc8'.encode('utf-8')
544
r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
545
r2 = tree.commit('2nd commit', rev_id='second-rev')
547
branch_token = tree.branch.lock_write()
548
repo_token = tree.branch.repository.lock_write()
549
tree.branch.repository.unlock()
552
FailedSmartServerResponse(('NotDescendant',)),
554
'', branch_token, repo_token,
556
self.assertEqual('second-rev', tree.branch.last_revision())
560
529
def test_branch_diverged(self):
561
530
backing = self.get_transport()
562
531
request = self.request_class(backing)
578
547
tree.branch.repository.unlock()
580
549
self.assertEqual(
581
FailedSmartServerResponse(('NotDescendant',)),
550
FailedSmartServerResponse(('Diverged',)),
583
'', branch_token, repo_token,
552
'', branch_token, repo_token, 'child-1', 0, 0))
585
553
self.assertEqual('child-2', tree.branch.last_revision())
587
555
tree.branch.unlock()