724
724
format = branch._format
725
725
self.assertEqual(network_name, format.network_name())
727
def test_already_open_repo_and_reused_medium(self):
728
"""Bug 726584: create_branch(..., repository=repo) should work
729
regardless of what the smart medium's base URL is.
731
self.transport_server = test_server.SmartTCPServer_for_testing
732
transport = self.get_transport('.')
733
repo = self.make_repository('quack')
734
# Client's medium rooted a transport root (not at the bzrdir)
735
client = FakeClient(transport.base)
736
transport = transport.clone('quack')
737
reference_bzrdir_format = bzrdir.format_registry.get('default')()
738
reference_format = reference_bzrdir_format.get_branch_format()
739
network_name = reference_format.network_name()
740
reference_repo_fmt = reference_bzrdir_format.repository_format
741
reference_repo_name = reference_repo_fmt.network_name()
742
client.add_expected_call(
743
'BzrDir.create_branch', ('extra/quack/', network_name),
744
'success', ('ok', network_name, '', 'no', 'no', 'yes',
745
reference_repo_name))
746
a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
748
branch = a_bzrdir.create_branch(repository=repo)
749
# We should have got a remote branch
750
self.assertIsInstance(branch, remote.RemoteBranch)
751
# its format should have the settings from the response
752
format = branch._format
753
self.assertEqual(network_name, format.network_name())
728
756
class TestBzrDirCreateRepository(TestRemote):
1143
1171
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1174
class TestBranchHeadsToFetch(RemoteBranchTestCase):
1176
def test_uses_last_revision_info_and_tags_by_default(self):
1177
transport = MemoryTransport()
1178
client = FakeClient(transport.base)
1179
client.add_expected_call(
1180
'Branch.get_stacked_on_url', ('quack/',),
1181
'error', ('NotStacked',))
1182
client.add_expected_call(
1183
'Branch.last_revision_info', ('quack/',),
1184
'success', ('ok', '1', 'rev-tip'))
1185
# XXX: this will break if the default format's serialization of tags
1186
# changes, or if the RPC for fetching tags changes from get_tags_bytes.
1187
client.add_expected_call(
1188
'Branch.get_tags_bytes', ('quack/',),
1189
'success', ('d5:tag-17:rev-foo5:tag-27:rev-bare',))
1190
transport.mkdir('quack')
1191
transport = transport.clone('quack')
1192
branch = self.make_remote_branch(transport, client)
1193
result = branch.heads_to_fetch()
1194
self.assertFinished(client)
1196
(set(['rev-tip']), set(['rev-foo', 'rev-bar'])), result)
1198
def test_uses_rpc_for_formats_with_non_default_heads_to_fetch(self):
1199
transport = MemoryTransport()
1200
client = FakeClient(transport.base)
1201
client.add_expected_call(
1202
'Branch.get_stacked_on_url', ('quack/',),
1203
'error', ('NotStacked',))
1204
client.add_expected_call(
1205
'Branch.heads_to_fetch', ('quack/',),
1206
'success', (['tip'], ['tagged-1', 'tagged-2']))
1207
transport.mkdir('quack')
1208
transport = transport.clone('quack')
1209
branch = self.make_remote_branch(transport, client)
1210
branch._format._use_default_local_heads_to_fetch = lambda: False
1211
result = branch.heads_to_fetch()
1212
self.assertFinished(client)
1213
self.assertEqual((set(['tip']), set(['tagged-1', 'tagged-2'])), result)
1215
def test_backwards_compatible(self):
1216
self.setup_smart_server_with_call_log()
1217
# Make a branch with a single revision.
1218
builder = self.make_branch_builder('foo')
1219
builder.start_series()
1220
builder.build_snapshot('tip', None, [
1221
('add', ('', 'root-id', 'directory', ''))])
1222
builder.finish_series()
1223
branch = builder.get_branch()
1224
# Add two tags to that branch
1225
branch.tags.set_tag('tag-1', 'rev-1')
1226
branch.tags.set_tag('tag-2', 'rev-2')
1227
self.addCleanup(branch.lock_read().unlock)
1228
# Disable the heads_to_fetch verb
1229
verb = 'Branch.heads_to_fetch'
1230
self.disable_verb(verb)
1231
self.reset_smart_call_log()
1232
result = branch.heads_to_fetch()
1233
self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1235
['Branch.last_revision_info', 'Branch.get_tags_bytes'],
1236
[call.call.method for call in self.hpss_calls])
1146
1239
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1148
1241
def test_empty_branch(self):
2775
2868
('pack collection autopack',)],
2871
def test_oom_error_reporting(self):
2872
"""An out-of-memory condition on the server is reported clearly"""
2873
transport_path = 'quack'
2874
repo, client = self.setup_fake_client_and_repository(transport_path)
2875
client.add_expected_call(
2876
'PackRepository.autopack', ('quack/',),
2877
'error', ('MemoryError',))
2878
err = self.assertRaises(errors.BzrError, repo.autopack)
2879
self.assertContainsRe(str(err), "^remote server out of mem")
2779
2882
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):
2780
2883
"""Base class for unit tests for bzrlib.remote._translate_error."""
2886
2996
expected_error = errors.DivergedBranches(branch, other_branch)
2887
2997
self.assertEqual(expected_error, translated_error)
2999
def test_NotStacked(self):
3000
branch = self.make_branch('')
3001
translated_error = self.translateTuple(('NotStacked',), branch=branch)
3002
expected_error = errors.NotStacked(branch)
3003
self.assertEqual(expected_error, translated_error)
2889
3005
def test_ReadError_no_args(self):
2890
3006
path = 'a path'
2891
3007
translated_error = self.translateTuple(('ReadError',), path=path)
2936
3053
expected_error = errors.PermissionDenied(path, extra)
2937
3054
self.assertEqual(expected_error, translated_error)
3056
# GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
3058
def test_NoSuchFile_context_path(self):
3059
local_path = "local path"
3060
translated_error = self.translateTuple(('ReadError', "remote path"),
3062
expected_error = errors.ReadError(local_path)
3063
self.assertEqual(expected_error, translated_error)
3065
def test_NoSuchFile_without_context(self):
3066
remote_path = "remote path"
3067
translated_error = self.translateTuple(('ReadError', remote_path))
3068
expected_error = errors.ReadError(remote_path)
3069
self.assertEqual(expected_error, translated_error)
3071
def test_ReadOnlyError(self):
3072
translated_error = self.translateTuple(('ReadOnlyError',))
3073
expected_error = errors.TransportNotPossible("readonly transport")
3074
self.assertEqual(expected_error, translated_error)
3076
def test_MemoryError(self):
3077
translated_error = self.translateTuple(('MemoryError',))
3078
self.assertStartsWith(str(translated_error),
3079
"remote server out of memory")
3081
def test_generic_IndexError_no_classname(self):
3082
err = errors.ErrorFromSmartServer(('error', "list index out of range"))
3083
translated_error = self.translateErrorFromSmartServer(err)
3084
expected_error = errors.UnknownErrorFromSmartServer(err)
3085
self.assertEqual(expected_error, translated_error)
3087
# GZ 2011-03-02: TODO test generic non-ascii error string
3089
def test_generic_KeyError(self):
3090
err = errors.ErrorFromSmartServer(('error', 'KeyError', "1"))
3091
translated_error = self.translateErrorFromSmartServer(err)
3092
expected_error = errors.UnknownErrorFromSmartServer(err)
3093
self.assertEqual(expected_error, translated_error)
2940
3096
class TestErrorTranslationRobustness(TestErrorTranslationBase):
2941
3097
"""Unit tests for bzrlib.remote._translate_error's robustness.