summaryrefslogtreecommitdiffhomepage
path: root/test/test_java_application.py
diff options
context:
space:
mode:
authorTiago Natel de Moura <t.nateldemoura@f5.com>2020-02-05 13:13:04 +0000
committerTiago Natel de Moura <t.nateldemoura@f5.com>2020-02-05 13:13:04 +0000
commitd3e218a8c379baf1af4759097d3c9c2fedb01432 (patch)
tree27c5b2c227535b7ff21ef41a16db3cb76f3f6033 /test/test_java_application.py
parent29d8b34244e24095f23f5e483f8452035fbb77aa (diff)
downloadunit-d3e218a8c379baf1af4759097d3c9c2fedb01432.tar.gz
unit-d3e218a8c379baf1af4759097d3c9c2fedb01432.tar.bz2
Tests: add helper for form-data and multipart.
Diffstat (limited to '')
-rw-r--r--test/test_java_application.py39
1 files changed, 17 insertions, 22 deletions
diff --git a/test/test_java_application.py b/test/test_java_application.py
index d2b97f88..9d873d6b 100644
--- a/test/test_java_application.py
+++ b/test/test_java_application.py
@@ -1,3 +1,4 @@
+import io
import os
import time
import unittest
@@ -1223,31 +1224,25 @@ class TestJavaApplication(TestApplicationJava):
os.mkdir(fulldst)
self.public_dir(fulldst)
- body = (
- """Preamble. Should be ignored.\r
-\r
---12345\r
-Content-Disposition: form-data; name="file"; filename="sample.txt"\r
-Content-Type: text/plain\r
-\r
-Data from sample file\r
---12345\r
-Content-Disposition: form-data; name="destination"\r
-\r
-%s\r
---12345\r
-Content-Disposition: form-data; name="upload"\r
-\r
-Upload\r
---12345--\r
-\r
-Epilogue. Should be ignored."""
- % fulldst
- )
+ fields = {
+ 'file': {
+ 'filename': 'sample.txt',
+ 'type': 'text/plain',
+ 'data': io.StringIO('Data from sample file'),
+ },
+ 'destination': fulldst,
+ 'upload': 'Upload',
+ }
+
+ encoded, content_type = self.multipart_encode(fields)
+
+ preamble = 'Preamble. Should be ignored.'
+ epilogue = 'Epilogue. Should be ignored.'
+ body = "%s\r\n%s\r\n%s" % (preamble, encoded.decode(), epilogue)
resp = self.post(
headers={
- 'Content-Type': 'multipart/form-data; boundary=12345',
+ 'Content-Type': content_type,
'Host': 'localhost',
'Connection': 'close',
},