~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 19:18:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216191839-eg681lxqibi1qxu1
Fix remaining tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        raise errors.NoSuchFile('xyzzy')
42
42
 
43
43
 
 
44
class DoUnexpectedErrorRequest(request.SmartServerRequest):
 
45
    """A request that encounters a generic error in self.do()"""
 
46
 
 
47
    def do(self):
 
48
        dict()[1]
 
49
 
 
50
 
44
51
class ChunkErrorRequest(request.SmartServerRequest):
45
52
    """A request that raises an error from self.do_chunk()."""
46
53
    
111
118
        self.assertEqual(
112
119
            [[transport]] * 3, handler._command.jail_transports_log)
113
120
 
 
121
    def test_all_registered_requests_are_safety_qualified(self):
 
122
        unclassified_requests = []
 
123
        allowed_info = ('read', 'idem', 'mutate', 'semivfs', 'semi', 'stream')
 
124
        for key in request.request_handlers.keys():
 
125
            info = request.request_handlers.get_info(key)
 
126
            if info is None or info not in allowed_info:
 
127
                unclassified_requests.append(key)
 
128
        if unclassified_requests:
 
129
            self.fail('These requests were not categorized as safe/unsafe'
 
130
                      ' to retry: %s'  % (unclassified_requests,))
114
131
 
115
132
 
116
133
class TestSmartRequestHandlerErrorTranslation(TestCase):
149
166
        handler.end_received()
150
167
        self.assertResponseIsTranslatedError(handler)
151
168
 
 
169
    def test_unexpected_error_translation(self):
 
170
        handler = request.SmartServerRequestHandler(
 
171
            None, {'foo': DoUnexpectedErrorRequest}, '/')
 
172
        handler.args_received(('foo',))
 
173
        self.assertEqual(
 
174
            request.FailedSmartServerResponse(('error', 'KeyError', "1")),
 
175
            handler.response)
 
176
 
152
177
 
153
178
class TestRequestHanderErrorTranslation(TestCase):
154
179
    """Tests for bzrlib.smart.request._translate_error."""
172
197
            ('TokenMismatch', 'some-token', 'actual-token'),
173
198
            errors.TokenMismatch('some-token', 'actual-token'))
174
199
 
 
200
    def test_MemoryError(self):
 
201
        self.assertTranslationEqual(("MemoryError",), MemoryError())
 
202
 
 
203
    def test_generic_Exception(self):
 
204
        self.assertTranslationEqual(('error', 'Exception', ""),
 
205
            Exception())
 
206
 
 
207
    def test_generic_BzrError(self):
 
208
        self.assertTranslationEqual(('error', 'BzrError', "some text"),
 
209
            errors.BzrError(msg="some text"))
 
210
 
 
211
    def test_generic_zlib_error(self):
 
212
        from zlib import error
 
213
        msg = "Error -3 while decompressing data: incorrect data check"
 
214
        self.assertTranslationEqual(('error', 'zlib.error', msg),
 
215
            error(msg))
 
216
 
175
217
 
176
218
class TestRequestJail(TestCaseWithMemoryTransport):
177
219
 
208
250
        self.assertRaises(errors.JailBreak, _pre_open_hook, t.clone('..'))
209
251
        # A completely unrelated transport is not allowed
210
252
        self.assertRaises(errors.JailBreak, _pre_open_hook,
211
 
                          transport.get_transport('http://host/'))
 
253
                          transport.get_transport_from_url('http://host/'))
212
254
 
213
255
    def test_open_bzrdir_in_non_main_thread(self):
214
256
        """Opening a bzrdir in a non-main thread should work ok.