diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-02-08 12:01:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-08 12:01:32 +0100 |
commit | 79354c0b43fd7449b931037b9a4e43a5bb85a21d (patch) | |
tree | 0a077d07fdb37850c08a473a32103450dc224d7c /test | |
parent | 2316c0fb74efefd76970c685b8f77f45834f1490 (diff) | |
parent | c622622c5924b291db302aa22f4d82608677ceed (diff) | |
download | mitmproxy-79354c0b43fd7449b931037b9a4e43a5bb85a21d.tar.gz mitmproxy-79354c0b43fd7449b931037b9a4e43a5bb85a21d.tar.bz2 mitmproxy-79354c0b43fd7449b931037b9a4e43a5bb85a21d.zip |
Merge pull request #1984 from ujjwal96/har_dump-fix
Fixes #1978
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(): |