153
154
r = BzrDir.open_from_transport(t.clone('stackable')).open_repository()
154
155
self.assertTrue(r._format.supports_external_lookups)
157
def test_remote_branch_set_append_revisions_only(self):
158
# Make a format 1.9 branch, which supports append_revisions_only
159
branch = self.make_branch('branch', format='1.9')
160
config = branch.get_config()
161
branch.set_append_revisions_only(True)
163
'True', config.get_user_option('append_revisions_only'))
164
branch.set_append_revisions_only(False)
166
'False', config.get_user_option('append_revisions_only'))
168
def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
169
branch = self.make_branch('branch', format='knit')
170
config = branch.get_config()
172
errors.UpgradeRequired, branch.set_append_revisions_only, True)
157
175
class FakeProtocol(object):
158
176
"""Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
741
759
self.assertEqual(network_name, repo._format.network_name())
762
class TestBzrDirFormatInitializeEx(TestRemote):
764
def test_success(self):
765
"""Simple test for typical successful call."""
766
fmt = bzrdir.RemoteBzrDirFormat()
767
default_format_name = BzrDirFormat.get_default_format().network_name()
768
transport = self.get_transport()
769
client = FakeClient(transport.base)
770
client.add_expected_call(
771
'BzrDirFormat.initialize_ex_1.16',
772
(default_format_name, 'path', 'False', 'False', 'False', '',
773
'', '', '', 'False'),
775
('.', 'no', 'no', 'yes', 'repo fmt', 'repo bzrdir fmt',
776
'bzrdir fmt', 'False', '', '', 'repo lock token'))
777
# XXX: It would be better to call fmt.initialize_on_transport_ex, but
778
# it's currently hard to test that without supplying a real remote
779
# transport connected to a real server.
780
result = fmt._initialize_on_transport_ex_rpc(client, 'path',
781
transport, False, False, False, None, None, None, None, False)
782
client.finished_test()
784
def test_error(self):
785
"""Error responses are translated, e.g. 'PermissionDenied' raises the
786
corresponding error from the client.
788
fmt = bzrdir.RemoteBzrDirFormat()
789
default_format_name = BzrDirFormat.get_default_format().network_name()
790
transport = self.get_transport()
791
client = FakeClient(transport.base)
792
client.add_expected_call(
793
'BzrDirFormat.initialize_ex_1.16',
794
(default_format_name, 'path', 'False', 'False', 'False', '',
795
'', '', '', 'False'),
797
('PermissionDenied', 'path', 'extra info'))
798
# XXX: It would be better to call fmt.initialize_on_transport_ex, but
799
# it's currently hard to test that without supplying a real remote
800
# transport connected to a real server.
801
err = self.assertRaises(errors.PermissionDenied,
802
fmt._initialize_on_transport_ex_rpc, client, 'path', transport,
803
False, False, False, None, None, None, None, False)
804
self.assertEqual('path', err.path)
805
self.assertEqual(': extra info', err.extra)
806
client.finished_test()
808
def test_error_from_real_server(self):
809
"""Integration test for error translation."""
810
transport = self.make_smart_server('foo')
811
transport = transport.clone('no-such-path')
812
fmt = bzrdir.RemoteBzrDirFormat()
813
err = self.assertRaises(errors.NoSuchFile,
814
fmt.initialize_on_transport_ex, transport, create_prefix=False)
744
817
class OldSmartClient(object):
745
818
"""A fake smart client for test_old_version that just returns a version one
746
819
response to the 'hello' (query version) command.
1963
2036
self.assertEqual(('AnUnexpectedError',), e.error_tuple)
2039
class TestRepositoryGetRevIdForRevno(TestRemoteRepository):
2042
repo, client = self.setup_fake_client_and_repository('quack')
2043
client.add_expected_call(
2044
'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2045
'success', ('ok', 'rev-five'))
2046
result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2047
self.assertEqual((True, 'rev-five'), result)
2048
client.finished_test()
2050
def test_history_incomplete(self):
2051
repo, client = self.setup_fake_client_and_repository('quack')
2052
client.add_expected_call(
2053
'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2054
'success', ('history-incomplete', 10, 'rev-ten'))
2055
result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2056
self.assertEqual((False, (10, 'rev-ten')), result)
2057
client.finished_test()
2059
def test_history_incomplete_with_fallback(self):
2060
"""A 'history-incomplete' response causes the fallback repository to be
2061
queried too, if one is set.
2063
# Make a repo with a fallback repo, both using a FakeClient.
2064
format = remote.response_tuple_to_repo_format(
2065
('yes', 'no', 'yes', 'fake-network-name'))
2066
repo, client = self.setup_fake_client_and_repository('quack')
2067
repo._format = format
2068
fallback_repo, ignored = self.setup_fake_client_and_repository(
2070
fallback_repo._client = client
2071
repo.add_fallback_repository(fallback_repo)
2072
# First the client should ask the primary repo
2073
client.add_expected_call(
2074
'Repository.get_rev_id_for_revno', ('quack/', 1, (42, 'rev-foo')),
2075
'success', ('history-incomplete', 2, 'rev-two'))
2076
# Then it should ask the fallback, using revno/revid from the
2077
# history-incomplete response as the known revno/revid.
2078
client.add_expected_call(
2079
'Repository.get_rev_id_for_revno',('fallback/', 1, (2, 'rev-two')),
2080
'success', ('ok', 'rev-one'))
2081
result = repo.get_rev_id_for_revno(1, (42, 'rev-foo'))
2082
self.assertEqual((True, 'rev-one'), result)
2083
client.finished_test()
2085
def test_nosuchrevision(self):
2086
# 'nosuchrevision' is returned when the known-revid is not found in the
2087
# remote repo. The client translates that response to NoSuchRevision.
2088
repo, client = self.setup_fake_client_and_repository('quack')
2089
client.add_expected_call(
2090
'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2091
'error', ('nosuchrevision', 'rev-foo'))
2093
errors.NoSuchRevision,
2094
repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2095
client.finished_test()
1966
2098
class TestRepositoryIsShared(TestRemoteRepository):
1968
2100
def test_is_shared(self):