160
160
request.transport_from_client_path('foo/').base)
163
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
164
"""Tests for BzrDir.create_repository."""
166
def test_makes_repository(self):
167
"""When there is a bzrdir present, the call succeeds."""
168
backing = self.get_transport()
169
self.make_bzrdir('.')
170
request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository
171
request = request_class(backing)
172
reference_bzrdir_format = bzrdir.format_registry.get('default')()
173
reference_format = reference_bzrdir_format.repository_format
174
network_name = reference_format.network_name()
175
expected = SuccessfulSmartServerResponse(
176
('ok', 'no', 'no', 'no', network_name))
177
self.assertEqual(expected, request.execute('', network_name, 'True'))
163
180
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
164
181
"""Tests for BzrDir.find_repository."""
172
189
request.execute(''))
174
191
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
192
# nonshared repositorys only allow 'find' to return a handle when the
193
# path the repository is being searched on is the same as that that
177
194
# the repository is at.
178
195
backing = self.get_transport()
179
196
request = self._request_class(backing)
250
267
self.assertEqual(SmartServerResponse(('ok', )),
251
268
request.execute(''))
252
269
made_dir = bzrdir.BzrDir.open_from_transport(backing)
253
# no branch, tree or repository is expected with the current
270
# no branch, tree or repository is expected with the current
254
271
# default formart.
255
272
self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
256
273
self.assertRaises(errors.NotBranchError, made_dir.open_branch)
388
405
def test_with_content(self):
389
406
# SmartServerBranchGetConfigFile should return the content from
390
407
# branch.control_files.get('branch.conf') for now - in the future it may
391
# perform more complex processing.
408
# perform more complex processing.
392
409
backing = self.get_transport()
393
410
request = smart.branch.SmartServerBranchGetConfigFile(backing)
394
411
branch = self.make_branch('.')
416
433
def unlock_branch(self):
417
434
self.tree.branch.unlock()
419
436
def set_last_revision(self, revision_id, revno):
420
437
branch_token, repo_token = self.lock_branch()
421
438
response = self._set_last_revision(
427
444
response = self.set_last_revision(revision_id, revno)
428
445
self.assertEqual(SuccessfulSmartServerResponse(('ok',)), response)
431
448
class TestSetLastRevisionVerbMixin(object):
432
449
"""Mixin test case for verbs that implement set_last_revision."""
538
555
self.assertEqual(
539
556
SuccessfulSmartServerResponse(('ok', revno, revision_id)),
542
559
def test_branch_last_revision_info_rewind(self):
543
560
"""A branch's tip can be set to a revision that is an ancestor of the
544
561
current tip, but only if allow_overwrite_descendant is passed.
588
605
new_r2 = self.tree.commit('2nd commit', rev_id='child-2')
589
606
self.tree.unlock()
591
608
def test_not_allow_diverged(self):
592
609
"""If allow_diverged is not passed, then setting a divergent history
593
610
returns a Diverged error.
835
852
self.assertEqual(SmartServerResponse(('ok', ), rev_id_utf8),
836
853
request.execute('', rev_id_utf8))
838
855
def test_no_such_revision(self):
839
856
backing = self.get_transport()
840
857
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
1037
1054
SmartServerResponse(('yes',)), response)
1057
class TestSmartServerRepositorySetMakeWorkingTrees(tests.TestCaseWithMemoryTransport):
1059
def test_set_false(self):
1060
backing = self.get_transport()
1061
repo = self.make_repository('.', shared=True)
1062
repo.set_make_working_trees(True)
1063
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1064
request = request_class(backing)
1065
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1066
request.execute('', 'False'))
1067
repo = repo.bzrdir.open_repository()
1068
self.assertFalse(repo.make_working_trees())
1070
def test_set_true(self):
1071
backing = self.get_transport()
1072
repo = self.make_repository('.', shared=True)
1073
repo.set_make_working_trees(False)
1074
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
1075
request = request_class(backing)
1076
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
1077
request.execute('', 'True'))
1078
repo = repo.bzrdir.open_repository()
1079
self.assertTrue(repo.make_working_trees())
1040
1082
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1042
1084
def make_repo_needing_autopacking(self, path='.'):
1060
1102
self.assertEqual(SmartServerResponse(('ok',)), response)
1061
1103
repo._pack_collection.reload_pack_names()
1062
1104
self.assertEqual(1, len(repo._pack_collection.names()))
1064
1106
def test_autopack_not_needed(self):
1065
1107
tree = self.make_branch_and_tree('.', format='pack-0.92')
1066
1108
repo = tree.branch.repository
1073
1115
self.assertEqual(SmartServerResponse(('ok',)), response)
1074
1116
repo._pack_collection.reload_pack_names()
1075
1117
self.assertEqual(9, len(repo._pack_collection.names()))
1077
1119
def test_autopack_on_nonpack_format(self):
1078
1120
"""A request to autopack a non-pack repo is a no-op."""
1079
1121
repo = self.make_repository('.', format='knit')
1083
1125
response = request.execute('')
1084
1126
self.assertEqual(SmartServerResponse(('ok',)), response)
1087
1129
class TestHandlers(tests.TestCase):
1088
1130
"""Tests for the request.request_handlers object."""