Created test case for using bytes and bytearray objects with files argument to Request.
authorRasmus Scholer (TimelineX) <rasmusscholer@gmail.com>
Tue, 3 Mar 2015 02:41:00 +0000 (03:41 +0100)
committerRasmus Scholer (TimelineX) <rasmusscholer@gmail.com>
Tue, 3 Mar 2015 02:41:00 +0000 (03:41 +0100)
test_requests.py

index 6e52784..4f38b04 100755 (executable)
@@ -935,6 +935,19 @@ class RequestsTestCase(unittest.TestCase):
 
         assert 'multipart/form-data' in p.headers['Content-Type']
 
+    def test_can_send_bytes_bytearray_objects_with_files(self):
+        # Test bytes:
+        data = {'a': 0.0}
+        files = {'b': b'foo'}
+        r = requests.Request('POST', httpbin('post'), data=data, files=files)
+        p = r.prepare()
+        assert 'multipart/form-data' in p.headers['Content-Type']
+        # Test bytearrays:
+        files = {'b': bytearray(b'foo')}
+        r = requests.Request('POST', httpbin('post'), data=data, files=files)
+        p = r.prepare()
+        assert 'multipart/form-data' in p.headers['Content-Type']
+
     def test_can_send_file_object_with_non_string_filename(self):
         f = io.BytesIO()
         f.name = 2