~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Jelmer Vernooij
  • Date: 2011-03-03 12:50:21 UTC
  • mfrom: (5697 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5703.
  • Revision ID: jelmer@samba.org-20110303125021-ziry6a0qsr9l72x5
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
724
724
        format = branch._format
725
725
        self.assertEqual(network_name, format.network_name())
726
726
 
 
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.
 
730
        """
 
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(),
 
747
            _client=client)
 
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())
 
754
 
727
755
 
728
756
class TestBzrDirCreateRepository(TestRemote):
729
757
 
1143
1171
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1144
1172
 
1145
1173
 
 
1174
class TestBranchHeadsToFetch(RemoteBranchTestCase):
 
1175
 
 
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)
 
1195
        self.assertEqual(
 
1196
            (set(['rev-tip']), set(['rev-foo', 'rev-bar'])), result)
 
1197
 
 
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)
 
1214
 
 
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)
 
1234
        self.assertEqual(
 
1235
            ['Branch.last_revision_info', 'Branch.get_tags_bytes'],
 
1236
            [call.call.method for call in self.hpss_calls])
 
1237
 
 
1238
 
1146
1239
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1147
1240
 
1148
1241
    def test_empty_branch(self):
2775
2868
             ('pack collection autopack',)],
2776
2869
            client._calls)
2777
2870
 
 
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")
 
2880
 
2778
2881
 
2779
2882
class TestErrorTranslationBase(tests.TestCaseWithMemoryTransport):
2780
2883
    """Base class for unit tests for bzrlib.remote._translate_error."""
2853
2956
            detail='extra detail')
2854
2957
        self.assertEqual(expected_error, translated_error)
2855
2958
 
 
2959
    def test_norepository(self):
 
2960
        bzrdir = self.make_bzrdir('')
 
2961
        translated_error = self.translateTuple(('norepository',),
 
2962
            bzrdir=bzrdir)
 
2963
        expected_error = errors.NoRepositoryPresent(bzrdir)
 
2964
        self.assertEqual(expected_error, translated_error)
 
2965
 
2856
2966
    def test_LockContention(self):
2857
2967
        translated_error = self.translateTuple(('LockContention',))
2858
2968
        expected_error = errors.LockContention('(remote lock)')
2886
2996
        expected_error = errors.DivergedBranches(branch, other_branch)
2887
2997
        self.assertEqual(expected_error, translated_error)
2888
2998
 
 
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)
 
3004
 
2889
3005
    def test_ReadError_no_args(self):
2890
3006
        path = 'a path'
2891
3007
        translated_error = self.translateTuple(('ReadError',), path=path)
2907
3023
 
2908
3024
    def test_PermissionDenied_no_args(self):
2909
3025
        path = 'a path'
2910
 
        translated_error = self.translateTuple(('PermissionDenied',), path=path)
 
3026
        translated_error = self.translateTuple(('PermissionDenied',),
 
3027
            path=path)
2911
3028
        expected_error = errors.PermissionDenied(path)
2912
3029
        self.assertEqual(expected_error, translated_error)
2913
3030
 
2936
3053
        expected_error = errors.PermissionDenied(path, extra)
2937
3054
        self.assertEqual(expected_error, translated_error)
2938
3055
 
 
3056
    # GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
 
3057
 
 
3058
    def test_NoSuchFile_context_path(self):
 
3059
        local_path = "local path"
 
3060
        translated_error = self.translateTuple(('ReadError', "remote path"),
 
3061
            path=local_path)
 
3062
        expected_error = errors.ReadError(local_path)
 
3063
        self.assertEqual(expected_error, translated_error)
 
3064
 
 
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)
 
3070
 
 
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)
 
3075
 
 
3076
    def test_MemoryError(self):
 
3077
        translated_error = self.translateTuple(('MemoryError',))
 
3078
        self.assertStartsWith(str(translated_error),
 
3079
            "remote server out of memory")
 
3080
 
 
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)
 
3086
 
 
3087
    # GZ 2011-03-02: TODO test generic non-ascii error string
 
3088
 
 
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)
 
3094
 
2939
3095
 
2940
3096
class TestErrorTranslationRobustness(TestErrorTranslationBase):
2941
3097
    """Unit tests for bzrlib.remote._translate_error's robustness.