221
226
self.assertEqual(expected, request.execute('', 'False'))
229
class TestSmartServerBzrDirRequestCloningMetaDir(
230
tests.TestCaseWithMemoryTransport):
231
"""Tests for BzrDir.checkout_metadir."""
233
def test_checkout_metadir(self):
234
backing = self.get_transport()
235
request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
237
branch = self.make_branch('.', format='2a')
238
response = request.execute('')
240
smart_req.SmartServerResponse(
241
('Bazaar-NG meta directory, format 1\n',
242
'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
243
'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
247
class TestSmartServerBzrDirRequestDestroyBranch(
248
tests.TestCaseWithMemoryTransport):
249
"""Tests for BzrDir.destroy_branch."""
251
def test_destroy_branch_default(self):
252
"""The default branch can be removed."""
253
backing = self.get_transport()
254
dir = self.make_branch('.').bzrdir
255
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
256
request = request_class(backing)
257
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
258
self.assertEqual(expected, request.execute('', None))
260
def test_destroy_branch_named(self):
261
"""A named branch can be removed."""
262
backing = self.get_transport()
263
dir = self.make_repository('.', format="development-colo").bzrdir
264
dir.create_branch(name="branchname")
265
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
266
request = request_class(backing)
267
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
268
self.assertEqual(expected, request.execute('', "branchname"))
270
def test_destroy_branch_missing(self):
271
"""An error is raised if the branch didn't exist."""
272
backing = self.get_transport()
273
dir = self.make_bzrdir('.', format="development-colo")
274
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
275
request = request_class(backing)
276
expected = smart_req.FailedSmartServerResponse(('nobranch',), None)
277
self.assertEqual(expected, request.execute('', "branchname"))
280
class TestSmartServerBzrDirRequestHasWorkingTree(
281
tests.TestCaseWithTransport):
282
"""Tests for BzrDir.has_workingtree."""
284
def test_has_workingtree_yes(self):
285
"""A working tree is present."""
286
backing = self.get_transport()
287
dir = self.make_branch_and_tree('.').bzrdir
288
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
289
request = request_class(backing)
290
expected = smart_req.SuccessfulSmartServerResponse(('yes',))
291
self.assertEqual(expected, request.execute(''))
293
def test_has_workingtree_no(self):
294
"""A working tree is missing."""
295
backing = self.get_transport()
296
dir = self.make_bzrdir('.')
297
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
298
request = request_class(backing)
299
expected = smart_req.SuccessfulSmartServerResponse(('no',))
300
self.assertEqual(expected, request.execute(''))
303
class TestSmartServerBzrDirRequestDestroyRepository(
304
tests.TestCaseWithMemoryTransport):
305
"""Tests for BzrDir.destroy_repository."""
307
def test_destroy_repository_default(self):
308
"""The repository can be removed."""
309
backing = self.get_transport()
310
dir = self.make_repository('.').bzrdir
311
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
312
request = request_class(backing)
313
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
314
self.assertEqual(expected, request.execute(''))
316
def test_destroy_repository_missing(self):
317
"""An error is raised if the repository didn't exist."""
318
backing = self.get_transport()
319
dir = self.make_bzrdir('.')
320
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
321
request = request_class(backing)
322
expected = smart_req.FailedSmartServerResponse(
323
('norepository',), None)
324
self.assertEqual(expected, request.execute(''))
224
327
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
225
328
"""Tests for BzrDir.create_repository."""
356
459
self.assertEqual(expected, request.execute(''))
462
class TestSmartServerBzrDirRequestGetBranches(
463
tests.TestCaseWithMemoryTransport):
464
"""Tests for BzrDir.get_branches."""
466
def test_simple(self):
467
backing = self.get_transport()
468
branch = self.make_branch('.')
469
request_class = smart_dir.SmartServerBzrDirRequestGetBranches
470
request = request_class(backing)
471
local_result = bencode.bencode(
472
{"": ("branch", branch._format.network_name())})
473
expected = smart_req.SuccessfulSmartServerResponse(
474
("success", ), local_result)
475
self.assertEqual(expected, request.execute(''))
477
def test_empty(self):
478
backing = self.get_transport()
479
dir = self.make_bzrdir('.')
480
request_class = smart_dir.SmartServerBzrDirRequestGetBranches
481
request = request_class(backing)
482
local_result = bencode.bencode({})
483
expected = smart_req.SuccessfulSmartServerResponse(
484
('success',), local_result)
485
self.assertEqual(expected, request.execute(''))
359
488
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
361
490
def test_empty_dir(self):
735
864
request.execute(''))
867
class TestSmartServerBranchRequestRevisionIdToRevno(
868
tests.TestCaseWithMemoryTransport):
871
backing = self.get_transport()
872
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
874
self.make_branch('.')
875
self.assertEqual(smart_req.SmartServerResponse(('ok', '0')),
876
request.execute('', 'null:'))
878
def test_simple(self):
879
backing = self.get_transport()
880
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
882
tree = self.make_branch_and_memory_tree('.')
885
r1 = tree.commit('1st commit')
888
smart_req.SmartServerResponse(('ok', '1')),
889
request.execute('', r1))
891
def test_not_found(self):
892
backing = self.get_transport()
893
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
895
branch = self.make_branch('.')
897
smart_req.FailedSmartServerResponse(
898
('NoSuchRevision', 'idontexist')),
899
request.execute('', 'idontexist'))
738
902
class TestSmartServerBranchRequestGetConfigFile(
739
903
tests.TestCaseWithMemoryTransport):
769
933
return branch_token, repo_token
936
class TestSmartServerBranchRequestPutConfigFile(TestLockedBranch):
938
def test_with_content(self):
939
backing = self.get_transport()
940
request = smart_branch.SmartServerBranchPutConfigFile(backing)
941
branch = self.make_branch('.')
942
branch_token, repo_token = self.get_lock_tokens(branch)
943
self.assertIs(None, request.execute('', branch_token, repo_token))
945
smart_req.SmartServerResponse(('ok', )),
946
request.do_body('foo bar baz'))
948
branch.control_transport.get_bytes('branch.conf'),
772
953
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
774
955
def test_value_name(self):
1088
1269
self.assertEqual('child-1', self.tree.branch.last_revision())
1272
class TestSmartServerBranchBreakLock(tests.TestCaseWithMemoryTransport):
1274
def test_lock_to_break(self):
1275
base_branch = self.make_branch('base')
1276
request = smart_branch.SmartServerBranchBreakLock(
1277
self.get_transport())
1278
base_branch.lock_write()
1280
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1281
request.execute('base'))
1283
def test_nothing_to_break(self):
1284
base_branch = self.make_branch('base')
1285
request = smart_branch.SmartServerBranchBreakLock(
1286
self.get_transport())
1288
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1289
request.execute('base'))
1091
1292
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
1093
1294
def test_get_parent_none(self):
1275
1476
self.assertEqual('LockFailed', error_name)
1479
class TestSmartServerBranchRequestGetPhysicalLockStatus(TestLockedBranch):
1482
tests.TestCaseWithMemoryTransport.setUp(self)
1484
def test_true(self):
1485
backing = self.get_transport()
1486
request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1488
branch = self.make_branch('.')
1489
branch_token, repo_token = self.get_lock_tokens(branch)
1490
self.assertEquals(True, branch.get_physical_lock_status())
1491
response = request.execute('')
1493
smart_req.SmartServerResponse(('yes',)), response)
1496
def test_false(self):
1497
backing = self.get_transport()
1498
request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1500
branch = self.make_branch('.')
1501
self.assertEquals(False, branch.get_physical_lock_status())
1502
response = request.execute('')
1504
smart_req.SmartServerResponse(('no',)), response)
1278
1507
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
1280
1509
def setUp(self):
1345
1574
request.execute, 'subdir')
1577
class TestSmartServerRepositoryAddSignatureText(tests.TestCaseWithMemoryTransport):
1579
def test_add_text(self):
1580
backing = self.get_transport()
1581
request = smart_repo.SmartServerRepositoryAddSignatureText(backing)
1582
tree = self.make_branch_and_memory_tree('.')
1583
write_token = tree.lock_write()
1584
self.addCleanup(tree.unlock)
1586
tree.commit("Message", rev_id='rev1')
1587
tree.branch.repository.start_write_group()
1588
write_group_tokens = tree.branch.repository.suspend_write_group()
1589
self.assertEqual(None, request.execute('', write_token,
1590
'rev1', *write_group_tokens))
1591
response = request.do_body('somesignature')
1592
self.assertTrue(response.is_successful())
1593
self.assertEqual(response.args[0], 'ok')
1594
write_group_tokens = response.args[1:]
1595
tree.branch.repository.resume_write_group(write_group_tokens)
1596
tree.branch.repository.commit_write_group()
1598
self.assertEqual("somesignature",
1599
tree.branch.repository.get_signature_text("rev1"))
1602
class TestSmartServerRepositoryAllRevisionIds(
1603
tests.TestCaseWithMemoryTransport):
1605
def test_empty(self):
1606
"""An empty body should be returned for an empty repository."""
1607
backing = self.get_transport()
1608
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1609
self.make_repository('.')
1611
smart_req.SuccessfulSmartServerResponse(("ok", ), ""),
1612
request.execute(''))
1614
def test_some_revisions(self):
1615
"""An empty body should be returned for an empty repository."""
1616
backing = self.get_transport()
1617
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1618
tree = self.make_branch_and_memory_tree('.')
1621
tree.commit(rev_id='origineel', message="message")
1622
tree.commit(rev_id='nog-een-revisie', message="message")
1625
smart_req.SuccessfulSmartServerResponse(("ok", ),
1626
"origineel\nnog-een-revisie"),
1627
request.execute(''))
1630
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1632
def test_lock_to_break(self):
1633
backing = self.get_transport()
1634
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1635
tree = self.make_branch_and_memory_tree('.')
1636
tree.branch.repository.lock_write()
1638
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1639
request.execute(''))
1641
def test_nothing_to_break(self):
1642
backing = self.get_transport()
1643
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1644
tree = self.make_branch_and_memory_tree('.')
1646
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1647
request.execute(''))
1348
1650
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithMemoryTransport):
1350
1652
def test_trivial_bzipped(self):
1470
1772
request.execute('stacked', 1, (3, r3)))
1775
class TestSmartServerRepositoryIterRevisions(
1776
tests.TestCaseWithMemoryTransport):
1778
def test_basic(self):
1779
backing = self.get_transport()
1780
request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1781
tree = self.make_branch_and_memory_tree('.', format='2a')
1784
tree.commit('1st commit', rev_id="rev1")
1785
tree.commit('2nd commit', rev_id="rev2")
1788
self.assertIs(None, request.execute(''))
1789
response = request.do_body("rev1\nrev2")
1790
self.assertTrue(response.is_successful())
1791
# Format 2a uses serializer format 10
1792
self.assertEquals(response.args, ("ok", "10"))
1794
self.addCleanup(tree.branch.lock_read().unlock)
1795
entries = [zlib.compress(record.get_bytes_as("fulltext")) for record in
1796
tree.branch.repository.revisions.get_record_stream(
1797
[("rev1", ), ("rev2", )], "unordered", True)]
1799
contents = "".join(response.body_stream)
1800
self.assertTrue(contents in (
1801
"".join([entries[0], entries[1]]),
1802
"".join([entries[1], entries[0]])))
1804
def test_missing(self):
1805
backing = self.get_transport()
1806
request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1807
tree = self.make_branch_and_memory_tree('.', format='2a')
1809
self.assertIs(None, request.execute(''))
1810
response = request.do_body("rev1\nrev2")
1811
self.assertTrue(response.is_successful())
1812
# Format 2a uses serializer format 10
1813
self.assertEquals(response.args, ("ok", "10"))
1815
contents = "".join(response.body_stream)
1816
self.assertEquals(contents, "")
1473
1819
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
1475
1821
def make_two_commit_repo(self):
1549
1895
request.execute('', rev_id_utf8))
1898
class TestSmartServerRepositoryIterFilesBytes(tests.TestCaseWithTransport):
1900
def test_single(self):
1901
backing = self.get_transport()
1902
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1903
t = self.make_branch_and_tree('.')
1904
self.addCleanup(t.lock_write().unlock)
1905
self.build_tree_contents([("file", "somecontents")])
1906
t.add(["file"], ["thefileid"])
1907
t.commit(rev_id='somerev', message="add file")
1908
self.assertIs(None, request.execute(''))
1909
response = request.do_body("thefileid\0somerev\n")
1910
self.assertTrue(response.is_successful())
1911
self.assertEquals(response.args, ("ok", ))
1912
self.assertEquals("".join(response.body_stream),
1913
"ok\x000\n" + zlib.compress("somecontents"))
1915
def test_missing(self):
1916
backing = self.get_transport()
1917
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1918
t = self.make_branch_and_tree('.')
1919
self.addCleanup(t.lock_write().unlock)
1920
self.assertIs(None, request.execute(''))
1921
response = request.do_body("thefileid\0revision\n")
1922
self.assertTrue(response.is_successful())
1923
self.assertEquals(response.args, ("ok", ))
1924
self.assertEquals("".join(response.body_stream),
1925
"absent\x00thefileid\x00revision\x000\n")
1928
class TestSmartServerRequestHasSignatureForRevisionId(
1929
tests.TestCaseWithMemoryTransport):
1931
def test_missing_revision(self):
1932
"""For a missing revision, NoSuchRevision is returned."""
1933
backing = self.get_transport()
1934
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1936
self.make_repository('.')
1938
smart_req.FailedSmartServerResponse(
1939
('nosuchrevision', 'revid'), None),
1940
request.execute('', 'revid'))
1942
def test_missing_signature(self):
1943
"""For a missing signature, ('no', ) is returned."""
1944
backing = self.get_transport()
1945
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1947
tree = self.make_branch_and_memory_tree('.')
1950
r1 = tree.commit('a commit', rev_id='A')
1952
self.assertTrue(tree.branch.repository.has_revision('A'))
1953
self.assertEqual(smart_req.SmartServerResponse(('no', )),
1954
request.execute('', 'A'))
1956
def test_present_signature(self):
1957
"""For a present signature, ('yes', ) is returned."""
1958
backing = self.get_transport()
1959
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1961
strategy = gpg.LoopbackGPGStrategy(None)
1962
tree = self.make_branch_and_memory_tree('.')
1965
r1 = tree.commit('a commit', rev_id='A')
1966
tree.branch.repository.start_write_group()
1967
tree.branch.repository.sign_revision('A', strategy)
1968
tree.branch.repository.commit_write_group()
1970
self.assertTrue(tree.branch.repository.has_revision('A'))
1971
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1972
request.execute('', 'A'))
1552
1975
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
1554
1977
def test_empty_revid(self):
1627
2061
request.execute('', ))
2064
class TestSmartServerRepositoryGetRevisionSignatureText(
2065
tests.TestCaseWithMemoryTransport):
2067
def test_get_signature(self):
2068
backing = self.get_transport()
2069
request = smart_repo.SmartServerRepositoryGetRevisionSignatureText(
2071
bb = self.make_branch_builder('.')
2072
bb.build_commit(rev_id='A')
2073
repo = bb.get_branch().repository
2074
strategy = gpg.LoopbackGPGStrategy(None)
2075
self.addCleanup(repo.lock_write().unlock)
2076
repo.start_write_group()
2077
repo.sign_revision('A', strategy)
2078
repo.commit_write_group()
2080
'-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
2081
Testament.from_revision(repo, 'A').as_short_text() +
2082
'-----END PSEUDO-SIGNED CONTENT-----\n')
2084
smart_req.SmartServerResponse(('ok', ), expected_body),
2085
request.execute('', 'A'))
2088
class TestSmartServerRepositoryMakeWorkingTrees(
2089
tests.TestCaseWithMemoryTransport):
2091
def test_make_working_trees(self):
2092
"""For a repository with working trees, ('yes', ) is returned."""
2093
backing = self.get_transport()
2094
request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2095
r = self.make_repository('.')
2096
r.set_make_working_trees(True)
2097
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2098
request.execute('', ))
2100
def test_is_not_shared(self):
2101
"""For a repository with working trees, ('no', ) is returned."""
2102
backing = self.get_transport()
2103
request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2104
r = self.make_repository('.')
2105
r.set_make_working_trees(False)
2106
self.assertEqual(smart_req.SmartServerResponse(('no', )),
2107
request.execute('', ))
1630
2110
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
1632
2112
def test_lock_write_on_unlocked_repo(self):
1746
2226
smart_req.SmartServerResponse(('TokenMismatch',)), response)
2229
class TestSmartServerRepositoryGetPhysicalLockStatus(
2230
tests.TestCaseWithTransport):
2232
def test_with_write_lock(self):
2233
backing = self.get_transport()
2234
repo = self.make_repository('.')
2235
self.addCleanup(repo.lock_write().unlock)
2236
# lock_write() doesn't necessarily actually take a physical
2238
if repo.get_physical_lock_status():
2242
request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2243
request = request_class(backing)
2244
self.assertEqual(smart_req.SuccessfulSmartServerResponse((expected,)),
2245
request.execute('', ))
2247
def test_without_write_lock(self):
2248
backing = self.get_transport()
2249
repo = self.make_repository('.')
2250
self.assertEquals(False, repo.get_physical_lock_status())
2251
request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2252
request = request_class(backing)
2253
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('no',)),
2254
request.execute('', ))
2257
class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
2259
def test_reconcile(self):
2260
backing = self.get_transport()
2261
repo = self.make_repository('.')
2262
token = repo.lock_write().repository_token
2263
self.addCleanup(repo.unlock)
2264
request_class = smart_repo.SmartServerRepositoryReconcile
2265
request = request_class(backing)
2266
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
2268
'garbage_inventories: 0\n'
2269
'inconsistent_parents: 0\n'),
2270
request.execute('', token))
1749
2273
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
1751
2275
def test_is_readonly_no(self):
1789
2313
self.assertTrue(repo.make_working_trees())
2316
class TestSmartServerRepositoryGetSerializerFormat(
2317
tests.TestCaseWithMemoryTransport):
2319
def test_get_serializer_format(self):
2320
backing = self.get_transport()
2321
repo = self.make_repository('.', format='2a')
2322
request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2323
request = request_class(backing)
2325
smart_req.SuccessfulSmartServerResponse(('ok', '10')),
2326
request.execute(''))
2329
class TestSmartServerRepositoryWriteGroup(
2330
tests.TestCaseWithMemoryTransport):
2332
def test_start_write_group(self):
2333
backing = self.get_transport()
2334
repo = self.make_repository('.')
2335
lock_token = repo.lock_write().repository_token
2336
self.addCleanup(repo.unlock)
2337
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2338
request = request_class(backing)
2339
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok', [])),
2340
request.execute('', lock_token))
2342
def test_start_write_group_unsuspendable(self):
2343
backing = self.get_transport()
2344
repo = self.make_repository('.', format='knit')
2345
lock_token = repo.lock_write().repository_token
2346
self.addCleanup(repo.unlock)
2347
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2348
request = request_class(backing)
2350
smart_req.FailedSmartServerResponse(('UnsuspendableWriteGroup',)),
2351
request.execute('', lock_token))
2353
def test_commit_write_group(self):
2354
backing = self.get_transport()
2355
repo = self.make_repository('.')
2356
lock_token = repo.lock_write().repository_token
2357
self.addCleanup(repo.unlock)
2358
repo.start_write_group()
2359
tokens = repo.suspend_write_group()
2360
request_class = smart_repo.SmartServerRepositoryCommitWriteGroup
2361
request = request_class(backing)
2362
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2363
request.execute('', lock_token, tokens))
2365
def test_abort_write_group(self):
2366
backing = self.get_transport()
2367
repo = self.make_repository('.')
2368
lock_token = repo.lock_write().repository_token
2369
repo.start_write_group()
2370
tokens = repo.suspend_write_group()
2371
self.addCleanup(repo.unlock)
2372
request_class = smart_repo.SmartServerRepositoryAbortWriteGroup
2373
request = request_class(backing)
2374
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2375
request.execute('', lock_token, tokens))
2377
def test_check_write_group(self):
2378
backing = self.get_transport()
2379
repo = self.make_repository('.')
2380
lock_token = repo.lock_write().repository_token
2381
repo.start_write_group()
2382
tokens = repo.suspend_write_group()
2383
self.addCleanup(repo.unlock)
2384
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2385
request = request_class(backing)
2386
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2387
request.execute('', lock_token, tokens))
2389
def test_check_write_group_invalid(self):
2390
backing = self.get_transport()
2391
repo = self.make_repository('.')
2392
lock_token = repo.lock_write().repository_token
2393
self.addCleanup(repo.unlock)
2394
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2395
request = request_class(backing)
2396
self.assertEqual(smart_req.FailedSmartServerResponse(
2397
('UnresumableWriteGroup', ['random'],
2398
'Malformed write group token')),
2399
request.execute('', lock_token, ["random"]))
1792
2402
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1794
2404
def make_repo_needing_autopacking(self, path='.'):
1860
2470
"""All registered request_handlers can be found."""
1861
2471
# If there's a typo in a register_lazy call, this loop will fail with
1862
2472
# an AttributeError.
1863
for key, item in smart_req.request_handlers.iteritems():
2473
for key in smart_req.request_handlers.keys():
2475
item = smart_req.request_handlers.get(key)
2476
except AttributeError, e:
2477
raise AttributeError('failed to get %s: %s' % (key, e))
1866
2479
def assertHandlerEqual(self, verb, handler):
1867
2480
self.assertEqual(smart_req.request_handlers.get(verb), handler)
1869
2482
def test_registered_methods(self):
1870
2483
"""Test that known methods are registered to the correct object."""
2484
self.assertHandlerEqual('Branch.break_lock',
2485
smart_branch.SmartServerBranchBreakLock)
1871
2486
self.assertHandlerEqual('Branch.get_config_file',
1872
2487
smart_branch.SmartServerBranchGetConfigFile)
2488
self.assertHandlerEqual('Branch.put_config_file',
2489
smart_branch.SmartServerBranchPutConfigFile)
1873
2490
self.assertHandlerEqual('Branch.get_parent',
1874
2491
smart_branch.SmartServerBranchGetParent)
2492
self.assertHandlerEqual('Branch.get_physical_lock_status',
2493
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
1875
2494
self.assertHandlerEqual('Branch.get_tags_bytes',
1876
2495
smart_branch.SmartServerBranchGetTagsBytes)
1877
2496
self.assertHandlerEqual('Branch.lock_write',
1912
2539
smart_dir.SmartServerRequestOpenBranchV3)
1913
2540
self.assertHandlerEqual('PackRepository.autopack',
1914
2541
smart_packrepo.SmartServerPackRepositoryAutopack)
2542
self.assertHandlerEqual('Repository.add_signature_text',
2543
smart_repo.SmartServerRepositoryAddSignatureText)
2544
self.assertHandlerEqual('Repository.all_revision_ids',
2545
smart_repo.SmartServerRepositoryAllRevisionIds)
2546
self.assertHandlerEqual('Repository.break_lock',
2547
smart_repo.SmartServerRepositoryBreakLock)
1915
2548
self.assertHandlerEqual('Repository.gather_stats',
1916
2549
smart_repo.SmartServerRepositoryGatherStats)
1917
2550
self.assertHandlerEqual('Repository.get_parent_map',
1918
2551
smart_repo.SmartServerRepositoryGetParentMap)
2552
self.assertHandlerEqual('Repository.get_physical_lock_status',
2553
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
1919
2554
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
1920
2555
smart_repo.SmartServerRepositoryGetRevIdForRevno)
1921
2556
self.assertHandlerEqual('Repository.get_revision_graph',
1922
2557
smart_repo.SmartServerRepositoryGetRevisionGraph)
2558
self.assertHandlerEqual('Repository.get_revision_signature_text',
2559
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
1923
2560
self.assertHandlerEqual('Repository.get_stream',
1924
2561
smart_repo.SmartServerRepositoryGetStream)
1925
2562
self.assertHandlerEqual('Repository.get_stream_1.19',
1926
2563
smart_repo.SmartServerRepositoryGetStream_1_19)
2564
self.assertHandlerEqual('Repository.iter_revisions',
2565
smart_repo.SmartServerRepositoryIterRevisions)
1927
2566
self.assertHandlerEqual('Repository.has_revision',
1928
2567
smart_repo.SmartServerRequestHasRevision)
1929
2568
self.assertHandlerEqual('Repository.insert_stream',
1932
2571
smart_repo.SmartServerRepositoryInsertStreamLocked)
1933
2572
self.assertHandlerEqual('Repository.is_shared',
1934
2573
smart_repo.SmartServerRepositoryIsShared)
2574
self.assertHandlerEqual('Repository.iter_files_bytes',
2575
smart_repo.SmartServerRepositoryIterFilesBytes)
1935
2576
self.assertHandlerEqual('Repository.lock_write',
1936
2577
smart_repo.SmartServerRepositoryLockWrite)
2578
self.assertHandlerEqual('Repository.make_working_trees',
2579
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2580
self.assertHandlerEqual('Repository.pack',
2581
smart_repo.SmartServerRepositoryPack)
2582
self.assertHandlerEqual('Repository.reconcile',
2583
smart_repo.SmartServerRepositoryReconcile)
1937
2584
self.assertHandlerEqual('Repository.tarball',
1938
2585
smart_repo.SmartServerRepositoryTarball)
1939
2586
self.assertHandlerEqual('Repository.unlock',
1940
2587
smart_repo.SmartServerRepositoryUnlock)
2588
self.assertHandlerEqual('Repository.start_write_group',
2589
smart_repo.SmartServerRepositoryStartWriteGroup)
2590
self.assertHandlerEqual('Repository.check_write_group',
2591
smart_repo.SmartServerRepositoryCheckWriteGroup)
2592
self.assertHandlerEqual('Repository.commit_write_group',
2593
smart_repo.SmartServerRepositoryCommitWriteGroup)
2594
self.assertHandlerEqual('Repository.abort_write_group',
2595
smart_repo.SmartServerRepositoryAbortWriteGroup)
2596
self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2597
smart_repo.SmartServerRepositoryGetSerializerFormat)
2598
self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2599
smart_repo.SmartServerRepositoryGetInventories)
1941
2600
self.assertHandlerEqual('Transport.is_readonly',
1942
2601
smart_req.SmartServerIsReadonly)
1987
2646
self.server.run_server_stopped_hooks()
1988
2647
self.assertEquals(stopped_calls,
1989
2648
[([self.get_transport().base], 'bzr://example.com:42/')])
2651
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
2653
def test_pack(self):
2654
backing = self.get_transport()
2655
request = smart_repo.SmartServerRepositoryPack(backing)
2656
tree = self.make_branch_and_memory_tree('.')
2657
repo_token = tree.branch.repository.lock_write().repository_token
2659
self.assertIs(None, request.execute('', repo_token, False))
2662
smart_req.SuccessfulSmartServerResponse(('ok', ), ),
2663
request.do_body(''))
2666
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2668
def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2669
base_inv = repository.revision_tree(base_revid).inventory
2670
inv = repository.revision_tree(revid).inventory
2671
inv_delta = inv._make_delta(base_inv)
2672
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2673
return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2675
def test_single(self):
2676
backing = self.get_transport()
2677
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2678
t = self.make_branch_and_tree('.', format='2a')
2679
self.addCleanup(t.lock_write().unlock)
2680
self.build_tree_contents([("file", "somecontents")])
2681
t.add(["file"], ["thefileid"])
2682
t.commit(rev_id='somerev', message="add file")
2683
self.assertIs(None, request.execute('', 'unordered'))
2684
response = request.do_body("somerev\n")
2685
self.assertTrue(response.is_successful())
2686
self.assertEquals(response.args, ("ok", ))
2687
stream = [('inventory-deltas', [
2688
versionedfile.FulltextContentFactory('somerev', None, None,
2689
self._get_serialized_inventory_delta(
2690
t.branch.repository, 'null:', 'somerev'))])]
2691
fmt = bzrdir.format_registry.get('2a')().repository_format
2693
"".join(response.body_stream),
2694
"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2696
def test_empty(self):
2697
backing = self.get_transport()
2698
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2699
t = self.make_branch_and_tree('.', format='2a')
2700
self.addCleanup(t.lock_write().unlock)
2701
self.build_tree_contents([("file", "somecontents")])
2702
t.add(["file"], ["thefileid"])
2703
t.commit(rev_id='somerev', message="add file")
2704
self.assertIs(None, request.execute('', 'unordered'))
2705
response = request.do_body("")
2706
self.assertTrue(response.is_successful())
2707
self.assertEquals(response.args, ("ok", ))
2708
self.assertEquals("".join(response.body_stream),
2709
"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")