added mutlipart file=strings

This commit is contained in:
barberj
2012-04-20 22:15:35 -04:00
committed by Shivaram Lingamneni
parent 7b6338c4b6
commit ed7b14899f
2 changed files with 18 additions and 1 deletions
+3 -1
View File
@@ -32,7 +32,7 @@ from .utils import (
DEFAULT_CA_BUNDLE_PATH)
from .compat import (
cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,
is_py2)
StringIO, is_py2)
# Import chardet if it is available.
try:
@@ -348,6 +348,8 @@ class Request(object):
else:
fn = guess_filename(v) or k
fp = v
if isinstance(fp, bytes):
fp = StringIO(fp)
fields.update({k: (fn, fp.read())})
(body, content_type) = encode_multipart_formdata(fields)
+15
View File
@@ -329,6 +329,21 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
self.assertEqual(post2.status_code, 200)
def test_POSTBIN_GET_POST_FILES_STRINGS(self):
for service in SERVICES:
url = service('post')
post1 = post(url, files={'fname.txt': 'fdata'})
self.assertEqual(post1.status_code, 200)
post2 = post(url, files={'fname.txt': 'fdata', 'fname2.txt':'more fdata'})
self.assertEqual(post2.status_code, 200)
post3 = post(url, files={'fname.txt': 'fdata', 'fname2.txt':open(__file__,'rb')})
self.assertEqual(post3.status_code, 200)
def test_nonzero_evaluation(self):
for service in SERVICES: