330
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,
365
'False', '', '', '')),
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')
333
393
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
335
395
def test_no_branch(self):
485
565
request.execute(''))
488
class SetLastRevisionTestBase(tests.TestCaseWithMemoryTransport):
568
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
570
def get_lock_tokens(self, branch):
571
branch_token = branch.lock_write()
572
repo_token = branch.repository.lock_write()
573
branch.repository.unlock()
574
return branch_token, repo_token
577
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
579
def test_value_name(self):
580
branch = self.make_branch('.')
581
request = smart.branch.SmartServerBranchRequestSetConfigOption(
582
branch.bzrdir.root_transport)
583
branch_token, repo_token = self.get_lock_tokens(branch)
584
config = branch._get_config()
585
result = request.execute('', branch_token, repo_token, 'bar', 'foo',
587
self.assertEqual(SuccessfulSmartServerResponse(()), result)
588
self.assertEqual('bar', config.get_option('foo'))
592
def test_value_name_section(self):
593
branch = self.make_branch('.')
594
request = smart.branch.SmartServerBranchRequestSetConfigOption(
595
branch.bzrdir.root_transport)
596
branch_token, repo_token = self.get_lock_tokens(branch)
597
config = branch._get_config()
598
result = request.execute('', branch_token, repo_token, 'bar', 'foo',
600
self.assertEqual(SuccessfulSmartServerResponse(()), result)
601
self.assertEqual('bar', config.get_option('foo', 'gam'))
606
class SetLastRevisionTestBase(TestLockedBranch):
489
607
"""Base test case for verbs that implement set_last_revision."""
839
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
841
def test_set_parent_none(self):
842
branch = self.make_branch('base', format="1.9")
844
branch._set_parent_location('foo')
846
request = smart.branch.SmartServerBranchRequestSetParentLocation(
847
self.get_transport())
848
branch_token = branch.lock_write()
849
repo_token = branch.repository.lock_write()
851
response = request.execute('base', branch_token, repo_token, '')
853
branch.repository.unlock()
855
self.assertEqual(SuccessfulSmartServerResponse(()), response)
856
self.assertEqual(None, branch.get_parent())
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()
865
response = request.execute('base', branch_token, repo_token,
868
branch.repository.unlock()
870
self.assertEqual(SuccessfulSmartServerResponse(()), response)
871
self.assertEqual('http://bar/', branch.get_parent())
725
874
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
726
875
# Only called when the branch format and tags match [yay factory
727
876
# methods] so only need to test straight forward cases.
811
974
branch_token+'xxx', repo_token)
812
975
self.assertEqual(
813
976
SmartServerResponse(('TokenMismatch',)), response)
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()
815
985
def test_lock_write_on_locked_repo(self):
816
986
backing = self.get_transport()
817
987
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
818
988
branch = self.make_branch('.', format='knit')
819
branch.repository.lock_write()
820
branch.repository.leave_lock_in_place()
821
branch.repository.unlock()
989
repo = branch.repository
990
repo_token = repo.lock_write()
991
repo.leave_lock_in_place()
822
993
response = request.execute('')
823
994
self.assertEqual(
824
995
SmartServerResponse(('LockContention',)), response)
997
repo.lock_write(repo_token)
998
repo.dont_leave_lock_in_place()
826
1001
def test_lock_write_on_readonly_transport(self):
827
1002
backing = self.get_readonly_transport()
1149
1344
self.assertEqual('LockFailed', response.args[0])
1347
class TestInsertStreamBase(tests.TestCaseWithMemoryTransport):
1349
def make_empty_byte_stream(self, repo):
1350
byte_stream = smart.repository._stream_to_byte_stream([], repo._format)
1351
return ''.join(byte_stream)
1354
class TestSmartServerRepositoryInsertStream(TestInsertStreamBase):
1356
def test_insert_stream_empty(self):
1357
backing = self.get_transport()
1358
request = smart.repository.SmartServerRepositoryInsertStream(backing)
1359
repository = self.make_repository('.')
1360
response = request.execute('', '')
1361
self.assertEqual(None, response)
1362
response = request.do_chunk(self.make_empty_byte_stream(repository))
1363
self.assertEqual(None, response)
1364
response = request.do_end()
1365
self.assertEqual(SmartServerResponse(('ok', )), response)
1368
class TestSmartServerRepositoryInsertStreamLocked(TestInsertStreamBase):
1370
def test_insert_stream_empty(self):
1371
backing = self.get_transport()
1372
request = smart.repository.SmartServerRepositoryInsertStreamLocked(
1374
repository = self.make_repository('.', format='knit')
1375
lock_token = repository.lock_write()
1376
response = request.execute('', '', lock_token)
1377
self.assertEqual(None, response)
1378
response = request.do_chunk(self.make_empty_byte_stream(repository))
1379
self.assertEqual(None, response)
1380
response = request.do_end()
1381
self.assertEqual(SmartServerResponse(('ok', )), response)
1384
def test_insert_stream_with_wrong_lock_token(self):
1385
backing = self.get_transport()
1386
request = smart.repository.SmartServerRepositoryInsertStreamLocked(
1388
repository = self.make_repository('.', format='knit')
1389
lock_token = repository.lock_write()
1391
errors.TokenMismatch, request.execute, '', '', 'wrong-token')
1152
1395
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
1154
1397
def setUp(self):
1278
1525
for key, item in smart.request.request_handlers.iteritems():
1528
def assertHandlerEqual(self, verb, handler):
1529
self.assertEqual(smart.request.request_handlers.get(verb), handler)
1281
1531
def test_registered_methods(self):
1282
1532
"""Test that known methods are registered to the correct object."""
1284
smart.request.request_handlers.get('Branch.get_config_file'),
1533
self.assertHandlerEqual('Branch.get_config_file',
1285
1534
smart.branch.SmartServerBranchGetConfigFile)
1287
smart.request.request_handlers.get('Branch.get_parent'),
1535
self.assertHandlerEqual('Branch.get_parent',
1288
1536
smart.branch.SmartServerBranchGetParent)
1290
smart.request.request_handlers.get('Branch.get_tags_bytes'),
1537
self.assertHandlerEqual('Branch.get_tags_bytes',
1291
1538
smart.branch.SmartServerBranchGetTagsBytes)
1293
smart.request.request_handlers.get('Branch.lock_write'),
1539
self.assertHandlerEqual('Branch.lock_write',
1294
1540
smart.branch.SmartServerBranchRequestLockWrite)
1296
smart.request.request_handlers.get('Branch.last_revision_info'),
1541
self.assertHandlerEqual('Branch.last_revision_info',
1297
1542
smart.branch.SmartServerBranchRequestLastRevisionInfo)
1299
smart.request.request_handlers.get('Branch.revision_history'),
1543
self.assertHandlerEqual('Branch.revision_history',
1300
1544
smart.branch.SmartServerRequestRevisionHistory)
1302
smart.request.request_handlers.get('Branch.set_last_revision'),
1545
self.assertHandlerEqual('Branch.set_config_option',
1546
smart.branch.SmartServerBranchRequestSetConfigOption)
1547
self.assertHandlerEqual('Branch.set_last_revision',
1303
1548
smart.branch.SmartServerBranchRequestSetLastRevision)
1305
smart.request.request_handlers.get('Branch.set_last_revision_info'),
1549
self.assertHandlerEqual('Branch.set_last_revision_info',
1306
1550
smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
1308
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',
1309
1556
smart.branch.SmartServerBranchRequestUnlock)
1311
smart.request.request_handlers.get('BzrDir.find_repository'),
1557
self.assertHandlerEqual('BzrDir.find_repository',
1312
1558
smart.bzrdir.SmartServerRequestFindRepositoryV1)
1314
smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
1559
self.assertHandlerEqual('BzrDir.find_repositoryV2',
1315
1560
smart.bzrdir.SmartServerRequestFindRepositoryV2)
1317
smart.request.request_handlers.get('BzrDirFormat.initialize'),
1561
self.assertHandlerEqual('BzrDirFormat.initialize',
1318
1562
smart.bzrdir.SmartServerRequestInitializeBzrDir)
1320
smart.request.request_handlers.get('BzrDir.cloning_metadir'),
1563
self.assertHandlerEqual('BzrDirFormat.initialize_ex',
1564
smart.bzrdir.SmartServerRequestBzrDirInitializeEx)
1565
self.assertHandlerEqual('BzrDir.cloning_metadir',
1321
1566
smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1323
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',
1324
1570
smart.bzrdir.SmartServerRequestOpenBranch)
1326
smart.request.request_handlers.get('BzrDir.open_branchV2'),
1571
self.assertHandlerEqual('BzrDir.open_branchV2',
1327
1572
smart.bzrdir.SmartServerRequestOpenBranchV2)
1329
smart.request.request_handlers.get('PackRepository.autopack'),
1573
self.assertHandlerEqual('PackRepository.autopack',
1330
1574
smart.packrepository.SmartServerPackRepositoryAutopack)
1332
smart.request.request_handlers.get('Repository.gather_stats'),
1575
self.assertHandlerEqual('Repository.gather_stats',
1333
1576
smart.repository.SmartServerRepositoryGatherStats)
1335
smart.request.request_handlers.get('Repository.get_parent_map'),
1577
self.assertHandlerEqual('Repository.get_parent_map',
1336
1578
smart.repository.SmartServerRepositoryGetParentMap)
1338
smart.request.request_handlers.get(
1339
'Repository.get_revision_graph'),
1579
self.assertHandlerEqual('Repository.get_revision_graph',
1340
1580
smart.repository.SmartServerRepositoryGetRevisionGraph)
1342
smart.request.request_handlers.get('Repository.has_revision'),
1581
self.assertHandlerEqual('Repository.get_stream',
1582
smart.repository.SmartServerRepositoryGetStream)
1583
self.assertHandlerEqual('Repository.has_revision',
1343
1584
smart.repository.SmartServerRequestHasRevision)
1345
smart.request.request_handlers.get('Repository.is_shared'),
1585
self.assertHandlerEqual('Repository.insert_stream',
1586
smart.repository.SmartServerRepositoryInsertStream)
1587
self.assertHandlerEqual('Repository.insert_stream_locked',
1588
smart.repository.SmartServerRepositoryInsertStreamLocked)
1589
self.assertHandlerEqual('Repository.is_shared',
1346
1590
smart.repository.SmartServerRepositoryIsShared)
1348
smart.request.request_handlers.get('Repository.lock_write'),
1591
self.assertHandlerEqual('Repository.lock_write',
1349
1592
smart.repository.SmartServerRepositoryLockWrite)
1351
smart.request.request_handlers.get('Repository.get_stream'),
1352
smart.repository.SmartServerRepositoryGetStream)
1354
smart.request.request_handlers.get('Repository.tarball'),
1593
self.assertHandlerEqual('Repository.tarball',
1355
1594
smart.repository.SmartServerRepositoryTarball)
1357
smart.request.request_handlers.get('Repository.unlock'),
1595
self.assertHandlerEqual('Repository.unlock',
1358
1596
smart.repository.SmartServerRepositoryUnlock)
1360
smart.request.request_handlers.get('Transport.is_readonly'),
1597
self.assertHandlerEqual('Transport.is_readonly',
1361
1598
smart.request.SmartServerIsReadonly)