Beispiel #1
0
 def test_multipart(self):
     """ Environ: POST (multipart files and multible values per key) """
     fields = [('field1', 'value1'), ('field2', 'value2'),
               ('field2', 'value3')]
     files = [('file1', 'filename1.txt', 'content1'),
              ('file2', 'filename2.py', u'ä\nö\rü')]
     e = tools.multipart_environ(fields=fields, files=files)
     request.bind(e)
     # File content
     self.assertTrue('file1' in request.POST)
     cmp = tob('content1') if sys.version_info >= (3, 2, 0) else 'content1'
     self.assertEqual(cmp, request.POST['file1'].file.read())
     # File name and meta data
     self.assertTrue('file2' in request.POST)
     self.assertEqual('filename2.py', request.POST['file2'].filename)
     # UTF-8 files
     x = request.POST['file2'].file.read()
     if (3, 2, 0) > sys.version_info >= (3, 0, 0):
         x = x.encode('ISO-8859-1')
     self.assertEqual(u'ä\nö\rü'.encode('utf8'), x)
     # No file
     self.assertTrue('file3' not in request.POST)
     # Field (single)
     self.assertEqual('value1', request.POST['field1'])
     # Field (multi)
     self.assertEqual(2, len(request.POST.getall('field2')))
     self.assertEqual(['value2', 'value3'], request.POST.getall('field2'))
Beispiel #2
0
 def test_multipart(self):
     """ Environ: POST (multipart files and multible values per key) """
     fields = [("field1", "value1"), ("field2", "value2"), ("field2", "value3")]
     files = [("file1", "filename1.txt", "content1"), ("file2", "filename2.py", u"ä\nö\rü")]
     e = tools.multipart_environ(fields=fields, files=files)
     request.bind(e)
     # File content
     self.assertTrue("file1" in request.POST)
     cmp = tob("content1") if sys.version_info >= (3, 2, 0) else "content1"
     self.assertEqual(cmp, request.POST["file1"].file.read())
     # File name and meta data
     self.assertTrue("file2" in request.POST)
     self.assertEqual("filename2.py", request.POST["file2"].filename)
     # UTF-8 files
     x = request.POST["file2"].file.read()
     if (3, 2, 0) > sys.version_info >= (3, 0, 0):
         x = x.encode("ISO-8859-1")
     self.assertEqual(u"ä\nö\rü".encode("utf8"), x)
     # No file
     self.assertTrue("file3" not in request.POST)
     # Field (single)
     self.assertEqual("value1", request.POST["field1"])
     # Field (multi)
     self.assertEqual(2, len(request.POST.getall("field2")))
     self.assertEqual(["value2", "value3"], request.POST.getall("field2"))
Beispiel #3
0
 def test_multipart(self):
     """ Environ: POST (multipart files and multible values per key) """
     fields = [('field1','value1'), ('field2','value2'), ('field2','value3')]
     files = [('file1','filename1.txt','content1'), ('file2','filename2.py',touni('ä\nö\rü'))]
     e = tools.multipart_environ(fields=fields, files=files)
     request = BaseRequest(e)
     # File content
     self.assertTrue('file1' in request.POST)
     self.assertTrue('file1' in request.files)
     self.assertTrue('file1' not in request.forms)
     cmp = tob('content1') if sys.version_info >= (3,2,0) else 'content1'
     self.assertEqual(cmp, request.POST['file1'].file.read())
     # File name and meta data
     self.assertTrue('file2' in request.POST)
     self.assertTrue('file2' in request.files)
     self.assertTrue('file2' not in request.forms)
     self.assertEqual('filename2.py', request.POST['file2'].filename)
     # UTF-8 files
     x = request.POST['file2'].file.read()
     if (3,2,0) > sys.version_info >= (3,0,0):
         x = x.encode('ISO-8859-1')
     self.assertEqual(tob('ä\nö\rü'), x)
     # No file
     self.assertTrue('file3' not in request.POST)
     self.assertTrue('file3' not in request.files)
     self.assertTrue('file3' not in request.forms)
     # Field (single)
     self.assertEqual('value1', request.POST['field1'])
     self.assertTrue('field1' not in request.files)
     self.assertEqual('value1', request.forms['field1'])
     # Field (multi)
     self.assertEqual(2, len(request.POST.getall('field2')))
     self.assertEqual(['value2', 'value3'], request.POST.getall('field2'))
     self.assertEqual(['value2', 'value3'], request.forms.getall('field2'))
     self.assertTrue('field2' not in request.files)
Beispiel #4
0
 def test_multipart(self):
     """ Environ: POST (multipart files and multible values per key) """
     fields = [('field1','value1'), ('field2','value2'), ('field2','value3')]
     files = [('file1','filename1.txt','content1'), ('file2','filename2.py',u'äöü')]
     e = tools.multipart_environ(fields=fields, files=files)
     request.bind(e, None)
     self.assertTrue(e['CONTENT_LENGTH'], request.input_length)
     # File content
     self.assertTrue('file1' in request.POST)
     self.assertEqual('content1', request.POST['file1'].file.read())
     # File name and meta data
     self.assertTrue('file2' in request.POST)
     self.assertEqual('filename2.py', request.POST['file2'].filename)
     # UTF-8 files
     x = request.POST['file2'].file.read()
     if sys.version_info >= (3,0,0):
         x = x.encode('ISO-8859-1')
     self.assertEqual(u'äöü'.encode('utf8'), x)
     # No file
     self.assertTrue('file3' not in request.POST)
     # Field (single)
     self.assertEqual('value1', request.POST['field1'])
     # Field (multi)
     self.assertEqual(2, len(request.POST['field2']))
     self.assertTrue('value2' in request.POST['field2'])
     self.assertTrue('value3' in request.POST['field2'])