/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-28 16:04:39 UTC
  • mfrom: (4387 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4405.
  • Revision ID: jelmer@samba.org-20090528160439-4z0xlrk5nejobm7q
Merge bzr.dev.

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):
327
350
            request.execute, 'subdir')
328
351
 
329
352
 
 
353
class TestSmartServerRequestBzrDirInitializeEx(tests.TestCaseWithMemoryTransport):
 
354
    """Basic tests for BzrDir.initialize_ex in the smart server.
 
355
 
 
356
    The main unit tests in test_bzrdir exercise the API comprehensively.
 
357
    """
 
358
 
 
359
    def test_empty_dir(self):
 
360
        """Initializing an empty dir should succeed and do it."""
 
361
        backing = self.get_transport()
 
362
        name = self.make_bzrdir('reference')._format.network_name()
 
363
        request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
 
364
        self.assertEqual(SmartServerResponse(('', '', '', '', '', '', name,
 
365
            'False', '', '', '')),
 
366
            request.execute(name, '', 'True', 'False', 'False', '', '', '', '',
 
367
            'False'))
 
368
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
 
369
        # no branch, tree or repository is expected with the current
 
370
        # default format.
 
371
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
 
372
        self.assertRaises(errors.NotBranchError, made_dir.open_branch)
 
373
        self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository)
 
374
 
 
375
    def test_missing_dir(self):
 
376
        """Initializing a missing directory should fail like the bzrdir api."""
 
377
        backing = self.get_transport()
 
378
        name = self.make_bzrdir('reference')._format.network_name()
 
379
        request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
 
380
        self.assertRaises(errors.NoSuchFile, request.execute, name,
 
381
            'subdir/dir', 'False', 'False', 'False', '', '', '', '', 'False')
 
382
 
 
383
    def test_initialized_dir(self):
 
384
        """Initializing an extant dirctory should fail like the bzrdir api."""
 
385
        backing = self.get_transport()
 
386
        name = self.make_bzrdir('reference')._format.network_name()
 
387
        request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
 
388
        self.make_bzrdir('subdir')
 
389
        self.assertRaises(errors.FileExists, request.execute, name, 'subdir',
 
390
            'False', 'False', 'False', '', '', '', '', 'False')
 
391
 
 
392
 
330
393
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
331
394
 
332
395
    def test_no_branch(self):
523
586
            '')
524
587
        self.assertEqual(SuccessfulSmartServerResponse(()), result)
525
588
        self.assertEqual('bar', config.get_option('foo'))
 
589
        # Cleanup
 
590
        branch.unlock()
526
591
 
527
592
    def test_value_name_section(self):
528
593
        branch = self.make_branch('.')
534
599
            'gam')
535
600
        self.assertEqual(SuccessfulSmartServerResponse(()), result)
536
601
        self.assertEqual('bar', config.get_option('foo', 'gam'))
 
602
        # Cleanup
 
603
        branch.unlock()
537
604
 
538
605
 
539
606
class SetLastRevisionTestBase(TestLockedBranch):
769
836
            response)
770
837
 
771
838
 
 
839
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
 
840
 
 
841
    def test_set_parent_none(self):
 
842
        branch = self.make_branch('base', format="1.9")
 
843
        branch.lock_write()
 
844
        branch._set_parent_location('foo')
 
845
        branch.unlock()
 
846
        request = smart.branch.SmartServerBranchRequestSetParentLocation(
 
847
            self.get_transport())
 
848
        branch_token = branch.lock_write()
 
849
        repo_token = branch.repository.lock_write()
 
850
        try:
 
851
            response = request.execute('base', branch_token, repo_token, '')
 
852
        finally:
 
853
            branch.repository.unlock()
 
854
            branch.unlock()
 
855
        self.assertEqual(SuccessfulSmartServerResponse(()), response)
 
856
        self.assertEqual(None, branch.get_parent())
 
857
 
 
858
    def test_set_parent_something(self):
 
859
        branch = self.make_branch('base', format="1.9")
 
860
        request = smart.branch.SmartServerBranchRequestSetParentLocation(
 
861
            self.get_transport())
 
862
        branch_token = branch.lock_write()
 
863
        repo_token = branch.repository.lock_write()
 
864
        try:
 
865
            response = request.execute('base', branch_token, repo_token,
 
866
            'http://bar/')
 
867
        finally:
 
868
            branch.repository.unlock()
 
869
            branch.unlock()
 
870
        self.assertEqual(SuccessfulSmartServerResponse(()), response)
 
871
        self.assertEqual('http://bar/', branch.get_parent())
 
872
 
 
873
 
