/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_wsgi.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for WSGI application"""
18
18
 
19
 
from cStringIO import StringIO
20
 
 
21
 
from breezy import tests
22
 
from breezy.smart import medium, protocol
23
 
from breezy.transport.http import wsgi
24
 
from breezy.transport import chroot, memory
 
19
from .. import tests
 
20
from ..sixish import (
 
21
    BytesIO,
 
22
    )
 
23
from ..smart import medium, protocol
 
24
from ..transport.http import wsgi
 
25
from ..transport import chroot, memory
25
26
 
26
27
 
27
28
class WSGITestMixin(object):
44
45
            # Required WSGI variables
45
46
            'wsgi.version': (1,0),
46
47
            'wsgi.url_scheme': 'http',
47
 
            'wsgi.input': StringIO(''),
48
 
            'wsgi.errors': StringIO(),
 
48
            'wsgi.input': BytesIO(b''),
 
49
            'wsgi.errors': BytesIO(),
49
50
            'wsgi.multithread': False,
50
51
            'wsgi.multiprocess': False,
51
52
            'wsgi.run_once': True,
100
101
        wsgi_app = wsgi.SmartWSGIApp(transport)
101
102
        wsgi_app.backing_transport = transport
102
103
        wsgi_app.make_request = self._fake_make_request
103
 
        fake_input = StringIO('fake request')
 
104
        fake_input = BytesIO(b'fake request')
104
105
        environ = self.build_environ({
105
106
            'REQUEST_METHOD': 'POST',
106
107
            'CONTENT_LENGTH': len(fake_input.getvalue()),
119
120
        transport.put_bytes('foo', 'some bytes')
120
121
        wsgi_app = wsgi.SmartWSGIApp(transport)
121
122
        wsgi_app.make_request = self._fake_make_request
122
 
        fake_input = StringIO('fake request')
 
123
        fake_input = BytesIO(b'fake request')
123
124
        environ = self.build_environ({
124
125
            'REQUEST_METHOD': 'POST',
125
126
            'CONTENT_LENGTH': len(fake_input.getvalue()),
195
196
            return request
196
197
        wsgi_app.make_request = make_request
197
198
 
198
 
        fake_input = StringIO('incomplete request')
 
199
        fake_input = BytesIO(b'incomplete request')
199
200
        environ = self.build_environ({
200
201
            'REQUEST_METHOD': 'POST',
201
202
            'CONTENT_LENGTH': len(fake_input.getvalue()),
212
213
        # REQUEST_VERSION_TWO as version one.
213
214
        transport = memory.MemoryTransport()
214
215
        wsgi_app = wsgi.SmartWSGIApp(transport)
215
 
        fake_input = StringIO('hello\n')
 
216
        fake_input = BytesIO(b'hello\n')
216
217
        environ = self.build_environ({
217
218
            'REQUEST_METHOD': 'POST',
218
219
            'CONTENT_LENGTH': len(fake_input.getvalue()),
230
231
        # as version two.
231
232
        transport = memory.MemoryTransport()
232
233
        wsgi_app = wsgi.SmartWSGIApp(transport)
233
 
        fake_input = StringIO(protocol.REQUEST_VERSION_TWO + 'hello\n')
 
234
        fake_input = BytesIO(protocol.REQUEST_VERSION_TWO + 'hello\n')
234
235
        environ = self.build_environ({
235
236
            'REQUEST_METHOD': 'POST',
236
237
            'CONTENT_LENGTH': len(fake_input.getvalue()),
248
249
class TestWSGIJail(tests.TestCaseWithMemoryTransport, WSGITestMixin):
249
250
 
250
251
    def make_hpss_wsgi_request(self, wsgi_relpath, *args):
251
 
        write_buf = StringIO()
 
252
        write_buf = BytesIO()
252
253
        request_medium = medium.SmartSimplePipesClientMedium(
253
254
            None, write_buf, 'fake:' + wsgi_relpath)
254
255
        request_encoder = protocol.ProtocolThreeRequester(