diff options
author | Benjamin Peterson <benjamin@python.org> | 2019-07-24 03:46:10 -0700 |
---|---|---|
committer | Chris Dent <cdent@anticdent.org> | 2019-07-24 11:46:10 +0100 |
commit | 37bb9b45cdb55b50a4c2b371c5a0a75198863287 (patch) | |
tree | 4119dd4f3cc246ba9c3ce8859f9db0e9201cf347 /tests | |
parent | 0cfebf50090b7069a4c9b3bc6baf65693d22792d (diff) | |
download | paste-git-37bb9b45cdb55b50a4c2b371c5a0a75198863287.tar.gz |
Fix WSGIResponse.__call__ on Python 3. (#27)
Replace `isinstance(self.content, file)` with a duck type for the `read()` method. Having a read method is what PEP 333 defines as the minimum requirement for a "file-like" object.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_wsgiwrappers.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_wsgiwrappers.py b/tests/test_wsgiwrappers.py index 75d03ed..43210c2 100644 --- a/tests/test_wsgiwrappers.py +++ b/tests/test_wsgiwrappers.py @@ -2,6 +2,7 @@ # (c) 2007 Philip Jenvey; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php import cgi +import io from paste.fixture import TestApp from paste.wsgiwrappers import WSGIRequest, WSGIResponse import six @@ -144,3 +145,19 @@ def test_wsgiresponse_charset(): assert isinstance(data, six.text_type) finally: WSGIResponse.defaults._pop_object() + +def test_call_wsgiresponse(): + resp = WSGIResponse(b'some content', 'application/octet-stream') + def sp(status, response_headers): + assert status == '200 OK' + assert sorted(response_headers) == [ + ('cache-control', 'no-cache'), + ('content-type', 'application/octet-stream'), + ] + assert resp({}, sp) == [b'some content'] + f = io.BytesIO(b'some content') + resp = WSGIResponse(f, 'application/octet-stream') + assert list(resp({}, sp)) == [b'some content'] + f = io.BytesIO() + resp = WSGIResponse(f, 'application/octet-stream') + assert resp({'wsgi.file_wrapper': lambda x: x}, sp) is f |