diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-10-20 11:56:38 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-10-20 11:56:38 +1300 |
commit | 8430f857b504a3e7406dc36e54dc32783569d0dd (patch) | |
tree | d3116cd540faf01f272a0892fc6a9b83b4f6de8a /test/netlib/http/test_encoding.py | |
parent | 853e03a5e753354fad3a3fa5384ef3a09384ef43 (diff) | |
download | mitmproxy-8430f857b504a3e7406dc36e54dc32783569d0dd.tar.gz mitmproxy-8430f857b504a3e7406dc36e54dc32783569d0dd.tar.bz2 mitmproxy-8430f857b504a3e7406dc36e54dc32783569d0dd.zip |
The final piece: netlib -> mitproxy.net
Diffstat (limited to 'test/netlib/http/test_encoding.py')
-rw-r--r-- | test/netlib/http/test_encoding.py | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/test/netlib/http/test_encoding.py b/test/netlib/http/test_encoding.py deleted file mode 100644 index 89600709..00000000 --- a/test/netlib/http/test_encoding.py +++ /dev/null @@ -1,73 +0,0 @@ -import mock -import pytest - -from netlib.http import encoding -from mitmproxy.test import tutils - - -@pytest.mark.parametrize("encoder", [ - 'identity', - 'none', -]) -def test_identity(encoder): - assert b"string" == encoding.decode(b"string", encoder) - assert b"string" == encoding.encode(b"string", encoder) - with tutils.raises(ValueError): - encoding.encode(b"string", "nonexistent encoding") - - -@pytest.mark.parametrize("encoder", [ - 'gzip', - 'br', - 'deflate', -]) -def test_encoders(encoder): - assert "" == encoding.decode("", encoder) - assert b"" == encoding.decode(b"", encoder) - - assert "string" == encoding.decode( - encoding.encode( - "string", - encoder - ), - encoder - ) - assert b"string" == encoding.decode( - encoding.encode( - b"string", - encoder - ), - encoder - ) - - with tutils.raises(ValueError): - encoding.decode(b"foobar", encoder) - - -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 |