diff options
author | Ujjwal Verma <ujjwalverma1111@gmail.com> | 2017-02-05 18:59:01 +0530 |
---|---|---|
committer | Ujjwal Verma <ujjwalverma1111@gmail.com> | 2017-02-05 18:59:01 +0530 |
commit | c622622c5924b291db302aa22f4d82608677ceed (patch) | |
tree | 0a077d07fdb37850c08a473a32103450dc224d7c /test | |
parent | 2316c0fb74efefd76970c685b8f77f45834f1490 (diff) | |
download | mitmproxy-c622622c5924b291db302aa22f4d82608677ceed.tar.gz mitmproxy-c622622c5924b291db302aa22f4d82608677ceed.tar.bz2 mitmproxy-c622622c5924b291db302aa22f4d82608677ceed.zip |
Encoding fixes and tests
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/net/http/test_encoding.py | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/test/mitmproxy/net/http/test_encoding.py b/test/mitmproxy/net/http/test_encoding.py index 11619c44..8dac12cb 100644 --- a/test/mitmproxy/net/http/test_encoding.py +++ b/test/mitmproxy/net/http/test_encoding.py @@ -21,26 +21,55 @@ def test_identity(encoder): 'deflate', ]) def test_encoders(encoder): - assert "" == encoding.decode("", encoder) + """ + This test is for testing byte->byte encoding/decoding + """ + assert encoding.decode(None, encoder) is None + assert encoding.encode(None, encoder) is None + assert b"" == encoding.decode(b"", encoder) - assert "string" == encoding.decode( + assert b"string" == encoding.decode( encoding.encode( - "string", + b"string", encoder ), encoder ) - assert b"string" == encoding.decode( + + with pytest.raises(TypeError): + encoding.encode("string", encoder) + + with pytest.raises(TypeError): + encoding.decode("string", encoder) + with pytest.raises(ValueError): + encoding.decode(b"foobar", encoder) + + +@pytest.mark.parametrize("encoder", [ + 'utf8', + 'latin-1' +]) +def test_encoders_strings(encoder): + """ + This test is for testing byte->str decoding + and str->byte encoding + """ + assert "" == encoding.decode(b"", encoder) + + assert "string" == encoding.decode( encoding.encode( - b"string", + "string", encoder ), encoder ) - with pytest.raises(ValueError): - encoding.decode(b"foobar", encoder) + with pytest.raises(TypeError): + encoding.encode(b"string", encoder) + + with pytest.raises(TypeError): + encoding.decode("foobar", encoder) def test_cache(): |