pyramid_cubicweb/tests/test_bw_request.py
changeset 11630 1400aee10df4
parent 11611 9d2bb6bdb5c8
equal deleted inserted replaced
11629:0459094d9728 11630:1400aee10df4
     1 # -*- coding: utf-8 -*-
     1 # -*- coding: utf-8 -*-
     2 from StringIO import StringIO
     2 from io import BytesIO
     3 
     3 
     4 import webtest
     4 import webtest
     5 
     5 
     6 import pyramid.request
     6 import pyramid.request
     7 
     7 
    27     def test_content_body(self):
    27     def test_content_body(self):
    28         req = CubicWebPyramidRequest(
    28         req = CubicWebPyramidRequest(
    29             self.make_request('/', {
    29             self.make_request('/', {
    30                 'CONTENT_LENGTH': 12,
    30                 'CONTENT_LENGTH': 12,
    31                 'CONTENT_TYPE': 'text/plain',
    31                 'CONTENT_TYPE': 'text/plain',
    32                 'wsgi.input': StringIO('some content')}))
    32                 'wsgi.input': BytesIO(b'some content')}))
    33 
    33 
    34         self.assertEqual('some content', req.content.read())
    34         self.assertEqual(b'some content', req.content.read())
    35 
    35 
    36     def test_http_scheme(self):
    36     def test_http_scheme(self):
    37         req = CubicWebPyramidRequest(
    37         req = CubicWebPyramidRequest(
    38             self.make_request('/', {
    38             self.make_request('/', {
    39                 'wsgi.url_scheme': 'http'}))
    39                 'wsgi.url_scheme': 'http'}))
    47 
    47 
    48         self.assertTrue(req.https)
    48         self.assertTrue(req.https)
    49 
    49 
    50     def test_https_prefix(self):
    50     def test_https_prefix(self):
    51         r = self.webapp.get('/https/')
    51         r = self.webapp.get('/https/')
    52         self.assertIn('https://', r.body)
    52         self.assertIn('https://', r.text)
    53 
    53 
    54     def test_big_content(self):
    54     def test_big_content(self):
    55         content = 'x'*100001
    55         content = b'x'*100001
    56 
    56 
    57         req = CubicWebPyramidRequest(
    57         req = CubicWebPyramidRequest(
    58             self.make_request('/', {
    58             self.make_request('/', {
    59                 'CONTENT_LENGTH': len(content),
    59                 'CONTENT_LENGTH': len(content),
    60                 'CONTENT_TYPE': 'text/plain',
    60                 'CONTENT_TYPE': 'text/plain',
    61                 'wsgi.input': StringIO(content)}))
    61                 'wsgi.input': BytesIO(content)}))
    62 
    62 
    63         self.assertEqual(content, req.content.read())
    63         self.assertEqual(content, req.content.read())
    64 
    64 
    65     def test_post(self):
    65     def test_post(self):
    66         self.webapp.post(
    66         self.webapp.post(
    79 
    79 
    80         self.assertEqual([u'1', u'2'], req.form['arg'])
    80         self.assertEqual([u'1', u'2'], req.form['arg'])
    81 
    81 
    82     def test_post_files(self):
    82     def test_post_files(self):
    83         content_type, params = self.webapp.encode_multipart(
    83         content_type, params = self.webapp.encode_multipart(
    84             (), (('filefield', 'aname', 'acontent'),))
    84             (), (('filefield', 'aname', b'acontent'),))
    85         req = CubicWebPyramidRequest(
    85         req = CubicWebPyramidRequest(
    86             self.make_request('/', POST=params, content_type=content_type))
    86             self.make_request('/', POST=params, content_type=content_type))
    87         self.assertIn('filefield', req.form)
    87         self.assertIn('filefield', req.form)
    88         fieldvalue = req.form['filefield']
    88         fieldvalue = req.form['filefield']
    89         self.assertEqual(u'aname', fieldvalue[0])
    89         self.assertEqual(u'aname', fieldvalue[0])
    90         self.assertEqual('acontent', fieldvalue[1].read())
    90         self.assertEqual(b'acontent', fieldvalue[1].read())
    91 
    91 
    92     def test_post_unicode_urlencoded(self):
    92     def test_post_unicode_urlencoded(self):
    93         params = 'arg=%C3%A9'
    93         params = 'arg=%C3%A9'
    94         req = CubicWebPyramidRequest(
    94         req = CubicWebPyramidRequest(
    95             self.make_request(
    95             self.make_request(