diff options
author | Aldo Cortesi <aldo@corte.si> | 2016-07-17 15:06:58 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-17 15:06:58 +1200 |
commit | fb45d59c0257cdec38b14e8839fb2dbca079fb97 (patch) | |
tree | 116b1cd6a4ed083d22c9f8f77fa00bf49f51a6e9 /test/netlib/http/http1/test_read.py | |
parent | 15c7528faf3374e246eb7de02c194edcf0d913b2 (diff) | |
parent | a32312cecc88662c13b724b9c6f2f641c1b72822 (diff) | |
download | mitmproxy-fb45d59c0257cdec38b14e8839fb2dbca079fb97.tar.gz mitmproxy-fb45d59c0257cdec38b14e8839fb2dbca079fb97.tar.bz2 mitmproxy-fb45d59c0257cdec38b14e8839fb2dbca079fb97.zip |
Merge pull request #1367 from Kriechi/fix-1366
fix-1366
Diffstat (limited to 'test/netlib/http/http1/test_read.py')
-rw-r--r-- | test/netlib/http/http1/test_read.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/test/netlib/http/http1/test_read.py b/test/netlib/http/http1/test_read.py index 5285ac1d..c8a40ecb 100644 --- a/test/netlib/http/http1/test_read.py +++ b/test/netlib/http/http1/test_read.py @@ -1,6 +1,9 @@ from __future__ import absolute_import, print_function, division + from io import BytesIO from mock import Mock +import pytest + from netlib.exceptions import HttpException, HttpSyntaxException, HttpReadDisconnect, TcpDisconnect from netlib.http import Headers from netlib.http.http1.read import ( @@ -23,11 +26,18 @@ def test_get_header_tokens(): assert get_header_tokens(headers, "foo") == ["bar", "voing", "oink"] -def test_read_request(): - rfile = BytesIO(b"GET / HTTP/1.1\r\n\r\nskip") +@pytest.mark.parametrize("input", [ + b"GET / HTTP/1.1\r\n\r\nskip", + b"GET / HTTP/1.1\r\n\r\nskip", + b"GET / HTTP/1.1\r\n\r\nskip", + b"GET / HTTP/1.1 \r\n\r\nskip", +]) +def test_read_request(input): + rfile = BytesIO(input) r = read_request(rfile) assert r.method == "GET" assert r.content == b"" + assert r.http_version == "HTTP/1.1" assert r.timestamp_end assert rfile.read() == b"skip" @@ -50,11 +60,19 @@ def test_read_request_head(): assert rfile.read() == b"skip" -def test_read_response(): +@pytest.mark.parametrize("input", [ + b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody", + b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody", + b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody", + b"HTTP/1.1 418 I'm a teapot \r\n\r\nbody", +]) +def test_read_response(input): req = treq() - rfile = BytesIO(b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody") + rfile = BytesIO(input) r = read_response(rfile, req) + assert r.http_version == "HTTP/1.1" assert r.status_code == 418 + assert r.reason == "I'm a teapot" assert r.content == b"body" assert r.timestamp_end |