~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-12 18:05:15 UTC
  • mto: (4371.4.5 vila-better-heads)
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090612180515-t0cwbjsnve094oik
Add a failing test for handling nodes that are in the same linear chain.

It fails because the ancestry skipping causes us to miss the fact that the two nodes
are actually directly related. We could check at the beginning, as the 
code used to do, but I think that will be incomplete for the more-than-two
heads cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
 
19
19
import threading
20
20
 
21
 
from bzrlib import (
22
 
    errors,
23
 
    transport,
24
 
    )
 
21
from bzrlib import errors
25
22
from bzrlib.bzrdir import BzrDir
26
23
from bzrlib.smart import request
27
24
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
 
25
from bzrlib.transport import get_transport
28
26
 
29
27
 
30
28
class NoBodyRequest(request.SmartServerRequest):
36
34
 
37
35
class DoErrorRequest(request.SmartServerRequest):
38
36
    """A request that raises an error from self.do()."""
39
 
 
 
37
    
40
38
    def do(self):
41
39
        raise errors.NoSuchFile('xyzzy')
42
40
 
43
41
 
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
 
 
51
42
class ChunkErrorRequest(request.SmartServerRequest):
52
43
    """A request that raises an error from self.do_chunk()."""
53
44
    
156
147
        handler.end_received()
157
148
        self.assertResponseIsTranslatedError(handler)
158
149
 
159
 
    def test_unexpected_error_translation(self):
160
 
        handler = request.SmartServerRequestHandler(
161
 
            None, {'foo': DoUnexpectedErrorRequest}, '/')
162
 
        handler.args_received(('foo',))
163
 
        self.assertEqual(
164
 
            request.FailedSmartServerResponse(('error', 'KeyError', "1")),
165
 
            handler.response)
166
 
 
167
150
 
168
151
class TestRequestHanderErrorTranslation(TestCase):
169
152
    """Tests for bzrlib.smart.request._translate_error."""
176
159
            ('NoSuchFile', 'path'), errors.NoSuchFile('path'))
177
160
 
178
161
    def test_LockContention(self):
179
 
        # For now, LockContentions are always transmitted with no details.
180
 
        # Eventually they should include a relpath or url or something else to
181
 
        # identify which lock is busy.
182
162
        self.assertTranslationEqual(
183
 
            ('LockContention',), errors.LockContention('lock', 'msg'))
 
163
            ('LockContention', 'lock', 'msg'),
 
164
            errors.LockContention('lock', 'msg'))
184
165
 
185
166
    def test_TokenMismatch(self):
186
167
        self.assertTranslationEqual(
187
168
            ('TokenMismatch', 'some-token', 'actual-token'),
188
169
            errors.TokenMismatch('some-token', 'actual-token'))
189
170
 
190
 
    def test_MemoryError(self):
191
 
        self.assertTranslationEqual(("MemoryError",), MemoryError())
192
 
 
193
 
    def test_generic_Exception(self):
194
 
        self.assertTranslationEqual(('error', 'Exception', ""),
195
 
            Exception())
196
 
 
197
 
    def test_generic_BzrError(self):
198
 
        self.assertTranslationEqual(('error', 'BzrError', "some text"),
199
 
            errors.BzrError(msg="some text"))
200
 
 
201
 
    def test_generic_zlib_error(self):
202
 
        from zlib import error
203
 
        msg = "Error -3 while decompressing data: incorrect data check"
204
 
        self.assertTranslationEqual(('error', 'zlib.error', msg),
205
 
            error(msg))
206
 
 
207
171
 
208
172
class TestRequestJail(TestCaseWithMemoryTransport):
209
 
 
 
173
    
210
174
    def test_jail(self):
211
175
        transport = self.get_transport('blah')
212
176
        req = request.SmartServerRequest(transport)
219
183
 
220
184
class TestJailHook(TestCaseWithMemoryTransport):
221
185
 
222
 
    def setUp(self):
223
 
        super(TestJailHook, self).setUp()
224
 
        def clear_jail_info():
225
 
            request.jail_info.transports = None
226
 
        self.addCleanup(clear_jail_info)
 
186
    def tearDown(self):
 
187
        request.jail_info.transports = None
 
188
        TestCaseWithMemoryTransport.tearDown(self)
227
189
 
228
190
    def test_jail_hook(self):
229
191
        request.jail_info.transports = None
239
201
        # A parent is not allowed
240
202
        self.assertRaises(errors.JailBreak, _pre_open_hook, t.clone('..'))
241
203
        # A completely unrelated transport is not allowed
242
 
        self.assertRaises(errors.JailBreak, _pre_open_hook,
243
 
                          transport.get_transport('http://host/'))
 
204
        self.assertRaises(
 
205
            errors.JailBreak, _pre_open_hook, get_transport('http://host/'))
244
206
 
245
207
    def test_open_bzrdir_in_non_main_thread(self):
246
208
        """Opening a bzrdir in a non-main thread should work ok.