~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

Set branch config options via a smart method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
502
502
            request.execute(''))
503
503
 
504
504
 
505
 
class SetLastRevisionTestBase(tests.TestCaseWithMemoryTransport):
 
505
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
 
506
 
 
507
    def get_lock_tokens(self, branch):
 
508
        branch_token = branch.lock_write()
 
509
        repo_token = branch.repository.lock_write()
 
510
        branch.repository.unlock()
 
511
        return branch_token, repo_token
 
512
 
 
513
 
 
514
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
 
515
 
 
516
    def test_value_name(self):
 
517
        branch = self.make_branch('.')
 
518
        request = smart.branch.SmartServerBranchRequestSetConfigOption(
 
519
            branch.bzrdir.root_transport)
 
520
        branch_token, repo_token = self.get_lock_tokens(branch)
 
521
        config = branch._get_config()
 
522
        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
 
523
            '')
 
524
        self.assertEqual(SuccessfulSmartServerResponse(()), result)
 
525
        self.assertEqual('bar', config.get_option('foo'))
 
526
 
 
527
    def test_value_name_section(self):
 
528
        branch = self.make_branch('.')
 
529
        request = smart.branch.SmartServerBranchRequestSetConfigOption(
 
530
            branch.bzrdir.root_transport)
 
531
        branch_token, repo_token = self.get_lock_tokens(branch)
 
532
        config = branch._get_config()
 
533
        result = request.execute('', branch_token, repo_token, 'bar', 'foo',
 
534
            'gam')
 
535
        self.assertEqual(SuccessfulSmartServerResponse(()), result)
 
536
        self.assertEqual('bar', config.get_option('foo', 'gam'))
 
537
 
 
538
 
 
539
class SetLastRevisionTestBase(TestLockedBranch):
506
540
    """Base test case for verbs that implement set_last_revision."""
507
541
 
508
542
    def setUp(self):
512
546
        self.tree = self.make_branch_and_memory_tree('.')
513
547
 
514
548
    def lock_branch(self):
515
 
        b = self.tree.branch
516
 
        branch_token = b.lock_write()
517
 
        repo_token = b.repository.lock_write()
518
 
        b.repository.unlock()
519
 
        return branch_token, repo_token
 
549
        return self.get_lock_tokens(self.tree.branch)
520
550
 
521
551
    def unlock_branch(self):
522
552
        self.tree.branch.unlock()
1377
1407
            smart.request.request_handlers.get('Branch.revision_history'),
1378
1408
            smart.branch.SmartServerRequestRevisionHistory)
1379
1409
        self.assertEqual(
 
1410
            smart.request.request_handlers.get('Branch.set_config_option'),
 
1411
            smart.branch.SmartServerBranchRequestSetConfigOption)
 
1412
        self.assertEqual(
1380
1413
            smart.request.request_handlers.get('Branch.set_last_revision'),
1381
1414
            smart.branch.SmartServerBranchRequestSetLastRevision)
1382
1415
        self.assertEqual(