~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

  • Committer: Martin Pool
  • Date: 2009-09-14 02:30:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4693.
  • Revision ID: mbp@sourcefrog.net-20090914023023-ros0f3ndo04j3bww
Clearer docs about bzr help.  (Thanks to Naoki)

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
 
174
172
 
175
173
 
176
174
class TestRequestJail(TestCaseWithMemoryTransport):
177
 
 
 
175
    
178
176
    def test_jail(self):
179
177
        transport = self.get_transport('blah')
180
178
        req = request.SmartServerRequest(transport)
187
185
 
188
186
class TestJailHook(TestCaseWithMemoryTransport):
189
187
 
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)
 
188
    def tearDown(self):
 
189
        request.jail_info.transports = None
 
190
        TestCaseWithMemoryTransport.tearDown(self)
195
191
 
196
192
    def test_jail_hook(self):
197
193
        request.jail_info.transports = None
207
203
        # A parent is not allowed
208
204
        self.assertRaises(errors.JailBreak, _pre_open_hook, t.clone('..'))
209
205
        # A completely unrelated transport is not allowed
210
 
        self.assertRaises(errors.JailBreak, _pre_open_hook,
211
 
                          transport.get_transport('http://host/'))
 
206
        self.assertRaises(
 
207
            errors.JailBreak, _pre_open_hook, get_transport('http://host/'))
212
208
 
213
209
    def test_open_bzrdir_in_non_main_thread(self):
214
210
        """Opening a bzrdir in a non-main thread should work ok.