772
874
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
773
875
# Only called when the branch format and tags match [yay factory
774
876
# methods] so only need to test straight forward cases.
817
919
        # with a new branch object.
818
920
        new_branch = repository.bzrdir.open_branch()
819
921
        self.assertRaises(errors.LockContention, new_branch.lock_write)
 
922
        # Cleanup
 
923
        request = smart.branch.SmartServerBranchRequestUnlock(backing)
 
924
        response = request.execute('', branch_nonce, repository_nonce)
820
925
 
821
926
    def test_lock_write_on_locked_branch(self):
822
927
        backing = self.get_transport()
823
928
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
824
929
        branch = self.make_branch('.')
825
 
        branch.lock_write()
 
930
        branch_token = branch.lock_write()
826
931
        branch.leave_lock_in_place()
827
932
        branch.unlock()
828
933
        response = request.execute('')
829
934
        self.assertEqual(
830
935
            SmartServerResponse(('LockContention',)), response)
 
936
        # Cleanup
 
937
        branch.lock_write(branch_token)
 
938
        branch.dont_leave_lock_in_place()
 
939
        branch.unlock()
831
940
 
832
941
    def test_lock_write_with_tokens_on_locked_branch(self):
833
942
        backing = self.get_transport()
843
952
                                   branch_token, repo_token)
844
953
        self.assertEqual(
845
954
            SmartServerResponse(('ok', branch_token, repo_token)), response)
 
955
        # Cleanup
 
956
        branch.repository.lock_write(repo_token)
 
957
        branch.repository.dont_leave_lock_in_place()
 
958
        branch.repository.unlock()
 
959
        branch.lock_write(branch_token)
 
960
        branch.dont_leave_lock_in_place()
 
961
        branch.unlock()
846
962
 
847
963
    def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
848
964
        backing = self.get_transport()
858
974
                                   branch_token+'xxx', repo_token)
859
975
        self.assertEqual(
860
976
            SmartServerResponse(('TokenMismatch',)), response)
 
977
        # Cleanup
 
978
        branch.repository.lock_write(repo_token)
 
979
        branch.repository.dont_leave_lock_in_place()
 
980
        branch.repository.unlock()
 
981
        branch.lock_write(branch_token)
 
982
        branch.dont_leave_lock_in_place()
 
983
        branch.unlock()
861
984
 
862
985
    def test_lock_write_on_locked_repo(self):
863
986
        backing = self.get_transport()
864
987
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
865
988
        branch = self.make_branch('.', format='knit')
866
 
        branch.repository.lock_write()
867
 
        branch.repository.leave_lock_in_place()
868
 
        branch.repository.unlock()
 
989
        repo = branch.repository
 
990
        repo_token = repo.lock_write()
 
991
        repo.leave_lock_in_place()
 
992
        repo.unlock()
869
993
        response = request.execute('')
870
994
        self.assertEqual(
871
995
            SmartServerResponse(('LockContention',)), response)
 
996
        # Cleanup
 
997
        repo.lock_write(repo_token)
 
998
        repo.dont_leave_lock_in_place()
 
999
        repo.unlock()
872
1000
 
873
1001
    def test_lock_write_on_readonly_transport(self):
874
1002
        backing = self.get_readonly_transport()
933
1061
            '', 'branch token', repo_token)
934
1062
        self.assertEqual(
935
1063
            SmartServerResponse(('TokenMismatch',)), response)
 
1064
        # Cleanup
 
1065
        branch.repository.lock_write(repo_token)
 
1066
        branch.repository.dont_leave_lock_in_place()
 
1067
        branch.repository.unlock()
936
1068
 
937
1069
 
938
1070
class TestSmartServerRepositoryRequest(tests.TestCaseWithMemoryTransport):
1184
1316
        # object.
1185
1317
        new_repo = repository.bzrdir.open_repository()
1186
1318
        self.assertRaises(errors.LockContention, new_repo.lock_write)
 
1319
        # Cleanup
 
1320
        request = smart.repository.SmartServerRepositoryUnlock(backing)
 
1321
        response = request.execute('', nonce)
1187
1322
 
1188
1323
    def test_lock_write_on_locked_repo(self):
1189
1324
        backing = self.get_transport()
1190
1325
        request = smart.repository.SmartServerRepositoryLockWrite(backing)
1191
1326
        repository = self.make_repository('.', format='knit')
1192
 
        repository.lock_write()
 
1327
        repo_token = repository.lock_write()
1193
1328
        repository.leave_lock_in_place()
1194
1329
        repository.unlock()
1195
1330
        response = request.execute('')
