327
350
request.execute, 'subdir')
353
class TestSmartServerRequestBzrDirInitializeEx(tests.TestCaseWithMemoryTransport):
354
"""Basic tests for BzrDir.initialize_ex in the smart server.
356
The main unit tests in test_bzrdir exercise the API comprehensively.
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,
366
request.execute(name, '', 'True', 'False', 'False', '', '', '', '',
368
made_dir = bzrdir.BzrDir.open_from_transport(backing)
369
# no branch, tree or repository is expected with the current
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)
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')
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')
330
393
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
332
395
def test_no_branch(self):
835
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
837
def test_set_parent_none(self):
838
branch = self.make_branch('base', format="1.9")
840
branch._set_parent_location('foo')
842
request = smart.branch.SmartServerBranchRequestSetParentLocation(
843
self.get_transport())
844
branch_token = branch.lock_write()
845
repo_token = branch.repository.lock_write()
847
response = request.execute('base', branch_token, repo_token, '')
849
branch.repository.unlock()
851
self.assertEqual(SuccessfulSmartServerResponse(()), response)
852
self.assertEqual(None, branch.get_parent())
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()
861
response = request.execute('base', branch_token, repo_token,
864
branch.repository.unlock()
866
self.assertEqual(SuccessfulSmartServerResponse(()), response)
867
self.assertEqual('http://bar/', branch.get_parent())
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():
1487
def assertHandlerEqual(self, verb, handler):
1488
self.assertEqual(smart.request.request_handlers.get(verb), handler)
1389
1490
def test_registered_methods(self):
1390
1491
"""Test that known methods are registered to the correct object."""
1392
smart.request.request_handlers.get('Branch.get_config_file'),
1492
self.assertHandlerEqual('Branch.get_config_file',
1393
1493
smart.branch.SmartServerBranchGetConfigFile)
1395
smart.request.request_handlers.get('Branch.get_parent'),
1494
self.assertHandlerEqual('Branch.get_parent',
1396
1495
smart.branch.SmartServerBranchGetParent)
1398
smart.request.request_handlers.get('Branch.get_tags_bytes'),
1496
self.assertHandlerEqual('Branch.get_tags_bytes',
1399
1497
smart.branch.SmartServerBranchGetTagsBytes)
1401
smart.request.request_handlers.get('Branch.lock_write'),
1498
self.assertHandlerEqual('Branch.lock_write',
1402
1499
smart.branch.SmartServerBranchRequestLockWrite)
1404
smart.request.request_handlers.get('Branch.last_revision_info'),
1500
self.assertHandlerEqual('Branch.last_revision_info',
1405
1501
smart.branch.SmartServerBranchRequestLastRevisionInfo)
1407
smart.request.request_handlers.get('Branch.revision_history'),
1502
self.assertHandlerEqual('Branch.revision_history',
1408
1503
smart.branch.SmartServerRequestRevisionHistory)
1410
smart.request.request_handlers.get('Branch.set_config_option'),
1504
self.assertHandlerEqual('Branch.set_config_option',
1411
1505
smart.branch.SmartServerBranchRequestSetConfigOption)
1413
smart.request.request_handlers.get('Branch.set_last_revision'),
1506
self.assertHandlerEqual('Branch.set_last_revision',
1414
1507
smart.branch.SmartServerBranchRequestSetLastRevision)
1416
smart.request.request_handlers.get('Branch.set_last_revision_info'),
1508
self.assertHandlerEqual('Branch.set_last_revision_info',
1417
1509
smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
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)
1422
smart.request.request_handlers.get('BzrDir.find_repository'),
1516
self.assertHandlerEqual('BzrDir.find_repository',
1423
1517
smart.bzrdir.SmartServerRequestFindRepositoryV1)
1425
smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
1518
self.assertHandlerEqual('BzrDir.find_repositoryV2',
1426
1519
smart.bzrdir.SmartServerRequestFindRepositoryV2)
1428
smart.request.request_handlers.get('BzrDirFormat.initialize'),
1520
self.assertHandlerEqual('BzrDirFormat.initialize',
1429
1521
smart.bzrdir.SmartServerRequestInitializeBzrDir)
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)
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)
1437
smart.request.request_handlers.get('BzrDir.open_branchV2'),
1530
self.assertHandlerEqual('BzrDir.open_branchV2',
1438
1531
smart.bzrdir.SmartServerRequestOpenBranchV2)
1440
smart.request.request_handlers.get('PackRepository.autopack'),
1532
self.assertHandlerEqual('PackRepository.autopack',
1441
1533
smart.packrepository.SmartServerPackRepositoryAutopack)
1443
smart.request.request_handlers.get('Repository.gather_stats'),
1534
self.assertHandlerEqual('Repository.gather_stats',
1444
1535
smart.repository.SmartServerRepositoryGatherStats)
1446
smart.request.request_handlers.get('Repository.get_parent_map'),
1536
self.assertHandlerEqual('Repository.get_parent_map',
1447
1537
smart.repository.SmartServerRepositoryGetParentMap)
1449
smart.request.request_handlers.get(
1450
'Repository.get_revision_graph'),
1538
self.assertHandlerEqual('Repository.get_revision_graph',
1451
1539
smart.repository.SmartServerRepositoryGetRevisionGraph)
1453
smart.request.request_handlers.get('Repository.get_stream'),
1540
self.assertHandlerEqual('Repository.get_stream',
1454
1541
smart.repository.SmartServerRepositoryGetStream)
1456
smart.request.request_handlers.get('Repository.has_revision'),
1542
self.assertHandlerEqual('Repository.has_revision',
1457
1543
smart.repository.SmartServerRequestHasRevision)
1459
smart.request.request_handlers.get('Repository.insert_stream'),
1544
self.assertHandlerEqual('Repository.insert_stream',
1460
1545
smart.repository.SmartServerRepositoryInsertStream)
1462
smart.request.request_handlers.get('Repository.insert_stream_locked'),
1546
self.assertHandlerEqual('Repository.insert_stream_locked',
1463
1547
smart.repository.SmartServerRepositoryInsertStreamLocked)
1465
smart.request.request_handlers.get('Repository.is_shared'),
1548
self.assertHandlerEqual('Repository.is_shared',
1466
1549
smart.repository.SmartServerRepositoryIsShared)
1468
smart.request.request_handlers.get('Repository.lock_write'),
1550
self.assertHandlerEqual('Repository.lock_write',
1469
1551
smart.repository.SmartServerRepositoryLockWrite)
1471
smart.request.request_handlers.get('Repository.tarball'),
1552
self.assertHandlerEqual('Repository.tarball',
1472
1553
smart.repository.SmartServerRepositoryTarball)
1474
smart.request.request_handlers.get('Repository.unlock'),
1554
self.assertHandlerEqual('Repository.unlock',
1475
1555
smart.repository.SmartServerRepositoryUnlock)
1477
smart.request.request_handlers.get('Transport.is_readonly'),
1556
self.assertHandlerEqual('Transport.is_readonly',
1478
1557
smart.request.SmartServerIsReadonly)