~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-16 13:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090616135714-8o7jdtqqsfuv914z
The new code removes a get_parent_map call.

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
 
161
159
            ('NoSuchFile', 'path'), errors.NoSuchFile('path'))
162
160
 
163
161
    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.
167
162
        self.assertTranslationEqual(
168
 
            ('LockContention',), errors.LockContention('lock', 'msg'))
 
163
            ('LockContention', 'lock', 'msg'),
 
164
            errors.LockContention('lock', 'msg'))
169
165
 
170
166
    def test_TokenMismatch(self):
171
167
        self.assertTranslationEqual(
174
170
 
175
171
 
176
172
class TestRequestJail(TestCaseWithMemoryTransport):
177
 
 
 
173
    
178
174
    def test_jail(self):
179
175
        transport = self.get_transport('blah')
180
176
        req = request.SmartServerRequest(transport)
187
183
 
188
184
class TestJailHook(TestCaseWithMemoryTransport):
189
185
 
190
 
    def setUp(self):
191
 
        super(TestJailHook, self).setUp()
192
 
        def clear_jail_info():
193
 
            request.jail_info.transports = None
194
 
        self.addCleanup(clear_jail_info)
 
186
    def tearDown(self):
 
187
        request.jail_info.transports = None
 
188
        TestCaseWithMemoryTransport.tearDown(self)
195
189
 
196
190
    def test_jail_hook(self):
197
191
        request.jail_info.transports = None
207
201
        # A parent is not allowed
208
202
        self.assertRaises(errors.JailBreak, _pre_open_hook, t.clone('..'))
209
203
        # A completely unrelated transport is not allowed
210
 
        self.assertRaises(errors.JailBreak, _pre_open_hook,
211
 
                          transport.get_transport('http://host/'))
 
204
        self.assertRaises(
 
205
            errors.JailBreak, _pre_open_hook, get_transport('http://host/'))
212
206
 
213
207
    def test_open_bzrdir_in_non_main_thread(self):
214
208
        """Opening a bzrdir in a non-main thread should work ok.