1196
1331
        self.assertEqual(
1197
1332
            SmartServerResponse(('LockContention',)), response)
 
1333
        # Cleanup
 
1334
        repository.lock_write(repo_token)
 
1335
        repository.dont_leave_lock_in_place()
 
1336
        repository.unlock()
1198
1337
 
1199
1338
    def test_lock_write_on_readonly_transport(self):
1200
1339
        backing = self.get_readonly_transport()
1386
1525
        for key, item in smart.request.request_handlers.iteritems():
1387
1526
            pass
1388
1527
 
 
1528
    def assertHandlerEqual(self, verb, handler):
 
1529
        self.assertEqual(smart.request.request_handlers.get(verb), handler)
 
1530
 
1389
1531
    def test_registered_methods(self):
1390
1532
        """Test that known methods are registered to the correct object."""
1391
 
        self.assertEqual(
1392
 
            smart.request.request_handlers.get('Branch.get_config_file'),
 
1533
        self.assertHandlerEqual('Branch.get_config_file',
1393
1534
            smart.branch.SmartServerBranchGetConfigFile)
1394
 
        self.assertEqual(
1395
 
            smart.request.request_handlers.get('Branch.get_parent'),
 
1535
        self.assertHandlerEqual('Branch.get_parent',
1396
1536
            smart.branch.SmartServerBranchGetParent)
1397
 
        self.assertEqual(
1398
 
            smart.request.request_handlers.get('Branch.get_tags_bytes'),
 
1537
        self.assertHandlerEqual('Branch.get_tags_bytes',
1399
1538
            smart.branch.SmartServerBranchGetTagsBytes)
1400
 
        self.assertEqual(
1401
 
            smart.request.request_handlers.get('Branch.lock_write'),
 
1539
        self.assertHandlerEqual('Branch.lock_write',
1402
1540
            smart.branch.SmartServerBranchRequestLockWrite)
1403
 
        self.assertEqual(
1404
 
            smart.request.request_handlers.get('Branch.last_revision_info'),
 
1541
        self.assertHandlerEqual('Branch.last_revision_info',
1405
1542
            smart.branch.SmartServerBranchRequestLastRevisionInfo)
1406
 
        self.assertEqual(
1407
 
            smart.request.request_handlers.get('Branch.revision_history'),
 
1543
        self.assertHandlerEqual('Branch.revision_history',
1408
1544
            smart.branch.SmartServerRequestRevisionHistory)
1409
 
        self.assertEqual(
1410
 
            smart.request.request_handlers.get('Branch.set_config_option'),
 
1545
        self.assertHandlerEqual('Branch.set_config_option',
1411
1546
            smart.branch.SmartServerBranchRequestSetConfigOption)
1412
 
        self.assertEqual(
1413
 
            smart.request.request_handlers.get('Branch.set_last_revision'),
 
1547
        self.assertHandlerEqual('Branch.set_last_revision',
1414
1548
            smart.branch.SmartServerBranchRequestSetLastRevision)
1415
 
        self.assertEqual(
1416
 
            smart.request.request_handlers.get('Branch.set_last_revision_info'),
 
1549
        self.assertHandlerEqual('Branch.set_last_revision_info',
1417
1550
            smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
1418
 
        self.assertEqual(
1419
 
            smart.request.request_handlers.get('Branch.unlock'),
 
1551
        self.assertHandlerEqual('Branch.set_last_revision_ex',
 
1552
            smart.branch.SmartServerBranchRequestSetLastRevisionEx)
 
1553
        self.assertHandlerEqual('Branch.set_parent_location',
 
1554
            smart.branch.SmartServerBranchRequestSetParentLocation)
 
1555
        self.assertHandlerEqual('Branch.unlock',
1420
1556
            smart.branch.SmartServerBranchRequestUnlock)
1421
 
        self.assertEqual(
1422
 
            smart.request.request_handlers.get('BzrDir.find_repository'),
 
1557
        self.assertHandlerEqual('BzrDir.find_repository',
1423
1558
            smart.bzrdir.SmartServerRequestFindRepositoryV1)
1424
 
        self.assertEqual(
1425
 
            smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
 
1559
        self.assertHandlerEqual('BzrDir.find_repositoryV2',
1426
1560
            smart.bzrdir.SmartServerRequestFindRepositoryV2)
1427
 
        self.assertEqual(
1428
 
            smart.request.request_handlers.get('BzrDirFormat.initialize'),
 
1561
        self.assertHandlerEqual('BzrDirFormat.initialize',
1429
1562
            smart.bzrdir.SmartServerRequestInitializeBzrDir)
1430
 
        self.assertEqual(
1431
 
            smart.request.request_handlers.get('BzrDir.cloning_metadir'),
 
1563
        self.assertHandlerEqual('BzrDirFormat.initialize_ex',
 
1564
            smart.bzrdir.SmartServerRequestBzrDirInitializeEx)
 
1565
        self.assertHandlerEqual('BzrDir.cloning_metadir',
1432
1566
            smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1433
 
        self.assertEqual(
1434
 
            smart.request.request_handlers.get('BzrDir.open_branch'),
 
1567
        self.assertHandlerEqual('BzrDir.get_config_file',
 
1568
            smart.bzrdir.SmartServerBzrDirRequestConfigFile)
 
1569
        self.assertHandlerEqual('BzrDir.open_branch',
1435
1570
            smart.bzrdir.SmartServerRequestOpenBranch)
1436
 
        self.assertEqual(
1437
 
            smart.request.request_handlers.get('BzrDir.open_branchV2'),
 
1571
        self.assertHandlerEqual('BzrDir.open_branchV2',
1438
1572
            smart.bzrdir.SmartServerRequestOpenBranchV2)
1439
 
        self.assertEqual(
1440
 
            smart.request.request_handlers.get('PackRepository.autopack'),
 
1573
        self.assertHandlerEqual('PackRepository.autopack',
1441
1574
            smart.packrepository.SmartServerPackRepositoryAutopack)
1442
 
        self.assertEqual(
1443
 
            smart.request.request_handlers.get('Repository.gather_stats'),
 
1575
        self.assertHandlerEqual('Repository.gather_stats',
1444
1576
            smart.repository.SmartServerRepositoryGatherStats)
1445
 
        self.assertEqual(
1446
 
            smart.request.request_handlers.get('Repository.get_parent_map'),
 
1577
        self.assertHandlerEqual('Repository.get_parent_map',
1447
1578
            smart.repository.SmartServerRepositoryGetParentMap)
1448
 
        self.assertEqual(
1449
 
            smart.request.request_handlers.get(
1450
 
                'Repository.get_revision_graph'),
 
1579
        self.assertHandlerEqual('Repository.get_revision_graph',
1451
1580
            smart.repository.SmartServerRepositoryGetRevisionGraph)
1452
 
        self.assertEqual(
1453
 
            smart.request.request_handlers.get('Repository.get_stream'),
 
1581
        self.assertHandlerEqual('Repository.get_stream',
1454
1582
            smart.repository.SmartServerRepositoryGetStream)
1455
 
        self.assertEqual(
1456
 
            smart.request.request_handlers.get('Repository.has_revision'),
 
1583
        self.assertHandlerEqual('Repository.has_revision',
1457
1584
            smart.repository.SmartServerRequestHasRevision)
1458
 
        self.assertEqual(
1459
 
            smart.request.request_handlers.get('Repository.insert_stream'),
 
1585
        self.assertHandlerEqual('Repository.insert_stream',
1460
1586
            smart.repository.SmartServerRepositoryInsertStream)
1461
 
        self.assertEqual(
1462
 
            smart.request.request_handlers.get('Repository.insert_stream_locked'),
 
1587
        self.assertHandlerEqual('Repository.insert_stream_locked',
1463
1588
            smart.repository.SmartServerRepositoryInsertStreamLocked)
1464
 
        self.assertEqual(
1465
 
            smart.request.request_handlers.get('Repository.is_shared'),
 
1589
        self.assertHandlerEqual('Repository.is_shared',
1466
1590
            smart.repository.SmartServerRepositoryIsShared)
1467
 
        self.assertEqual(
1468
 
            smart.request.request_handlers.get('Repository.lock_write'),
 
1591
        self.assertHandlerEqual('Repository.lock_write',
1469
1592
            smart.repository.SmartServerRepositoryLockWrite)
1470
 
        self.assertEqual(
1471
 
            smart.request.request_handlers.get('Repository.tarball'),
 
1593
        self.assertHandlerEqual('Repository.tarball',
1472
1594
            smart.repository.SmartServerRepositoryTarball)
1473
 
        self.assertEqual(
1474
 
            smart.request.request_handlers.get('Repository.unlock'),
 
1595
        self.assertHandlerEqual('Repository.unlock',
1475
1596
            smart.repository.SmartServerRepositoryUnlock)
1476
 
        self.assertEqual(
1477
 
            smart.request.request_handlers.get('Transport.is_readonly'),
 
1597
        self.assertHandlerEqual('Transport.is_readonly',
1478
1598
            smart.request.SmartServerIsReadonly)