diff options
author | Benjamin Peterson <benjamin@python.org> | 2019-08-25 05:05:18 -0700 |
---|---|---|
committer | Chris Dent <cdent@anticdent.org> | 2019-08-25 13:05:18 +0100 |
commit | 249c49d6cc7c28ffd2bfef92b2402f746d24ca8b (patch) | |
tree | d2acf2ec48732f8ab78cc8ea751dfb8c50d42806 /tests | |
parent | 13fe3fadc740067342e1ac04c8685a97da6781d9 (diff) | |
download | paste-git-249c49d6cc7c28ffd2bfef92b2402f746d24ca8b.tar.gz |
Modify TestApp.encode_multipart to handle bytes filenames and params. (#29)3.1.1
As the test shows, this fixes passing boths params and upload_files on Python 3.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_fixture.py | 28 | ||||
-rw-r--r-- | tests/test_wsgiwrappers.py | 2 |
2 files changed, 29 insertions, 1 deletions
diff --git a/tests/test_fixture.py b/tests/test_fixture.py index 4d1ddc8..2954140 100644 --- a/tests/test_fixture.py +++ b/tests/test_fixture.py @@ -1,5 +1,8 @@ +import cgi + from paste.debug.debugapp import SimpleApplication, SlowConsumer from paste.fixture import TestApp +from paste.wsgiwrappers import WSGIRequest def test_fixture(): @@ -44,3 +47,28 @@ def test_fixture_form_end(): ('Content-Length', str(len(body)))]) return [body] TestApp(response).get('/') + +def test_params_and_upload_files(): + class PostApp(object): + def __call__(self, environ, start_response): + start_response("204 No content", []) + self.request = WSGIRequest(environ) + return [b''] + post_app = PostApp() + app = TestApp(post_app) + app.post( + '/', + params={'param1': 'a', 'param2': 'b'}, + upload_files=[ + ('file1', 'myfile.txt', b'data1'), + ('file2', b'yourfile.txt', b'data2'), + ], + ) + params = post_app.request.params + assert len(params) == 4 + assert params['param1'] == 'a' + assert params['param2'] == 'b' + assert params['file1'].value == b'data1' + assert params['file1'].filename == 'myfile.txt' + assert params['file2'].value == b'data2' + assert params['file2'].filename == 'yourfile.txt' diff --git a/tests/test_wsgiwrappers.py b/tests/test_wsgiwrappers.py index 43210c2..bfdd4b3 100644 --- a/tests/test_wsgiwrappers.py +++ b/tests/test_wsgiwrappers.py @@ -96,7 +96,7 @@ def test_wsgirequest_charset_fileupload(): return [] app = TestApp(handle_fileupload) - res = app.post('/', upload_files=[('thefile', '寿司.txt', b'Sushi')]) + res = app.post('/', upload_files=[('thefile', u'寿司.txt'.encode('utf-8'), b'Sushi')]) def test_wsgiresponse_charset(): response = WSGIResponse(mimetype='text/html; charset=UTF-8') |