~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

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