aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2016-05-29 11:43:29 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2016-05-29 11:55:12 +0200
commit8eeab37a07a00a0c85067ed58885233e426067f7 (patch)
treeafdff60b21b92adfa177232d04ef5583e005db60 /test/netlib
parent0c2c017727c7be1eff3bad1766f3030be1f281ec (diff)
downloadmitmproxy-8eeab37a07a00a0c85067ed58885233e426067f7.tar.gz
mitmproxy-8eeab37a07a00a0c85067ed58885233e426067f7.tar.bz2
mitmproxy-8eeab37a07a00a0c85067ed58885233e426067f7.zip
more style cleanup
Use this to check: flake8 --count mitmproxy netlib pathod examples test
Diffstat (limited to 'test/netlib')
-rw-r--r--test/netlib/http/http1/test_assemble.py10
-rw-r--r--test/netlib/http/http1/test_read.py4
-rw-r--r--test/netlib/http/http2/test_connections.py19
-rw-r--r--test/netlib/websockets/test_websockets.py5
4 files changed, 22 insertions, 16 deletions
diff --git a/test/netlib/http/http1/test_assemble.py b/test/netlib/http/http1/test_assemble.py
index 8dcbae8e..4b6ebb91 100644
--- a/test/netlib/http/http1/test_assemble.py
+++ b/test/netlib/http/http1/test_assemble.py
@@ -10,11 +10,11 @@ from netlib.tutils import treq, raises, tresp
def test_assemble_request():
- c = assemble_request(treq()) == (
+ assert assemble_request(treq()) == (
b"GET /path HTTP/1.1\r\n"
b"header: qvalue\r\n"
- b"Host: address:22\r\n"
- b"Content-Length: 7\r\n"
+ b"content-length: 7\r\n"
+ b"host: address:22\r\n"
b"\r\n"
b"content"
)
@@ -32,10 +32,10 @@ def test_assemble_request_head():
def test_assemble_response():
- c = assemble_response(tresp()) == (
+ assert assemble_response(tresp()) == (
b"HTTP/1.1 200 OK\r\n"
+ b"content-length: 7\r\n"
b"header-response: svalue\r\n"
- b"Content-Length: 7\r\n"
b"\r\n"
b"message"
)
diff --git a/test/netlib/http/http1/test_read.py b/test/netlib/http/http1/test_read.py
index 33f3802b..974aa895 100644
--- a/test/netlib/http/http1/test_read.py
+++ b/test/netlib/http/http1/test_read.py
@@ -105,6 +105,7 @@ class TestReadBody(object):
rfile = BytesIO(b"123456")
assert list(read_body(rfile, -1, max_chunk_size=1)) == [b"1", b"2", b"3", b"4", b"5", b"6"]
+
def test_connection_close():
headers = Headers()
assert connection_close(b"HTTP/1.0", headers)
@@ -120,6 +121,7 @@ def test_connection_close():
assert connection_close(b"HTTP/1.0", headers)
assert not connection_close(b"HTTP/1.1", headers)
+
def test_expected_http_body_size():
# Expect: 100-continue
assert expected_http_body_size(
@@ -202,6 +204,7 @@ def test_read_request_line():
with raises(HttpReadDisconnect):
t(b"")
+
def test_parse_authority_form():
assert _parse_authority_form(b"foo:42") == (b"foo", 42)
with raises(HttpSyntaxException):
@@ -301,6 +304,7 @@ class TestReadHeaders(object):
headers = self._read(data)
assert headers.fields == ((b"bar", b""),)
+
def test_read_chunked():
req = treq(content=None)
req.headers["Transfer-Encoding"] = "chunked"
diff --git a/test/netlib/http/http2/test_connections.py b/test/netlib/http/http2/test_connections.py
index 139d4fc1..ff462ba6 100644
--- a/test/netlib/http/http2/test_connections.py
+++ b/test/netlib/http/http2/test_connections.py
@@ -1,7 +1,7 @@
import mock
import codecs
-from hyperframe.frame import *
+from hyperframe import frame
from netlib import tcp, http, utils
from netlib.tutils import raises
@@ -10,6 +10,7 @@ from netlib.http.http2.connections import HTTP2Protocol, TCPHandler
from ... import tservers
+
class TestTCPHandlerWrapper:
def test_wrapped(self):
h = TCPHandler(rfile='foo', wfile='bar')
@@ -213,19 +214,19 @@ class TestApplySettings(tservers.ServerTestBase):
protocol = HTTP2Protocol(c)
protocol._apply_settings({
- SettingsFrame.ENABLE_PUSH: 'foo',
- SettingsFrame.MAX_CONCURRENT_STREAMS: 'bar',
- SettingsFrame.INITIAL_WINDOW_SIZE: 'deadbeef',
+ frame.SettingsFrame.ENABLE_PUSH: 'foo',
+ frame.SettingsFrame.MAX_CONCURRENT_STREAMS: 'bar',
+ frame.SettingsFrame.INITIAL_WINDOW_SIZE: 'deadbeef',
})
assert c.rfile.safe_read(2) == b"OK"
assert protocol.http2_settings[
- SettingsFrame.ENABLE_PUSH] == 'foo'
+ frame.SettingsFrame.ENABLE_PUSH] == 'foo'
assert protocol.http2_settings[
- SettingsFrame.MAX_CONCURRENT_STREAMS] == 'bar'
+ frame.SettingsFrame.MAX_CONCURRENT_STREAMS] == 'bar'
assert protocol.http2_settings[
- SettingsFrame.INITIAL_WINDOW_SIZE] == 'deadbeef'
+ frame.SettingsFrame.INITIAL_WINDOW_SIZE] == 'deadbeef'
class TestCreateHeaders(object):
@@ -257,7 +258,7 @@ class TestCreateHeaders(object):
(b'server', b'version')])
protocol = HTTP2Protocol(self.c)
- protocol.http2_settings[SettingsFrame.MAX_FRAME_SIZE] = 8
+ protocol.http2_settings[frame.SettingsFrame.MAX_FRAME_SIZE] = 8
bytes = protocol._create_headers(headers, 1, end_stream=True)
assert len(bytes) == 3
assert bytes[0] == codecs.decode('000008010100000001828487408294e783', 'hex_codec')
@@ -280,7 +281,7 @@ class TestCreateBody(object):
def test_create_body_multiple_frames(self):
protocol = HTTP2Protocol(self.c)
- protocol.http2_settings[SettingsFrame.MAX_FRAME_SIZE] = 5
+ protocol.http2_settings[frame.SettingsFrame.MAX_FRAME_SIZE] = 5
bytes = protocol._create_body(b'foobarmehm42', 1)
assert len(bytes) == 3
assert bytes[0] == codecs.decode('000005000000000001666f6f6261', 'hex_codec')
diff --git a/test/netlib/websockets/test_websockets.py b/test/netlib/websockets/test_websockets.py
index 4a6f0f9b..024544f5 100644
--- a/test/netlib/websockets/test_websockets.py
+++ b/test/netlib/websockets/test_websockets.py
@@ -7,10 +7,11 @@ from netlib import tutils
from netlib import websockets
from netlib.http import status_codes
from netlib.tutils import treq
-from netlib.exceptions import *
+from netlib import exceptions
from .. import tservers
+
class WebSocketsEchoHandler(tcp.BaseHandler):
def __init__(self, connection, address, server):
@@ -176,7 +177,7 @@ class TestBadHandshake(tservers.ServerTestBase):
handler = BadHandshakeHandler
def test(self):
- with tutils.raises(TcpDisconnect):
+ with tutils.raises(exceptions.TcpDisconnect):
client = WebSocketsClient(("127.0.0.1", self.port))
client.connect()
client.send_message(b"hello")