mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Add tests for decode_unicode
This commit is contained in:
@@ -9,6 +9,7 @@ import os
|
||||
import pickle
|
||||
import unittest
|
||||
|
||||
import io
|
||||
import requests
|
||||
import pytest
|
||||
from requests.adapters import HTTPAdapter
|
||||
@@ -690,6 +691,26 @@ class RequestsTestCase(unittest.TestCase):
|
||||
assert next(iter(r))
|
||||
io.close()
|
||||
|
||||
def test_response_decode_unicode(self):
|
||||
"""
|
||||
When called with decode_unicode, Response.iter_content should always
|
||||
return unicode.
|
||||
"""
|
||||
r = requests.Response()
|
||||
r._content_consumed = True
|
||||
r._content = b'the content'
|
||||
r.encoding = 'ascii'
|
||||
|
||||
chunks = r.iter_content(decode_unicode=True)
|
||||
assert all(isinstance(chunk, str) for chunk in chunks)
|
||||
|
||||
# also for streaming
|
||||
r = requests.Response()
|
||||
r.raw = io.BytesIO(b'the content')
|
||||
r.encoding = 'ascii'
|
||||
chunks = r.iter_content(decode_unicode=True)
|
||||
assert all(isinstance(chunk, str) for chunk in chunks)
|
||||
|
||||
def test_request_and_response_are_pickleable(self):
|
||||
r = requests.get(httpbin('get'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user