aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:31 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:31 -0700
commit77245469d4fbd400c6702cde35f9d9002540663e (patch)
tree5bbc97fd683f8f7354204d24be7974b268b19531 /test
parent0c183b9d52b45bac22a2ff9db0e6348b655f4ab2 (diff)
downloadpython-urllib3-77245469d4fbd400c6702cde35f9d9002540663e.tar
python-urllib3-77245469d4fbd400c6702cde35f9d9002540663e.tar.gz
Imported Upstream version 1.3
Diffstat (limited to 'test')
-rw-r--r--test/test_collections.py1
-rw-r--r--test/test_connectionpool.py10
-rw-r--r--test/test_filepost.py85
3 files changed, 89 insertions, 7 deletions
diff --git a/test/test_collections.py b/test/test_collections.py
index f8275e0..6cb5aca 100644
--- a/test/test_collections.py
+++ b/test/test_collections.py
@@ -4,6 +4,7 @@ from urllib3._collections import RecentlyUsedContainer as Container
from urllib3.packages import six
xrange = six.moves.xrange
+
class TestLRUContainer(unittest.TestCase):
def test_maxsize(self):
d = Container(5)
diff --git a/test/test_connectionpool.py b/test/test_connectionpool.py
index 4281d42..c32c6dc 100644
--- a/test/test_connectionpool.py
+++ b/test/test_connectionpool.py
@@ -1,11 +1,7 @@
import unittest
-from urllib3.connectionpool import (
- connection_from_url,
- get_host,
- HTTPConnectionPool,
- make_headers)
-
+from urllib3.connectionpool import connection_from_url, HTTPConnectionPool
+from urllib3.util import get_host, make_headers
from urllib3.exceptions import EmptyPoolError, LocationParseError
@@ -105,7 +101,7 @@ class TestConnectionPool(unittest.TestCase):
pass
try:
- pool.get_url('/', pool_timeout=0.01)
+ pool.request('GET', '/', pool_timeout=0.01)
self.fail("Managed to get a connection without EmptyPoolError")
except EmptyPoolError:
pass
diff --git a/test/test_filepost.py b/test/test_filepost.py
new file mode 100644
index 0000000..c251778
--- /dev/null
+++ b/test/test_filepost.py
@@ -0,0 +1,85 @@
+import unittest
+
+from urllib3.filepost import encode_multipart_formdata, iter_fields
+from urllib3.packages.six import b, u
+
+
+BOUNDARY = '!! test boundary !!'
+
+
+class TestIterfields(unittest.TestCase):
+
+ def test_dict(self):
+ for fieldname, value in iter_fields(dict(a='b')):
+ self.assertEqual((fieldname, value), ('a', 'b'))
+
+ self.assertEqual(
+ list(sorted(iter_fields(dict(a='b', c='d')))),
+ [('a', 'b'), ('c', 'd')])
+
+ def test_tuple_list(self):
+ for fieldname, value in iter_fields([('a', 'b')]):
+ self.assertEqual((fieldname, value), ('a', 'b'))
+
+ self.assertEqual(
+ list(iter_fields([('a', 'b'), ('c', 'd')])),
+ [('a', 'b'), ('c', 'd')])
+
+
+class TestMultipartEncoding(unittest.TestCase):
+
+ def test_input_datastructures(self):
+ fieldsets = [
+ dict(k='v', k2='v2'),
+ [('k', 'v'), ('k2', 'v2')],
+ ]
+
+ for fields in fieldsets:
+ encoded, _ = encode_multipart_formdata(fields, boundary=BOUNDARY)
+ self.assertEqual(encoded.count(b(BOUNDARY)), 3)
+
+
+ def test_field_encoding(self):
+ fieldsets = [
+ [('k', 'v'), ('k2', 'v2')],
+ [('k', b'v'), (u('k2'), b'v2')],
+ [('k', b'v'), (u('k2'), 'v2')],
+ ]
+
+ for fields in fieldsets:
+ encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)
+
+ self.assertEqual(encoded,
+ b'--' + b(BOUNDARY) + b'\r\n'
+ b'Content-Disposition: form-data; name="k"\r\n'
+ b'Content-Type: text/plain\r\n'
+ b'\r\n'
+ b'v\r\n'
+ b'--' + b(BOUNDARY) + b'\r\n'
+ b'Content-Disposition: form-data; name="k2"\r\n'
+ b'Content-Type: text/plain\r\n'
+ b'\r\n'
+ b'v2\r\n'
+ b'--' + b(BOUNDARY) + b'--\r\n'
+ , fields)
+
+ self.assertEqual(content_type,
+ b'multipart/form-data; boundary=' + b(BOUNDARY))
+
+
+ def test_filename(self):
+ fields = [('k', ('somename', b'v'))]
+
+ encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)
+
+ self.assertEqual(encoded,
+ b'--' + b(BOUNDARY) + b'\r\n'
+ b'Content-Disposition: form-data; name="k"; filename="somename"\r\n'
+ b'Content-Type: application/octet-stream\r\n'
+ b'\r\n'
+ b'v\r\n'
+ b'--' + b(BOUNDARY) + b'--\r\n'
+ )
+
+ self.assertEqual(content_type,
+ b'multipart/form-data; boundary=' + b(BOUNDARY))