This commit is contained in:
Maximilian Hils 2016-07-02 03:03:42 -07:00
parent d9f797e7e6
commit 2f8a1fd2cb
2 changed files with 46 additions and 4 deletions

View File

@ -314,12 +314,12 @@ class decoded(object):
:py:attr:`raw_content` has the encoded content.
"""
def __init__(self, message):
def __init__(self, message): # pragma no cover
warnings.warn("decoded() is deprecated, you can now directly use .content instead. "
".raw_content has the encoded content.", DeprecationWarning)
def __enter__(self):
def __enter__(self): # pragma no cover
pass
def __exit__(self, type, value, tb):
def __exit__(self, type, value, tb): # pragma no cover
pass

View File

@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, division
import mock
import six
from netlib.tutils import tresp
from netlib import http
def _test_passthrough_attr(message, attr):
@ -69,6 +71,15 @@ class TestMessage(object):
assert resp != 0
def test_hash(self):
resp = tresp()
assert hash(resp)
def test_serializable(self):
resp = tresp()
resp2 = http.Response.from_state(resp.get_state())
assert resp == resp2
def test_content_length_update(self):
resp = tresp()
resp.content = b"foo"
@ -93,7 +104,7 @@ class TestMessage(object):
def test_timestamp_end(self):
_test_passthrough_attr(tresp(), "timestamp_end")
def teste_http_version(self):
def test_http_version(self):
_test_decoded_attr(tresp(), "http_version")
@ -109,6 +120,14 @@ class TestMessageContentEncoding(object):
assert r.content == b"message"
assert r.raw_content != b"message"
r.raw_content = b"foo"
with mock.patch("netlib.encoding.decode") as e:
assert r.content
assert e.call_count == 1
e.reset_mock()
assert r.content
assert e.call_count == 0
def test_modify(self):
r = tresp()
assert "content-encoding" not in r.headers
@ -119,6 +138,13 @@ class TestMessageContentEncoding(object):
r.decode()
assert r.raw_content == b"foo"
r.encode("identity")
with mock.patch("netlib.encoding.encode") as e:
r.content = b"foo"
assert e.call_count == 0
r.content = b"bar"
assert e.call_count == 1
def test_unknown_ce(self):
r = tresp()
r.headers["content-encoding"] = "zopfli"
@ -165,6 +191,15 @@ class TestMessageText(object):
assert r.content == b"\xc3\xbc"
assert r.text == u"ü"
r.encode("identity")
r.raw_content = b"foo"
with mock.patch("netlib.encoding.decode") as e:
assert r.text
assert e.call_count == 2
e.reset_mock()
assert r.text
assert e.call_count == 0
def test_modify(self):
r = tresp()
@ -176,6 +211,13 @@ class TestMessageText(object):
assert r.raw_content == b"\xfc"
assert r.headers["content-length"] == "1"
r.encode("identity")
with mock.patch("netlib.encoding.encode") as e:
r.text = u"ü"
assert e.call_count == 0
r.text = u"ä"
assert e.call_count == 2
def test_unknown_ce(self):
r = tresp()
r.headers["content-type"] = "text/html; charset=wtf"