221
225
self.assertEqual(expected, request.execute('', 'False'))
228
class TestSmartServerBzrDirRequestCloningMetaDir(
229
tests.TestCaseWithMemoryTransport):
230
"""Tests for BzrDir.checkout_metadir."""
232
def test_checkout_metadir(self):
233
backing = self.get_transport()
234
request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
236
branch = self.make_branch('.', format='2a')
237
response = request.execute('')
239
smart_req.SmartServerResponse(
240
('Bazaar-NG meta directory, format 1\n',
241
'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
242
'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
246
class TestSmartServerBzrDirRequestDestroyBranch(
247
tests.TestCaseWithMemoryTransport):
248
"""Tests for BzrDir.destroy_branch."""
250
def test_destroy_branch_default(self):
251
"""The default branch can be removed."""
252
backing = self.get_transport()
253
dir = self.make_branch('.').bzrdir
254
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
255
request = request_class(backing)
256
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
257
self.assertEqual(expected, request.execute('', None))
259
def test_destroy_branch_named(self):
260
"""A named branch can be removed."""
261
backing = self.get_transport()
262
dir = self.make_repository('.', format="development-colo").bzrdir
263
dir.create_branch(name="branchname")
264
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
265
request = request_class(backing)
266
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
267
self.assertEqual(expected, request.execute('', "branchname"))
269
def test_destroy_branch_missing(self):
270
"""An error is raised if the branch didn't exist."""
271
backing = self.get_transport()
272
dir = self.make_bzrdir('.', format="development-colo")
273
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
274
request = request_class(backing)
275
expected = smart_req.FailedSmartServerResponse(('nobranch',), None)
276
self.assertEqual(expected, request.execute('', "branchname"))
279
class TestSmartServerBzrDirRequestHasWorkingTree(
280
tests.TestCaseWithTransport):
281
"""Tests for BzrDir.has_workingtree."""
283
def test_has_workingtree_yes(self):
284
"""A working tree is present."""
285
backing = self.get_transport()
286
dir = self.make_branch_and_tree('.').bzrdir
287
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
288
request = request_class(backing)
289
expected = smart_req.SuccessfulSmartServerResponse(('yes',))
290
self.assertEqual(expected, request.execute(''))
292
def test_has_workingtree_no(self):
293
"""A working tree is missing."""
294
backing = self.get_transport()
295
dir = self.make_bzrdir('.')
296
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
297
request = request_class(backing)
298
expected = smart_req.SuccessfulSmartServerResponse(('no',))
299
self.assertEqual(expected, request.execute(''))
302
class TestSmartServerBzrDirRequestDestroyRepository(
303
tests.TestCaseWithMemoryTransport):
304
"""Tests for BzrDir.destroy_repository."""
306
def test_destroy_repository_default(self):
307
"""The repository can be removed."""
308
backing = self.get_transport()
309
dir = self.make_repository('.').bzrdir
310
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
311
request = request_class(backing)
312
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
313
self.assertEqual(expected, request.execute(''))
315
def test_destroy_repository_missing(self):
316
"""An error is raised if the repository didn't exist."""
317
backing = self.get_transport()
318
dir = self.make_bzrdir('.')
319
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
320
request = request_class(backing)
321
expected = smart_req.FailedSmartServerResponse(
322
('norepository',), None)
323
self.assertEqual(expected, request.execute(''))
224
326
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
225
327
"""Tests for BzrDir.create_repository."""
735
837
request.execute(''))
840
class TestSmartServerBranchRequestRevisionIdToRevno(
841
tests.TestCaseWithMemoryTransport):
844
backing = self.get_transport()
845
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
847
self.make_branch('.')
848
self.assertEqual(smart_req.SmartServerResponse(('ok', '0')),
849
request.execute('', 'null:'))
851
def test_simple(self):
852
backing = self.get_transport()
853
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
855
tree = self.make_branch_and_memory_tree('.')
858
r1 = tree.commit('1st commit')
861
smart_req.SmartServerResponse(('ok', '1')),
862
request.execute('', r1))
864
def test_not_found(self):
865
backing = self.get_transport()
866
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
868
branch = self.make_branch('.')
870
smart_req.FailedSmartServerResponse(
871
('NoSuchRevision', 'idontexist')),
872
request.execute('', 'idontexist'))
738
875
class TestSmartServerBranchRequestGetConfigFile(
739
876
tests.TestCaseWithMemoryTransport):
769
906
return branch_token, repo_token
909
class TestSmartServerBranchRequestPutConfigFile(TestLockedBranch):
911
def test_with_content(self):
912
backing = self.get_transport()
913
request = smart_branch.SmartServerBranchPutConfigFile(backing)
914
branch = self.make_branch('.')
915
branch_token, repo_token = self.get_lock_tokens(branch)
916
self.assertIs(None, request.execute('', branch_token, repo_token))
918
smart_req.SmartServerResponse(('ok', )),
919
request.do_body('foo bar baz'))
921
branch.control_transport.get_bytes('branch.conf'),
772
926
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
774
928
def test_value_name(self):
1088
1242
self.assertEqual('child-1', self.tree.branch.last_revision())
1245
class TestSmartServerBranchBreakLock(tests.TestCaseWithMemoryTransport):
1247
def test_lock_to_break(self):
1248
base_branch = self.make_branch('base')
1249
request = smart_branch.SmartServerBranchBreakLock(
1250
self.get_transport())
1251
base_branch.lock_write()
1253
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1254
request.execute('base'))
1256
def test_nothing_to_break(self):
1257
base_branch = self.make_branch('base')
1258
request = smart_branch.SmartServerBranchBreakLock(
1259
self.get_transport())
1261
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1262
request.execute('base'))
1091
1265
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
1093
1267
def test_get_parent_none(self):
1275
1449
self.assertEqual('LockFailed', error_name)
1452
class TestSmartServerBranchRequestGetPhysicalLockStatus(TestLockedBranch):
1455
tests.TestCaseWithMemoryTransport.setUp(self)
1457
def test_true(self):
1458
backing = self.get_transport()
1459
request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1461
branch = self.make_branch('.')
1462
branch_token, repo_token = self.get_lock_tokens(branch)
1463
self.assertEquals(True, branch.get_physical_lock_status())
1464
response = request.execute('')
1466
smart_req.SmartServerResponse(('yes',)), response)
1469
def test_false(self):
1470
backing = self.get_transport()
1471
request = smart_branch.SmartServerBranchRequestGetPhysicalLockStatus(
1473
branch = self.make_branch('.')
1474
self.assertEquals(False, branch.get_physical_lock_status())
1475
response = request.execute('')
1477
smart_req.SmartServerResponse(('no',)), response)
1278
1480
class TestSmartServerBranchRequestUnlock(TestLockedBranch):
1280
1482
def setUp(self):
1345
1547
request.execute, 'subdir')
1550
class TestSmartServerRepositoryAddSignatureText(tests.TestCaseWithMemoryTransport):
1552
def test_add_text(self):
1553
backing = self.get_transport()
1554
request = smart_repo.SmartServerRepositoryAddSignatureText(backing)
1555
tree = self.make_branch_and_memory_tree('.')
1556
write_token = tree.lock_write()
1557
self.addCleanup(tree.unlock)
1559
tree.commit("Message", rev_id='rev1')
1560
tree.branch.repository.start_write_group()
1561
write_group_tokens = tree.branch.repository.suspend_write_group()
1562
self.assertEqual(None, request.execute('', write_token,
1563
'rev1', *write_group_tokens))
1564
response = request.do_body('somesignature')
1565
self.assertTrue(response.is_successful())
1566
self.assertEqual(response.args[0], 'ok')
1567
write_group_tokens = response.args[1:]
1568
tree.branch.repository.resume_write_group(write_group_tokens)
1569
tree.branch.repository.commit_write_group()
1571
self.assertEqual("somesignature",
1572
tree.branch.repository.get_signature_text("rev1"))
1575
class TestSmartServerRepositoryAllRevisionIds(
1576
tests.TestCaseWithMemoryTransport):
1578
def test_empty(self):
1579
"""An empty body should be returned for an empty repository."""
1580
backing = self.get_transport()
1581
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1582
self.make_repository('.')
1584
smart_req.SuccessfulSmartServerResponse(("ok", ), ""),
1585
request.execute(''))
1587
def test_some_revisions(self):
1588
"""An empty body should be returned for an empty repository."""
1589
backing = self.get_transport()
1590
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1591
tree = self.make_branch_and_memory_tree('.')
1594
tree.commit(rev_id='origineel', message="message")
1595
tree.commit(rev_id='nog-een-revisie', message="message")
1598
smart_req.SuccessfulSmartServerResponse(("ok", ),
1599
"origineel\nnog-een-revisie"),
1600
request.execute(''))
1603
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1605
def test_lock_to_break(self):
1606
backing = self.get_transport()
1607
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1608
tree = self.make_branch_and_memory_tree('.')
1609
tree.branch.repository.lock_write()
1611
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1612
request.execute(''))
1614
def test_nothing_to_break(self):
1615
backing = self.get_transport()
1616
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1617
tree = self.make_branch_and_memory_tree('.')
1619
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1620
request.execute(''))
1348
1623
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithMemoryTransport):
1350
1625
def test_trivial_bzipped(self):
1470
1745
request.execute('stacked', 1, (3, r3)))
1748
class TestSmartServerRepositoryIterRevisions(
1749
tests.TestCaseWithMemoryTransport):
1751
def test_basic(self):
1752
backing = self.get_transport()
1753
request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1754
tree = self.make_branch_and_memory_tree('.', format='2a')
1757
tree.commit('1st commit', rev_id="rev1")
1758
tree.commit('2nd commit', rev_id="rev2")
1761
self.assertIs(None, request.execute(''))
1762
response = request.do_body("rev1\nrev2")
1763
self.assertTrue(response.is_successful())
1764
# Format 2a uses serializer format 10
1765
self.assertEquals(response.args, ("ok", "10"))
1767
self.addCleanup(tree.branch.lock_read().unlock)
1768
entries = [zlib.compress(record.get_bytes_as("fulltext")) for record in
1769
tree.branch.repository.revisions.get_record_stream(
1770
[("rev1", ), ("rev2", )], "unordered", True)]
1772
contents = "".join(response.body_stream)
1773
self.assertTrue(contents in (
1774
"".join([entries[0], entries[1]]),
1775
"".join([entries[1], entries[0]])))
1777
def test_missing(self):
1778
backing = self.get_transport()
1779
request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1780
tree = self.make_branch_and_memory_tree('.', format='2a')
1782
self.assertIs(None, request.execute(''))
1783
response = request.do_body("rev1\nrev2")
1784
self.assertTrue(response.is_successful())
1785
# Format 2a uses serializer format 10
1786
self.assertEquals(response.args, ("ok", "10"))
1788
contents = "".join(response.body_stream)
1789
self.assertEquals(contents, "")
1473
1792
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
1475
1794
def make_two_commit_repo(self):
1549
1868
request.execute('', rev_id_utf8))
1871
class TestSmartServerRepositoryIterFilesBytes(tests.TestCaseWithTransport):
1873
def test_single(self):
1874
backing = self.get_transport()
1875
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1876
t = self.make_branch_and_tree('.')
1877
self.addCleanup(t.lock_write().unlock)
1878
self.build_tree_contents([("file", "somecontents")])
1879
t.add(["file"], ["thefileid"])
1880
t.commit(rev_id='somerev', message="add file")
1881
self.assertIs(None, request.execute(''))
1882
response = request.do_body("thefileid\0somerev\n")
1883
self.assertTrue(response.is_successful())
1884
self.assertEquals(response.args, ("ok", ))
1885
self.assertEquals("".join(response.body_stream),
1886
"ok\x000\n" + zlib.compress("somecontents"))
1888
def test_missing(self):
1889
backing = self.get_transport()
1890
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1891
t = self.make_branch_and_tree('.')
1892
self.addCleanup(t.lock_write().unlock)
1893
self.assertIs(None, request.execute(''))
1894
response = request.do_body("thefileid\0revision\n")
1895
self.assertTrue(response.is_successful())
1896
self.assertEquals(response.args, ("ok", ))
1897
self.assertEquals("".join(response.body_stream),
1898
"absent\x00thefileid\x00revision\x000\n")
1901
class TestSmartServerRequestHasSignatureForRevisionId(
1902
tests.TestCaseWithMemoryTransport):
1904
def test_missing_revision(self):
1905
"""For a missing revision, NoSuchRevision is returned."""
1906
backing = self.get_transport()
1907
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1909
self.make_repository('.')
1911
smart_req.FailedSmartServerResponse(
1912
('nosuchrevision', 'revid'), None),
1913
request.execute('', 'revid'))
1915
def test_missing_signature(self):
1916
"""For a missing signature, ('no', ) is returned."""
1917
backing = self.get_transport()
1918
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1920
tree = self.make_branch_and_memory_tree('.')
1923
r1 = tree.commit('a commit', rev_id='A')
1925
self.assertTrue(tree.branch.repository.has_revision('A'))
1926
self.assertEqual(smart_req.SmartServerResponse(('no', )),
1927
request.execute('', 'A'))
1929
def test_present_signature(self):
1930
"""For a present signature, ('yes', ) is returned."""
1931
backing = self.get_transport()
1932
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1934
strategy = gpg.LoopbackGPGStrategy(None)
1935
tree = self.make_branch_and_memory_tree('.')
1938
r1 = tree.commit('a commit', rev_id='A')
1939
tree.branch.repository.start_write_group()
1940
tree.branch.repository.sign_revision('A', strategy)
1941
tree.branch.repository.commit_write_group()
1943
self.assertTrue(tree.branch.repository.has_revision('A'))
1944
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1945
request.execute('', 'A'))
1552
1948
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
1554
1950
def test_empty_revid(self):
1627
2034
request.execute('', ))
2037
class TestSmartServerRepositoryGetRevisionSignatureText(
2038
tests.TestCaseWithMemoryTransport):
2040
def test_get_signature(self):
2041
backing = self.get_transport()
2042
request = smart_repo.SmartServerRepositoryGetRevisionSignatureText(
2044
bb = self.make_branch_builder('.')
2045
bb.build_commit(rev_id='A')
2046
repo = bb.get_branch().repository
2047
strategy = gpg.LoopbackGPGStrategy(None)
2048
self.addCleanup(repo.lock_write().unlock)
2049
repo.start_write_group()
2050
repo.sign_revision('A', strategy)
2051
repo.commit_write_group()
2053
'-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
2054
Testament.from_revision(repo, 'A').as_short_text() +
2055
'-----END PSEUDO-SIGNED CONTENT-----\n')
2057
smart_req.SmartServerResponse(('ok', ), expected_body),
2058
request.execute('', 'A'))
2061
class TestSmartServerRepositoryMakeWorkingTrees(
2062
tests.TestCaseWithMemoryTransport):
2064
def test_make_working_trees(self):
2065
"""For a repository with working trees, ('yes', ) is returned."""
2066
backing = self.get_transport()
2067
request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2068
r = self.make_repository('.')
2069
r.set_make_working_trees(True)
2070
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2071
request.execute('', ))
2073
def test_is_not_shared(self):
2074
"""For a repository with working trees, ('no', ) is returned."""
2075
backing = self.get_transport()
2076
request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2077
r = self.make_repository('.')
2078
r.set_make_working_trees(False)
2079
self.assertEqual(smart_req.SmartServerResponse(('no', )),
2080
request.execute('', ))
1630
2083
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
1632
2085
def test_lock_write_on_unlocked_repo(self):
1746
2199
smart_req.SmartServerResponse(('TokenMismatch',)), response)
2202
class TestSmartServerRepositoryGetPhysicalLockStatus(
2203
tests.TestCaseWithTransport):
2205
def test_with_write_lock(self):
2206
backing = self.get_transport()
2207
repo = self.make_repository('.')
2208
self.addCleanup(repo.lock_write().unlock)
2209
# lock_write() doesn't necessarily actually take a physical
2211
if repo.get_physical_lock_status():
2215
request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2216
request = request_class(backing)
2217
self.assertEqual(smart_req.SuccessfulSmartServerResponse((expected,)),
2218
request.execute('', ))
2220
def test_without_write_lock(self):
2221
backing = self.get_transport()
2222
repo = self.make_repository('.')
2223
self.assertEquals(False, repo.get_physical_lock_status())
2224
request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2225
request = request_class(backing)
2226
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('no',)),
2227
request.execute('', ))
2230
class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
2232
def test_reconcile(self):
2233
backing = self.get_transport()
2234
repo = self.make_repository('.')
2235
token = repo.lock_write().repository_token
2236
self.addCleanup(repo.unlock)
2237
request_class = smart_repo.SmartServerRepositoryReconcile
2238
request = request_class(backing)
2239
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
2241
'garbage_inventories: 0\n'
2242
'inconsistent_parents: 0\n'),
2243
request.execute('', token))
1749
2246
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
1751
2248
def test_is_readonly_no(self):
1789
2286
self.assertTrue(repo.make_working_trees())
2289
class TestSmartServerRepositoryGetSerializerFormat(
2290
tests.TestCaseWithMemoryTransport):
2292
def test_get_serializer_format(self):
2293
backing = self.get_transport()
2294
repo = self.make_repository('.', format='2a')
2295
request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2296
request = request_class(backing)
2298
smart_req.SuccessfulSmartServerResponse(('ok', '10')),
2299
request.execute(''))
2302
class TestSmartServerRepositoryWriteGroup(
2303
tests.TestCaseWithMemoryTransport):
2305
def test_start_write_group(self):
2306
backing = self.get_transport()
2307
repo = self.make_repository('.')
2308
lock_token = repo.lock_write().repository_token
2309
self.addCleanup(repo.unlock)
2310
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2311
request = request_class(backing)
2312
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok', [])),
2313
request.execute('', lock_token))
2315
def test_start_write_group_unsuspendable(self):
2316
backing = self.get_transport()
2317
repo = self.make_repository('.', format='knit')
2318
lock_token = repo.lock_write().repository_token
2319
self.addCleanup(repo.unlock)
2320
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2321
request = request_class(backing)
2323
smart_req.FailedSmartServerResponse(('UnsuspendableWriteGroup',)),
2324
request.execute('', lock_token))
2326
def test_commit_write_group(self):
2327
backing = self.get_transport()
2328
repo = self.make_repository('.')
2329
lock_token = repo.lock_write().repository_token
2330
self.addCleanup(repo.unlock)
2331
repo.start_write_group()
2332
tokens = repo.suspend_write_group()
2333
request_class = smart_repo.SmartServerRepositoryCommitWriteGroup
2334
request = request_class(backing)
2335
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2336
request.execute('', lock_token, tokens))
2338
def test_abort_write_group(self):
2339
backing = self.get_transport()
2340
repo = self.make_repository('.')
2341
lock_token = repo.lock_write().repository_token
2342
repo.start_write_group()
2343
tokens = repo.suspend_write_group()
2344
self.addCleanup(repo.unlock)
2345
request_class = smart_repo.SmartServerRepositoryAbortWriteGroup
2346
request = request_class(backing)
2347
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2348
request.execute('', lock_token, tokens))
2350
def test_check_write_group(self):
2351
backing = self.get_transport()
2352
repo = self.make_repository('.')
2353
lock_token = repo.lock_write().repository_token
2354
repo.start_write_group()
2355
tokens = repo.suspend_write_group()
2356
self.addCleanup(repo.unlock)
2357
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2358
request = request_class(backing)
2359
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2360
request.execute('', lock_token, tokens))
2362
def test_check_write_group_invalid(self):
2363
backing = self.get_transport()
2364
repo = self.make_repository('.')
2365
lock_token = repo.lock_write().repository_token
2366
self.addCleanup(repo.unlock)
2367
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2368
request = request_class(backing)
2369
self.assertEqual(smart_req.FailedSmartServerResponse(
2370
('UnresumableWriteGroup', ['random'],
2371
'Malformed write group token')),
2372
request.execute('', lock_token, ["random"]))
1792
2375
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1794
2377
def make_repo_needing_autopacking(self, path='.'):
1860
2443
"""All registered request_handlers can be found."""
1861
2444
# If there's a typo in a register_lazy call, this loop will fail with
1862
2445
# an AttributeError.
1863
for key, item in smart_req.request_handlers.iteritems():
2446
for key in smart_req.request_handlers.keys():
2448
item = smart_req.request_handlers.get(key)
2449
except AttributeError, e:
2450
raise AttributeError('failed to get %s: %s' % (key, e))
1866
2452
def assertHandlerEqual(self, verb, handler):
1867
2453
self.assertEqual(smart_req.request_handlers.get(verb), handler)
1869
2455
def test_registered_methods(self):
1870
2456
"""Test that known methods are registered to the correct object."""
2457
self.assertHandlerEqual('Branch.break_lock',
2458
smart_branch.SmartServerBranchBreakLock)
1871
2459
self.assertHandlerEqual('Branch.get_config_file',
1872
2460
smart_branch.SmartServerBranchGetConfigFile)
2461
self.assertHandlerEqual('Branch.put_config_file',
2462
smart_branch.SmartServerBranchPutConfigFile)
1873
2463
self.assertHandlerEqual('Branch.get_parent',
1874
2464
smart_branch.SmartServerBranchGetParent)
2465
self.assertHandlerEqual('Branch.get_physical_lock_status',
2466
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
1875
2467
self.assertHandlerEqual('Branch.get_tags_bytes',
1876
2468
smart_branch.SmartServerBranchGetTagsBytes)
1877
2469
self.assertHandlerEqual('Branch.lock_write',
1912
2510
smart_dir.SmartServerRequestOpenBranchV3)
1913
2511
self.assertHandlerEqual('PackRepository.autopack',
1914
2512
smart_packrepo.SmartServerPackRepositoryAutopack)
2513
self.assertHandlerEqual('Repository.add_signature_text',
2514
smart_repo.SmartServerRepositoryAddSignatureText)
2515
self.assertHandlerEqual('Repository.all_revision_ids',
2516
smart_repo.SmartServerRepositoryAllRevisionIds)
2517
self.assertHandlerEqual('Repository.break_lock',
2518
smart_repo.SmartServerRepositoryBreakLock)
1915
2519
self.assertHandlerEqual('Repository.gather_stats',
1916
2520
smart_repo.SmartServerRepositoryGatherStats)
1917
2521
self.assertHandlerEqual('Repository.get_parent_map',
1918
2522
smart_repo.SmartServerRepositoryGetParentMap)
2523
self.assertHandlerEqual('Repository.get_physical_lock_status',
2524
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
1919
2525
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
1920
2526
smart_repo.SmartServerRepositoryGetRevIdForRevno)
1921
2527
self.assertHandlerEqual('Repository.get_revision_graph',
1922
2528
smart_repo.SmartServerRepositoryGetRevisionGraph)
2529
self.assertHandlerEqual('Repository.get_revision_signature_text',
2530
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
1923
2531
self.assertHandlerEqual('Repository.get_stream',
1924
2532
smart_repo.SmartServerRepositoryGetStream)
1925
2533
self.assertHandlerEqual('Repository.get_stream_1.19',
1926
2534
smart_repo.SmartServerRepositoryGetStream_1_19)
2535
self.assertHandlerEqual('Repository.iter_revisions',
2536
smart_repo.SmartServerRepositoryIterRevisions)
1927
2537
self.assertHandlerEqual('Repository.has_revision',
1928
2538
smart_repo.SmartServerRequestHasRevision)
1929
2539
self.assertHandlerEqual('Repository.insert_stream',
1932
2542
smart_repo.SmartServerRepositoryInsertStreamLocked)
1933
2543
self.assertHandlerEqual('Repository.is_shared',
1934
2544
smart_repo.SmartServerRepositoryIsShared)
2545
self.assertHandlerEqual('Repository.iter_files_bytes',
2546
smart_repo.SmartServerRepositoryIterFilesBytes)
1935
2547
self.assertHandlerEqual('Repository.lock_write',
1936
2548
smart_repo.SmartServerRepositoryLockWrite)
2549
self.assertHandlerEqual('Repository.make_working_trees',
2550
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2551
self.assertHandlerEqual('Repository.pack',
2552
smart_repo.SmartServerRepositoryPack)
2553
self.assertHandlerEqual('Repository.reconcile',
2554
smart_repo.SmartServerRepositoryReconcile)
1937
2555
self.assertHandlerEqual('Repository.tarball',
1938
2556
smart_repo.SmartServerRepositoryTarball)
1939
2557
self.assertHandlerEqual('Repository.unlock',
1940
2558
smart_repo.SmartServerRepositoryUnlock)
2559
self.assertHandlerEqual('Repository.start_write_group',
2560
smart_repo.SmartServerRepositoryStartWriteGroup)
2561
self.assertHandlerEqual('Repository.check_write_group',
2562
smart_repo.SmartServerRepositoryCheckWriteGroup)
2563
self.assertHandlerEqual('Repository.commit_write_group',
2564
smart_repo.SmartServerRepositoryCommitWriteGroup)
2565
self.assertHandlerEqual('Repository.abort_write_group',
2566
smart_repo.SmartServerRepositoryAbortWriteGroup)
2567
self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2568
smart_repo.SmartServerRepositoryGetSerializerFormat)
2569
self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2570
smart_repo.SmartServerRepositoryGetInventories)
1941
2571
self.assertHandlerEqual('Transport.is_readonly',
1942
2572
smart_req.SmartServerIsReadonly)
1987
2617
self.server.run_server_stopped_hooks()
1988
2618
self.assertEquals(stopped_calls,
1989
2619
[([self.get_transport().base], 'bzr://example.com:42/')])
2622
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
2624
def test_pack(self):
2625
backing = self.get_transport()
2626
request = smart_repo.SmartServerRepositoryPack(backing)
2627
tree = self.make_branch_and_memory_tree('.')
2628
repo_token = tree.branch.repository.lock_write().repository_token
2630
self.assertIs(None, request.execute('', repo_token, False))
2633
smart_req.SuccessfulSmartServerResponse(('ok', ), ),
2634
request.do_body(''))
2637
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2639
def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2640
base_inv = repository.revision_tree(base_revid).inventory
2641
inv = repository.revision_tree(revid).inventory
2642
inv_delta = inv._make_delta(base_inv)
2643
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2644
return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2646
def test_single(self):
2647
backing = self.get_transport()
2648
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2649
t = self.make_branch_and_tree('.', format='2a')
2650
self.addCleanup(t.lock_write().unlock)
2651
self.build_tree_contents([("file", "somecontents")])
2652
t.add(["file"], ["thefileid"])
2653
t.commit(rev_id='somerev', message="add file")
2654
self.assertIs(None, request.execute('', 'unordered'))
2655
response = request.do_body("somerev\n")
2656
self.assertTrue(response.is_successful())
2657
self.assertEquals(response.args, ("ok", ))
2658
stream = [('inventory-deltas', [
2659
versionedfile.FulltextContentFactory('somerev', None, None,
2660
self._get_serialized_inventory_delta(
2661
t.branch.repository, 'null:', 'somerev'))])]
2662
fmt = bzrdir.format_registry.get('2a')().repository_format
2664
"".join(response.body_stream),
2665
"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2667
def test_empty(self):
2668
backing = self.get_transport()
2669
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2670
t = self.make_branch_and_tree('.', format='2a')
2671
self.addCleanup(t.lock_write().unlock)
2672
self.build_tree_contents([("file", "somecontents")])
2673
t.add(["file"], ["thefileid"])
2674
t.commit(rev_id='somerev', message="add file")
2675
self.assertIs(None, request.execute('', 'unordered'))
2676
response = request.do_body("")
2677
self.assertTrue(response.is_successful())
2678
self.assertEquals(response.args, ("ok", ))
2679
self.assertEquals("".join(response.body_stream),
2680
"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")