65
65
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}),
66
66
("find_repositoryV2", {
67
67
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV2}),
68
("find_repositoryV3", {
69
"_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV3}),
69
71
to_adapt, result = split_suite_by_re(standard_tests,
70
72
"TestSmartServerRequestFindRepository")
160
162
request.transport_from_client_path('foo/').base)
165
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
166
"""Tests for BzrDir.create_repository."""
168
def test_makes_repository(self):
169
"""When there is a bzrdir present, the call succeeds."""
170
backing = self.get_transport()
171
self.make_bzrdir('.')
172
request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository
173
request = request_class(backing)
174
reference_bzrdir_format = bzrdir.format_registry.get('default')()
175
reference_format = reference_bzrdir_format.repository_format
176
network_name = reference_format.network_name()
177
expected = SuccessfulSmartServerResponse(
178
('ok', 'no', 'no', 'no', network_name))
179
self.assertEqual(expected, request.execute('', network_name, 'True'))
163
182
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
164
183
"""Tests for BzrDir.find_repository."""
172
191
request.execute(''))
174
193
def test_nonshared_repository(self):
175
# nonshared repositorys only allow 'find' to return a handle when the
176
# path the repository is being searched on is the same as that that
194
# nonshared repositorys only allow 'find' to return a handle when the
195
# path the repository is being searched on is the same as that that
177
196
# the repository is at.
178
197
backing = self.get_transport()
179
198
request = self._request_class(backing)
200
if (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
219
if (smart.bzrdir.SmartServerRequestFindRepositoryV3 ==
220
self._request_class):
221
return SuccessfulSmartServerResponse(
222
('ok', '', rich_root, subtrees, 'no',
223
repo._format.network_name()))
224
elif (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
201
225
self._request_class):
202
226
# All tests so far are on formats, and for non-external
250
274
self.assertEqual(SmartServerResponse(('ok', )),
251
275
request.execute(''))
252
276
made_dir = bzrdir.BzrDir.open_from_transport(backing)
253
# no branch, tree or repository is expected with the current
277
# no branch, tree or repository is expected with the current
254
278
# default formart.
255
279
self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
256
280
self.assertRaises(errors.NotBranchError, made_dir.open_branch)
388
412
def test_with_content(self):
389
413
# SmartServerBranchGetConfigFile should return the content from
390
414
# branch.control_files.get('branch.conf') for now - in the future it may
391
# perform more complex processing.
415
# perform more complex processing.
392
416
backing = self.get_transport()
393
417
request = smart.branch.SmartServerBranchGetConfigFile(backing)
394
418
branch = self.make_branch('.')
416
440
def unlock_branch(self):
417
441
self.tree.branch.unlock()
419
443
def set_last_revision(self, revision_id, revno):
420
444
branch_token, repo_token = self.lock_branch()
421
445
response = self._set_last_revision(
427
451
response = self.set_last_revision(revision_id, revno)
428
452
self.assertEqual(SuccessfulSmartServerResponse(('ok',)), response)
431
455
class TestSetLastRevisionVerbMixin(object):
432
456
"""Mixin test case for verbs that implement set_last_revision."""
538
562
self.assertEqual(
539
563
SuccessfulSmartServerResponse(('ok', revno, revision_id)),
542
566
def test_branch_last_revision_info_rewind(self):
543
567
"""A branch's tip can be set to a revision that is an ancestor of the
544
568
current tip, but only if allow_overwrite_descendant is passed.
588
612
new_r2 = self.tree.commit('2nd commit', rev_id='child-2')
589
613
self.tree.unlock()
591
615
def test_not_allow_diverged(self):
592
616
"""If allow_diverged is not passed, then setting a divergent history
593
617
returns a Diverged error.
835
859
self.assertEqual(SmartServerResponse(('ok', ), rev_id_utf8),
836
860
request.execute('', rev_id_utf8))
838
862
def test_no_such_revision(self):
839
863
backing = self.get_transport()
840
864
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
1037
1061
SmartServerResponse(('yes',)), response)
1064
class TestSmartServerRepositorySetMakeWorkingTrees(tests.TestCaseWithMemoryTransport):
1066
def test_set_false(self):
1067
backing = self.get_transport()
1068
repo = self.make_repository('.', shared=True)
1069
repo.set_make_working_trees(True)
1070
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1071
request = request_class(backing)
1072
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1073
request.execute('', 'False'))
1074
repo = repo.bzrdir.open_repository()
1075
self.assertFalse(repo.make_working_trees())
1077
def test_set_true(self):
1078
backing = self.get_transport()
1079
repo = self.make_repository('.', shared=True)
1080
repo.set_make_working_trees(False)
1081
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1082
request = request_class(backing)
1083
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1084
request.execute('', 'True'))
1085
repo = repo.bzrdir.open_repository()
1086
self.assertTrue(repo.make_working_trees())
1040
1089
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1042
1091
def make_repo_needing_autopacking(self, path='.'):
1060
1109
self.assertEqual(SmartServerResponse(('ok',)), response)
1061
1110
repo._pack_collection.reload_pack_names()
1062
1111
self.assertEqual(1, len(repo._pack_collection.names()))
1064
1113
def test_autopack_not_needed(self):
1065
1114
tree = self.make_branch_and_tree('.', format='pack-0.92')
1066
1115
repo = tree.branch.repository
1073
1122
self.assertEqual(SmartServerResponse(('ok',)), response)
1074
1123
repo._pack_collection.reload_pack_names()
1075
1124
self.assertEqual(9, len(repo._pack_collection.names()))
1077
1126
def test_autopack_on_nonpack_format(self):
1078
1127
"""A request to autopack a non-pack repo is a no-op."""
1079
1128
repo = self.make_repository('.', format='knit')
1083
1132
response = request.execute('')
1084
1133
self.assertEqual(SmartServerResponse(('ok',)), response)
1087
1136
class TestHandlers(tests.TestCase):
1088
1137
"""Tests for the request.request_handlers object."""
1152
1201
smart.request.request_handlers.get('Repository.lock_write'),
1153
1202
smart.repository.SmartServerRepositoryLockWrite)
1154
1203
self.assertEqual(
1204
smart.request.request_handlers.get('Repository.get_stream'),
1205
smart.repository.SmartServerRepositoryGetStream)
1155
1207
smart.request.request_handlers.get('Repository.tarball'),
1156
1208
smart.repository.SmartServerRepositoryTarball)
1157
1209
self.assertEqual(