aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib/test_encoding.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-23 23:33:38 -0700
committerGitHub <noreply@github.com>2016-07-23 23:33:38 -0700
commita3fa9e14aea6e586e839630c57df24aea8c55d26 (patch)
treea8e2c1eac7587a16543c3f4649c84b7708ae2177 /test/netlib/test_encoding.py
parent4d042ec54363d0ae993df19f684db8738b681286 (diff)
parente07f515a208ff10f00abee6cfd9d984e676261b1 (diff)
downloadmitmproxy-a3fa9e14aea6e586e839630c57df24aea8c55d26.tar.gz
mitmproxy-a3fa9e14aea6e586e839630c57df24aea8c55d26.tar.bz2
mitmproxy-a3fa9e14aea6e586e839630c57df24aea8c55d26.zip
Merge pull request #1421 from mhils/encoding-cache
Add Encoding Cache, Remove HTTP Message Content Cache
Diffstat (limited to 'test/netlib/test_encoding.py')
-rw-r--r--test/netlib/test_encoding.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/netlib/test_encoding.py b/test/netlib/test_encoding.py
index de10fc48..a5e81379 100644
--- a/test/netlib/test_encoding.py
+++ b/test/netlib/test_encoding.py
@@ -1,3 +1,4 @@
+import mock
from netlib import encoding, tutils
@@ -37,3 +38,32 @@ def test_deflate():
)
with tutils.raises(ValueError):
encoding.decode(b"bogus", "deflate")
+
+
+def test_cache():
+ decode_gzip = mock.MagicMock()
+ decode_gzip.return_value = b"decoded"
+ encode_gzip = mock.MagicMock()
+ encode_gzip.return_value = b"encoded"
+
+ with mock.patch.dict(encoding.custom_decode, gzip=decode_gzip):
+ with mock.patch.dict(encoding.custom_encode, gzip=encode_gzip):
+ assert encoding.decode(b"encoded", "gzip") == b"decoded"
+ assert decode_gzip.call_count == 1
+
+ # should be cached
+ assert encoding.decode(b"encoded", "gzip") == b"decoded"
+ assert decode_gzip.call_count == 1
+
+ # the other way around as well
+ assert encoding.encode(b"decoded", "gzip") == b"encoded"
+ assert encode_gzip.call_count == 0
+
+ # different encoding
+ decode_gzip.return_value = b"bar"
+ assert encoding.encode(b"decoded", "deflate") != b"decoded"
+ assert encode_gzip.call_count == 0
+
+ # This is not in the cache anymore
+ assert encoding.encode(b"decoded", "gzip") == b"encoded"
+ assert encode_gzip.call_count == 1