~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-20 08:37:32 UTC
  • mfrom: (4299 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4300.
  • Revision ID: tanner@real-time.com-20090420083732-bzx919oo7wpmqc2u
[merge] 1.14rc2 back into bzr.dev (Bob Tanner)

Show diffs side-by-side

added added

removed removed

Lines of Context:
296
296
        self.assertEqual(result, request.execute(''))
297
297
 
298
298
 
 
299
class TestSmartServerBzrDirRequestGetConfigFile(
 
300
    tests.TestCaseWithMemoryTransport):
 
301
    """Tests for BzrDir.get_config_file."""
 
302
 
 
303
    def test_present(self):
 
304
        backing = self.get_transport()
 
305
        dir = self.make_bzrdir('.')
 
306
        dir.get_config().set_default_stack_on("/")
 
307
        local_result = dir._get_config()._get_config_file().read()
 
308
        request_class = smart_dir.SmartServerBzrDirRequestConfigFile
 
309
        request = request_class(backing)
 
310
        expected = SuccessfulSmartServerResponse((), local_result)
 
311
        self.assertEqual(expected, request.execute(''))
 
312
 
 
313
    def test_missing(self):
 
314
        backing = self.get_transport()
 
315
        dir = self.make_bzrdir('.')
 
316
        request_class = smart_dir.SmartServerBzrDirRequestConfigFile
 
317
        request = request_class(backing)
 
318
        expected = SuccessfulSmartServerResponse((), '')
 
319
        self.assertEqual(expected, request.execute(''))
 
320
 
 
321
 
299
322
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
300
323
 
301
324
    def test_empty_dir(self):
769
792
            response)
770
793
 
771
794
 
 
795
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
 
796
 
 
797
    def test_set_parent_none(self):
 
798
        branch = self.make_branch('base', format="1.9")
 
799
        branch.lock_write()
 
800
        branch._set_parent_location('foo')
 
801
        branch.unlock()
 
802
        request = smart.branch.SmartServerBranchRequestSetParentLocation(
 
803
            self.get_transport())
 
804
        branch_token = branch.lock_write()
 
805
        repo_token = branch.repository.lock_write()
 
806
        try:
 
807
            response = request.execute('base', branch_token, repo_token, '')
 
808
        finally:
 
809
            branch.repository.unlock()
 
810
            branch.unlock()
 
811
        self.assertEqual(SuccessfulSmartServerResponse(()), response)
 
812
        self.assertEqual(None, branch.get_parent())
 
813
 
 
814
    def test_set_parent_something(self):
 
815
        branch = self.make_branch('base', format="1.9")
 
816
        request = smart.branch.SmartServerBranchRequestSetParentLocation(
 
817
            self.get_transport())
 
818
        branch_token = branch.lock_write()
 
819
        repo_token = branch.repository.lock_write()
 
820
        try:
 
821
            response = request.execute('base', branch_token, repo_token,
 
822
            'http://bar/')
 
823
        finally:
 
824
            branch.repository.unlock()
 
825
            branch.unlock()
 
826
        self.assertEqual(SuccessfulSmartServerResponse(()), response)
 
827
        self.assertEqual('http://bar/', branch.get_parent())
 
828
 
 
829
 
772
830
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
773
831
# Only called when the branch format and tags match [yay factory
774
832
# methods] so only need to test straight forward cases.
1386
1444
        for key, item in smart.request.request_handlers.iteritems():
1387
1445
            pass
1388
1446
 
 
1447
    def assertHandlerEqual(self, verb, handler):
 
1448
        self.assertEqual(smart.request.request_handlers.get(verb), handler)
 
1449
 
1389
1450
    def test_registered_methods(self):
1390
1451
        """Test that known methods are registered to the correct object."""
