~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 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 errors
 
21
from bzrlib import (
 
22
    errors,
 
23
    transport,
 
24
    )
22
25
from bzrlib.bzrdir import BzrDir
23
26
from bzrlib.smart import request
24
27
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
25
 
from bzrlib.transport import get_transport
26
28
 
27
29
 
28
30
class NoBodyRequest(request.SmartServerRequest):
34
36
 
35
37
class DoErrorRequest(request.SmartServerRequest):
36
38
    """A request that raises an error from self.do()."""
37
 
    
 
39
 
38
40
    def do(self):
39
41
        raise errors.NoSuchFile('xyzzy')
40
42
 
159
161
            ('NoSuchFile', 'path'), errors.NoSuchFile('path'))
160
162
 
161
163
    def test_LockContention(self):
 
164
        # For now, LockContentions are always transmitted with no details.
 
165
        # Eventually they should include a relpath or url or something else to
 
166
        # identify which lock is busy.
162
167
        self.assertTranslationEqual(
163
 
            ('LockContention', 'lock', 'msg'),
164
 
            errors.LockContention('lock', 'msg'))
 
168
            ('LockContention',), errors.LockContention('lock', 'msg'))
165
169
 
166
170
    def test_TokenMismatch(self):
167
171
        self.assertTranslationEqual(
170
174
 
171
175
 
172
176
class TestRequestJail(TestCaseWithMemoryTransport):
173
 
    
 
177
 
174
178
    def test_jail(self):
175
179
        transport = self.get_transport('blah')
176
180
        req = request.SmartServerRequest(transport)
199
203
        # A child of a transport in jail_info is allowed
200
204
        _pre_open_hook(t.clone('child'))
201
205
        # A parent is not allowed
202
 
        self.assertRaises(errors.BzrError, _pre_open_hook, t.clone('..'))
 
206
        self.assertRaises(errors.JailBreak, _pre_open_hook, t.clone('..'))
203
207
        # A completely unrelated transport is not allowed
204
 
        self.assertRaises(
205
 
            errors.BzrError, _pre_open_hook, get_transport('http://host/'))
 
208
        self.assertRaises(errors.JailBreak, _pre_open_hook,
 
209
                          transport.get_transport('http://host/'))
206
210
 
207
211
    def test_open_bzrdir_in_non_main_thread(self):
208
212
        """Opening a bzrdir in a non-main thread should work ok.