Michael Merickel avatar Michael Merickel committed 5254e98

Banged out a bunch of unit tests expected Request.body to return a native string.

Comments (0)

Files changed (1)

tests/test_request.py

         req = BaseRequest(environ)
         assert req.body_file_raw is INPUT
         assert req.body_file is not INPUT
-        assert req.body_file.read() == ''
+        assert req.body_file.read() == b''
 
     def test_body_file_setter_w_string(self):
         BEFORE = self._makeBytesIO(b'before')
                   }
         req = BaseRequest(environ)
         del req.body_file
-        self.assertEqual(req.body_file.getvalue(), '')
+        self.assertEqual(req.body_file.getvalue(), b'')
         self.assertEqual(req.content_length, 0)
 
     def test_body_file_raw(self):
         req = BaseRequest(environ)
         seekable = req.body_file_seekable
         self.assertTrue(seekable is not INPUT)
-        self.assertEqual(seekable.getvalue(), 'input')
+        self.assertEqual(seekable.getvalue(), b'input')
 
     def test_body_file_seekable_input_is_seekable(self):
         INPUT = self._makeBytesIO(b'input')
                    'REQUEST_METHOD': 'POST'
                   }
         req = BaseRequest(environ)
-        self.assertEqual(req.body, 'input')
+        self.assertEqual(req.body, b'input')
         self.assertEqual(req.content_length, len('input'))
     def test_body_setter_None(self):
         INPUT = self._makeBytesIO(b'input')
                   }
         req = BaseRequest(environ)
         req.body = None
-        self.assertEqual(req.body, '')
+        self.assertEqual(req.body, b'')
         self.assertEqual(req.content_length, 0)
         self.assertTrue(req.is_body_seekable)
     def test_body_setter_non_string_raises(self):
                   }
         req = BaseRequest(environ)
         req.body = b'after'
-        self.assertEqual(req.body, 'after')
+        self.assertEqual(req.body, b'after')
         self.assertEqual(req.content_length, len('after'))
         self.assertTrue(req.is_body_seekable)
     def test_body_setter_GET(self):
                   }
         req = BaseRequest(environ)
         del req.body
-        self.assertEqual(req.body, '')
+        self.assertEqual(req.body, b'')
         self.assertEqual(req.content_length, 0)
         self.assertTrue(req.is_body_seekable)
 
         old_body_file = req.body_file_raw
         req.make_body_seekable()
         self.assertTrue(req.body_file_raw is not old_body_file)
-        self.assertEqual(req.body, '0123456789')
+        self.assertEqual(req.body, b'0123456789')
         old_body_file = req.body_file
         req.make_body_seekable()
         self.assertTrue(req.body_file_raw is old_body_file)
         old_body_file = req.body_file
         req2 = req.copy()
         self.assertTrue(req2.body_file_raw is req2.body_file is not old_body_file)
-        self.assertEqual(req2.body, '0123456789')
+        self.assertEqual(req2.body, b'0123456789')
 
     def test_set_body(self):
         from webob import BaseRequest
         self.assertRaises(TypeError,
                           setattr, r, 'body', six.text_type('hello world'))
         r.body = None
-        self.assertEqual(r.body, '')
+        self.assertEqual(r.body, b'')
         r = Request({'a':1}, method='PUT', body_file=DummyBytesIO(ascii_letters))
         self.assertTrue(not hasattr(r.body_file_raw, 'seek'))
         r.make_body_seekable()
         self.assertEqual(req.get('CONTENT_LENGTH', None),'11')
         self.assertEqual(req.get('CONTENT_TYPE', None),
                          'application/x-www-form-urlencoded')
-        self.assertEqual(req['wsgi.input'].read(), 'hello=world')
+        self.assertEqual(req['wsgi.input'].read(), b'hello=world')
 
 
     def test_post_does_not_reparse(self):
     def test_body_file_noseek(self):
         req = Request.blank('/', method='PUT', body=b'abc')
         lst = [req.body_file.read(1) for i in range(3)]
-        self.assertEqual(lst, ['a','b','c'])
+        self.assertEqual(lst, [b'a',b'b',b'c'])
 
     def test_cgi_escaping_fix(self):
         req = Request.blank('/',
         from webob.request import FakeCGIBody
         body = FakeCGIBody({'bananas': 'bananas'}, 'multipart/form-data; boundary=foobar')
         self.assertEqual(list(body), [
-            '--foobar\r\n',
-             'Content-Disposition: form-data; name="bananas"\r\n',
-             '\r\n',
-             'bananas\r\n',
-             '--foobar--',
+            b'--foobar\r\n',
+            b'Content-Disposition: form-data; name="bananas"\r\n',
+            b'\r\n',
+            b'bananas\r\n',
+            b'--foobar--',
          ])
 
     def test_readline(self):
         from webob.request import FakeCGIBody
         body = FakeCGIBody({'bananas': 'bananas'}, 'multipart/form-data; boundary=foobar')
-        self.assertEqual(body.readline(), '--foobar\r\n')
-        self.assertEqual(body.readline(), 'Content-Disposition: form-data; name="bananas"\r\n')
-        self.assertEqual(body.readline(), '\r\n')
-        self.assertEqual(body.readline(), 'bananas\r\n')
-        self.assertEqual(body.readline(), '--foobar--')
+        self.assertEqual(body.readline(), b'--foobar\r\n')
+        self.assertEqual(body.readline(), b'Content-Disposition: form-data; name="bananas"\r\n')
+        self.assertEqual(body.readline(), b'\r\n')
+        self.assertEqual(body.readline(), b'bananas\r\n')
+        self.assertEqual(body.readline(), b'--foobar--')
         # subsequent calls to readline will return ''
 
     def test_read_bad_content_type(self):
     def test_read_urlencoded(self):
         from webob.request import FakeCGIBody
         body = FakeCGIBody({'bananas': 'bananas'}, 'application/x-www-form-urlencoded')
-        self.assertEqual(body.read(), 'bananas=bananas')
+        self.assertEqual(body.read(), b'bananas=bananas')
 
     def test_tell(self):
         from webob.request import FakeCGIBody
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.