~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-29 05:53:21 UTC
  • mfrom: (4311 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4312.
  • Revision ID: tanner@real-time.com-20090429055321-v2s5l1mgki9f6cgn
[merge] 1.14 back to trunk

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):
769
832
            response)
770
833
 
771
834
 
 
835
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
 
836
 
 
837
    def test_set_parent_none(self):
 
838
        branch = self.make_branch('base', format="1.9")
 
839
        branch.lock_write()
 
840
        branch._set_parent_location('foo')
 
841
        branch.unlock()
 
842
        request = smart.branch.SmartServerBranchRequestSetParentLocation(
 
843
            self.get_transport())
 
844
        branch_token = branch.lock_write()
 
845
        repo_token = branch.repository.lock_write()
 
846
        try:
 
847
            response = request.execute('base', branch_token, repo_token, '')
 
848
        finally:
 
849
            branch.repository.unlock()
 
850
            branch.unlock()
 
851
        self.assertEqual(SuccessfulSmartServerResponse(()), response)
 
852
        self.assertEqual(None, branch.get_parent())
 
853
 
 
854
    def test_set_parent_something(self):
 
855
        branch = self.make_branch('base', format="1.9")
 
856
        request = smart.branch.SmartServerBranchRequestSetParentLocation(
 
857
            self.get_transport())
 
858
        branch_token = branch.lock_write()
 
859
        repo_token = branch.repository.lock_write()
 
860
        try:
 
861
            response = request.execute('base', branch_token, repo_token,
 
862
            'http://bar/')
 
863
        finally:
 
864
            branch.repository.unlock()
 
865
            branch.unlock()
 
866
        self.assertEqual(SuccessfulSmartServerResponse(()), response)
 
867
        self.assertEqual('http://bar/', branch.get_parent())
 
868
 
 
869
 
772
870
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
773
871
# Only called when the branch format and tags match [yay factory
774
872
# methods] so only need to test straight forward cases.
1386
1484
        for key, item in smart.request.request_handlers.iteritems():
1387
1485
            pass
1388
1486
 
 
1487
    def assertHandlerEqual(self, verb, handler):
 
1488
        self.assertEqual(smart.request.request_handlers.get(verb), handler)
 
1489
 
1389
1490
    def test_registered_methods(self):
1390
1491
        """Test that known methods are registered to the correct object."""
