diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-07-02 03:03:42 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-07-02 03:03:42 -0700 |
commit | 2f8a1fd2cb1374941f436f36bbfa0d0b3d9213c7 (patch) | |
tree | 6d30bf9d18306b2244017181832d87fd86bcc2d6 /test | |
parent | d9f797e7e6936809171d9c99144fb5ded3ee131f (diff) | |
download | mitmproxy-2f8a1fd2cb1374941f436f36bbfa0d0b3d9213c7.tar.gz mitmproxy-2f8a1fd2cb1374941f436f36bbfa0d0b3d9213c7.tar.bz2 mitmproxy-2f8a1fd2cb1374941f436f36bbfa0d0b3d9213c7.zip |
tests++
Diffstat (limited to 'test')
-rw-r--r-- | test/netlib/http/test_message.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/test/netlib/http/test_message.py b/test/netlib/http/test_message.py index aecde1ec..e1707a91 100644 --- a/test/netlib/http/test_message.py +++ b/test/netlib/http/test_message.py @@ -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" |