aboutsummaryrefslogtreecommitdiff
path: root/test/test_fields.py
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:35 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:35 -0700
commit52980ebd0a4eb75acf055a2256e095772c1fa7c6 (patch)
treef339a7e66934caa7948c15e8c5bd3ea04ee72e5a /test/test_fields.py
parent92b84b67f7b187b81dacbf1ae46d59a1d0b5b125 (diff)
downloadpython-urllib3-52980ebd0a4eb75acf055a2256e095772c1fa7c6.tar
python-urllib3-52980ebd0a4eb75acf055a2256e095772c1fa7c6.tar.gz
Imported Upstream version 1.7.1
Diffstat (limited to 'test/test_fields.py')
-rw-r--r--test/test_fields.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/test_fields.py b/test/test_fields.py
new file mode 100644
index 0000000..888c2d5
--- /dev/null
+++ b/test/test_fields.py
@@ -0,0 +1,44 @@
+import unittest
+
+from urllib3.fields import guess_content_type, RequestField
+from urllib3.packages.six import b, u
+
+
+class TestRequestField(unittest.TestCase):
+
+ def test_guess_content_type(self):
+ self.assertEqual(guess_content_type('image.jpg'), 'image/jpeg')
+ self.assertEqual(guess_content_type('notsure'), 'application/octet-stream')
+ self.assertEqual(guess_content_type(None), 'application/octet-stream')
+
+ def test_create(self):
+ simple_field = RequestField('somename', 'data')
+ self.assertEqual(simple_field.render_headers(), '\r\n')
+ filename_field = RequestField('somename', 'data', filename='somefile.txt')
+ self.assertEqual(filename_field.render_headers(), '\r\n')
+ headers_field = RequestField('somename', 'data', headers={'Content-Length': 4})
+ self.assertEqual(headers_field.render_headers(),
+ 'Content-Length: 4\r\n'
+ '\r\n')
+
+ def test_make_multipart(self):
+ field = RequestField('somename', 'data')
+ field.make_multipart(content_type='image/jpg', content_location='/test')
+ self.assertEqual(field.render_headers(),
+ 'Content-Disposition: form-data; name="somename"\r\n'
+ 'Content-Type: image/jpg\r\n'
+ 'Content-Location: /test\r\n'
+ '\r\n')
+
+ def test_render_parts(self):
+ field = RequestField('somename', 'data')
+ parts = field._render_parts({'name': 'value', 'filename': 'value'})
+ self.assertTrue('name="value"' in parts)
+ self.assertTrue('filename="value"' in parts)
+ parts = field._render_parts([('name', 'value'), ('filename', 'value')])
+ self.assertEqual(parts, 'name="value"; filename="value"')
+
+ def test_render_part(self):
+ field = RequestField('somename', 'data')
+ param = field._render_part('filename', u('n\u00e4me'))
+ self.assertEqual(param, "filename*=utf-8''n%C3%A4me")