1391
 
        self.assertEqual(
1392
 
            smart.request.request_handlers.get('Branch.get_config_file'),
 
1492
        self.assertHandlerEqual('Branch.get_config_file',
1393
1493
            smart.branch.SmartServerBranchGetConfigFile)
1394
 
        self.assertEqual(
1395
 
            smart.request.request_handlers.get('Branch.get_parent'),
 
1494
        self.assertHandlerEqual('Branch.get_parent',
1396
1495
            smart.branch.SmartServerBranchGetParent)
1397
 
        self.assertEqual(
1398
 
            smart.request.request_handlers.get('Branch.get_tags_bytes'),
 
1496
        self.assertHandlerEqual('Branch.get_tags_bytes',
1399
1497
            smart.branch.SmartServerBranchGetTagsBytes)
1400
 
        self.assertEqual(
1401
 
            smart.request.request_handlers.get('Branch.lock_write'),
 
1498
        self.assertHandlerEqual('Branch.lock_write',
1402
1499
            smart.branch.SmartServerBranchRequestLockWrite)
1403
 
        self.assertEqual(
1404
 
            smart.request.request_handlers.get('Branch.last_revision_info'),
 
1500
        self.assertHandlerEqual('Branch.last_revision_info',
1405
1501
            smart.branch.SmartServerBranchRequestLastRevisionInfo)
1406
 
        self.assertEqual(
1407
 
            smart.request.request_handlers.get('Branch.revision_history'),
 
1502
        self.assertHandlerEqual('Branch.revision_history',
1408
1503
            smart.branch.SmartServerRequestRevisionHistory)
1409
 
        self.assertEqual(
1410
 
            smart.request.request_handlers.get('Branch.set_config_option'),
 
1504
        self.assertHandlerEqual('Branch.set_config_option',
1411
1505
            smart.branch.SmartServerBranchRequestSetConfigOption)
1412
 
        self.assertEqual(
1413
 
            smart.request.request_handlers.get('Branch.set_last_revision'),
 
1506
        self.assertHandlerEqual('Branch.set_last_revision',
1414
1507
            smart.branch.SmartServerBranchRequestSetLastRevision)
1415
 
        self.assertEqual(
1416
 
            smart.request.request_handlers.get('Branch.set_last_revision_info'),
 
1508
        self.assertHandlerEqual('Branch.set_last_revision_info',
1417
1509
            smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
1418
 
        self.assertEqual(
1419
 
            smart.request.request_handlers.get('Branch.unlock'),
 
1510
        self.assertHandlerEqual('Branch.set_last_revision_ex',
 
1511
            smart.branch.SmartServerBranchRequestSetLastRevisionEx)
 
1512
        self.assertHandlerEqual('Branch.set_parent_location',
 
1513
            smart.branch.SmartServerBranchRequestSetParentLocation)
 
1514
        self.assertHandlerEqual('Branch.unlock',
1420
1515
            smart.branch.SmartServerBranchRequestUnlock)
1421
 
        self.assertEqual(
1422
 
            smart.request.request_handlers.get('BzrDir.find_repository'),
 
1516
        self.assertHandlerEqual('BzrDir.find_repository',
1423
1517
            smart.bzrdir.SmartServerRequestFindRepositoryV1)
1424
 
        self.assertEqual(
1425
 
            smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
 
1518
        self.assertHandlerEqual('BzrDir.find_repositoryV2',
1426
1519
            smart.bzrdir.SmartServerRequestFindRepositoryV2)
1427
 
        self.assertEqual(
1428
 
            smart.request.request_handlers.get('BzrDirFormat.initialize'),
 
1520
        self.assertHandlerEqual('BzrDirFormat.initialize',
1429
1521
            smart.bzrdir.SmartServerRequestInitializeBzrDir)
1430
 
        self.assertEqual(
1431
 
            smart.request.request_handlers.get('BzrDir.cloning_metadir'),
 
1522
        self.assertHandlerEqual('BzrDirFormat.initialize_ex',
 
1523
            smart.bzrdir.SmartServerRequestBzrDirInitializeEx)
 
1524
        self.assertHandlerEqual('BzrDir.cloning_metadir',
1432
1525
            smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1433
 
        self.assertEqual(
1434
 
            smart.request.request_handlers.get('BzrDir.open_branch'),
 
1526
        self.assertHandlerEqual('BzrDir.get_config_file',
 
1527
            smart.bzrdir.SmartServerBzrDirRequestConfigFile)
 
1528
        self.assertHandlerEqual('BzrDir.open_branch',
1435
1529
            smart.bzrdir.SmartServerRequestOpenBranch)
1436
 
        self.assertEqual(
1437
 
            smart.request.request_handlers.get('BzrDir.open_branchV2'),
 
1530
        self.assertHandlerEqual('BzrDir.open_branchV2',
1438
1531
            smart.bzrdir.SmartServerRequestOpenBranchV2)
1439
 
        self.assertEqual(
1440
 
            smart.request.request_handlers.get('PackRepository.autopack'),
 
1532
        self.assertHandlerEqual('PackRepository.autopack',
1441
1533
            smart.packrepository.SmartServerPackRepositoryAutopack)
1442
 
        self.assertEqual(
1443
 
            smart.request.request_handlers.get('Repository.gather_stats'),
 
1534
        self.assertHandlerEqual('Repository.gather_stats',
1444
1535
            smart.repository.SmartServerRepositoryGatherStats)
1445
 
        self.assertEqual(
1446
 
            smart.request.request_handlers.get('Repository.get_parent_map'),
 
1536
        self.assertHandlerEqual('Repository.get_parent_map',
1447
1537
            smart.repository.SmartServerRepositoryGetParentMap)
1448
 
        self.assertEqual(
1449
 
            smart.request.request_handlers.get(
1450
 
                'Repository.get_revision_graph'),
 
1538
        self.assertHandlerEqual('Repository.get_revision_graph',
1451
1539
            smart.repository.SmartServerRepositoryGetRevisionGraph)
1452
 
        self.assertEqual(
1453
 
            smart.request.request_handlers.get('Repository.get_stream'),
 
1540
        self.assertHandlerEqual('Repository.get_stream',
1454
1541
            smart.repository.SmartServerRepositoryGetStream)
1455
 
        self.assertEqual(
1456
 
            smart.request.request_handlers.get('Repository.has_revision'),
 
1542
        self.assertHandlerEqual('Repository.has_revision',
1457
1543
            smart.repository.SmartServerRequestHasRevision)
1458
 
        self.assertEqual(
1459
 
            smart.request.request_handlers.get('Repository.insert_stream'),
 
1544
        self.assertHandlerEqual('Repository.insert_stream',
1460
1545
            smart.repository.SmartServerRepositoryInsertStream)
1461
 
        self.assertEqual(
1462
 
            smart.request.request_handlers.get('Repository.insert_stream_locked'),
 
1546
        self.assertHandlerEqual('Repository.insert_stream_locked',
1463
1547
            smart.repository.SmartServerRepositoryInsertStreamLocked)
1464
 
        self.assertEqual(
1465
 
            smart.request.request_handlers.get('Repository.is_shared'),
 
1548
        self.assertHandlerEqual('Repository.is_shared',
1466
1549
            smart.repository.SmartServerRepositoryIsShared)
1467
 
        self.assertEqual(
1468
 
            smart.request.request_handlers.get('Repository.lock_write'),
 
1550
        self.assertHandlerEqual('Repository.lock_write',
1469
1551
            smart.repository.SmartServerRepositoryLockWrite)
1470
 
        self.assertEqual(
1471
 
            smart.request.request_handlers.get('Repository.tarball'),
 
1552
        self.assertHandlerEqual('Repository.tarball',
1472
1553
            smart.repository.SmartServerRepositoryTarball)
1473
 
        self.assertEqual(
1474
 
            smart.request.request_handlers.get('Repository.unlock'),
 
1554
        self.assertHandlerEqual('Repository.unlock',
1475
1555
            smart.repository.SmartServerRepositoryUnlock)
1476
 
        self.assertEqual(
1477
 
            smart.request.request_handlers.get('Transport.is_readonly'),
 
1556
        self.assertHandlerEqual('Transport.is_readonly',
1478
1557
            smart.request.SmartServerIsReadonly)