1391
 
        self.assertEqual(
1392
 
            smart.request.request_handlers.get('Branch.get_config_file'),
 
1452
        self.assertHandlerEqual('Branch.get_config_file',
1393
1453
            smart.branch.SmartServerBranchGetConfigFile)
1394
 
        self.assertEqual(
1395
 
            smart.request.request_handlers.get('Branch.get_parent'),
 
1454
        self.assertHandlerEqual('Branch.get_parent',
1396
1455
            smart.branch.SmartServerBranchGetParent)
1397
 
        self.assertEqual(
1398
 
            smart.request.request_handlers.get('Branch.get_tags_bytes'),
 
1456
        self.assertHandlerEqual('Branch.get_tags_bytes',
1399
1457
            smart.branch.SmartServerBranchGetTagsBytes)
1400
 
        self.assertEqual(
1401
 
            smart.request.request_handlers.get('Branch.lock_write'),
 
1458
        self.assertHandlerEqual('Branch.lock_write',
1402
1459
            smart.branch.SmartServerBranchRequestLockWrite)
1403
 
        self.assertEqual(
1404
 
            smart.request.request_handlers.get('Branch.last_revision_info'),
 
1460
        self.assertHandlerEqual('Branch.last_revision_info',
1405
1461
            smart.branch.SmartServerBranchRequestLastRevisionInfo)
1406
 
        self.assertEqual(
1407
 
            smart.request.request_handlers.get('Branch.revision_history'),
 
1462
        self.assertHandlerEqual('Branch.revision_history',
1408
1463
            smart.branch.SmartServerRequestRevisionHistory)
1409
 
        self.assertEqual(
1410
 
            smart.request.request_handlers.get('Branch.set_config_option'),
 
1464
        self.assertHandlerEqual('Branch.set_config_option',
1411
1465
            smart.branch.SmartServerBranchRequestSetConfigOption)
1412
 
        self.assertEqual(
1413
 
            smart.request.request_handlers.get('Branch.set_last_revision'),
 
1466
        self.assertHandlerEqual('Branch.set_last_revision',
1414
1467
            smart.branch.SmartServerBranchRequestSetLastRevision)
1415
 
        self.assertEqual(
1416
 
            smart.request.request_handlers.get('Branch.set_last_revision_info'),
 
1468
        self.assertHandlerEqual('Branch.set_last_revision_info',
1417
1469
            smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
1418
 
        self.assertEqual(
1419
 
            smart.request.request_handlers.get('Branch.unlock'),
 
1470
        self.assertHandlerEqual('Branch.set_last_revision_ex',
 
1471
            smart.branch.SmartServerBranchRequestSetLastRevisionEx)
 
1472
        self.assertHandlerEqual('Branch.set_parent_location',
 
1473
            smart.branch.SmartServerBranchRequestSetParentLocation)
 
1474
        self.assertHandlerEqual('Branch.unlock',
1420
1475
            smart.branch.SmartServerBranchRequestUnlock)
1421
 
        self.assertEqual(
1422
 
            smart.request.request_handlers.get('BzrDir.find_repository'),
 
1476
        self.assertHandlerEqual('BzrDir.find_repository',
1423
1477
            smart.bzrdir.SmartServerRequestFindRepositoryV1)
1424
 
        self.assertEqual(
1425
 
            smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
 
1478
        self.assertHandlerEqual('BzrDir.find_repositoryV2',
1426
1479
            smart.bzrdir.SmartServerRequestFindRepositoryV2)
1427
 
        self.assertEqual(
1428
 
            smart.request.request_handlers.get('BzrDirFormat.initialize'),
 
1480
        self.assertHandlerEqual('BzrDirFormat.initialize',
1429
1481
            smart.bzrdir.SmartServerRequestInitializeBzrDir)
1430
 
        self.assertEqual(
1431
 
            smart.request.request_handlers.get('BzrDir.cloning_metadir'),
 
1482
        self.assertHandlerEqual('BzrDir.cloning_metadir',
1432
1483
            smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1433
 
        self.assertEqual(
1434
 
            smart.request.request_handlers.get('BzrDir.open_branch'),
 
1484
        self.assertHandlerEqual('BzrDir.get_config_file',
 
1485
            smart.bzrdir.SmartServerBzrDirRequestConfigFile)
 
1486
        self.assertHandlerEqual('BzrDir.open_branch',
1435
1487
            smart.bzrdir.SmartServerRequestOpenBranch)
1436
 
        self.assertEqual(
1437
 
            smart.request.request_handlers.get('BzrDir.open_branchV2'),
 
1488
        self.assertHandlerEqual('BzrDir.open_branchV2',
1438
1489
            smart.bzrdir.SmartServerRequestOpenBranchV2)
1439
 
        self.assertEqual(
1440
 
            smart.request.request_handlers.get('PackRepository.autopack'),
 
1490
        self.assertHandlerEqual('PackRepository.autopack',
1441
1491
            smart.packrepository.SmartServerPackRepositoryAutopack)
1442
 
        self.assertEqual(
1443
 
            smart.request.request_handlers.get('Repository.gather_stats'),
 
1492
        self.assertHandlerEqual('Repository.gather_stats',
1444
1493
            smart.repository.SmartServerRepositoryGatherStats)
1445
 
        self.assertEqual(
1446
 
            smart.request.request_handlers.get('Repository.get_parent_map'),
 
1494
        self.assertHandlerEqual('Repository.get_parent_map',
1447
1495
            smart.repository.SmartServerRepositoryGetParentMap)
1448
 
        self.assertEqual(
1449
 
            smart.request.request_handlers.get(
1450
 
                'Repository.get_revision_graph'),
 
1496
        self.assertHandlerEqual('Repository.get_revision_graph',
1451
1497
            smart.repository.SmartServerRepositoryGetRevisionGraph)
1452
 
        self.assertEqual(
1453
 
            smart.request.request_handlers.get('Repository.get_stream'),
 
1498
        self.assertHandlerEqual('Repository.get_stream',
1454
1499
            smart.repository.SmartServerRepositoryGetStream)
1455
 
        self.assertEqual(
1456
 
            smart.request.request_handlers.get('Repository.has_revision'),
 
1500
        self.assertHandlerEqual('Repository.has_revision',
1457
1501
            smart.repository.SmartServerRequestHasRevision)
1458
 
        self.assertEqual(
1459
 
            smart.request.request_handlers.get('Repository.insert_stream'),
 
1502
        self.assertHandlerEqual('Repository.insert_stream',
1460
1503
            smart.repository.SmartServerRepositoryInsertStream)
1461
 
        self.assertEqual(
1462
 
            smart.request.request_handlers.get('Repository.insert_stream_locked'),
 
1504
        self.assertHandlerEqual('Repository.insert_stream_locked',
1463
1505
            smart.repository.SmartServerRepositoryInsertStreamLocked)
1464
 
        self.assertEqual(
1465
 
            smart.request.request_handlers.get('Repository.is_shared'),
 
1506
        self.assertHandlerEqual('Repository.is_shared',
1466
1507
            smart.repository.SmartServerRepositoryIsShared)
1467
 
        self.assertEqual(
1468
 
            smart.request.request_handlers.get('Repository.lock_write'),
 
1508
        self.assertHandlerEqual('Repository.lock_write',
1469
1509
            smart.repository.SmartServerRepositoryLockWrite)
1470
 
        self.assertEqual(
1471
 
            smart.request.request_handlers.get('Repository.tarball'),
 
1510
        self.assertHandlerEqual('Repository.tarball',
1472
1511
            smart.repository.SmartServerRepositoryTarball)
1473
 
        self.assertEqual(
1474
 
            smart.request.request_handlers.get('Repository.unlock'),
 
1512
        self.assertHandlerEqual('Repository.unlock',
1475
1513
            smart.repository.SmartServerRepositoryUnlock)
1476
 
        self.assertEqual(
1477
 
            smart.request.request_handlers.get('Transport.is_readonly'),
 
1514
        self.assertHandlerEqual('Transport.is_readonly',
1478
1515
            smart.request.SmartServerIsReadonly)