aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-05-31 17:16:31 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-05-31 17:16:31 +1200
commit08fbe6f1118455bc44d05db30b83bdf81feda2a0 (patch)
tree38db5d8f3e1e52e09a9348d15db368ae3baa9b86 /test/netlib
parent2f526393d29b6a03e43d1f6240175b4dfb13dc7d (diff)
downloadmitmproxy-08fbe6f1118455bc44d05db30b83bdf81feda2a0.tar.gz
mitmproxy-08fbe6f1118455bc44d05db30b83bdf81feda2a0.tar.bz2
mitmproxy-08fbe6f1118455bc44d05db30b83bdf81feda2a0.zip
Start cleaning up netlib.utils
- Remove http2 functions, move to http2.frame - Remove Serializable, move to netlib.basetypes
Diffstat (limited to 'test/netlib')
-rw-r--r--test/netlib/http/http2/test_connections.py26
-rw-r--r--test/netlib/test_basetypes.py27
-rw-r--r--test/netlib/test_utils.py27
3 files changed, 40 insertions, 40 deletions
diff --git a/test/netlib/http/http2/test_connections.py b/test/netlib/http/http2/test_connections.py
index 69667d1c..be68a28c 100644
--- a/test/netlib/http/http2/test_connections.py
+++ b/test/netlib/http/http2/test_connections.py
@@ -1,12 +1,12 @@
import mock
import codecs
-from hyperframe import frame
-
-from netlib import tcp, http, utils
+import hyperframe
+from netlib import tcp, http
from netlib.tutils import raises
from netlib.exceptions import TcpDisconnect
from netlib.http.http2.connections import HTTP2Protocol, TCPHandler
+from netlib.http.http2 import frame
from ... import tservers
@@ -111,11 +111,11 @@ class TestPerformServerConnectionPreface(tservers.ServerTestBase):
self.wfile.flush()
# check empty settings frame
- raw = utils.http2_read_raw_frame(self.rfile)
+ raw = frame.http2_read_raw_frame(self.rfile)
assert raw == codecs.decode('00000c040000000000000200000000000300000001', 'hex_codec')
# check settings acknowledgement
- raw = utils.http2_read_raw_frame(self.rfile)
+ raw = frame.http2_read_raw_frame(self.rfile)
assert raw == codecs.decode('000000040100000000', 'hex_codec')
# send settings acknowledgement
@@ -214,19 +214,19 @@ class TestApplySettings(tservers.ServerTestBase):
protocol = HTTP2Protocol(c)
protocol._apply_settings({
- frame.SettingsFrame.ENABLE_PUSH: 'foo',
- frame.SettingsFrame.MAX_CONCURRENT_STREAMS: 'bar',
- frame.SettingsFrame.INITIAL_WINDOW_SIZE: 'deadbeef',
+ hyperframe.frame.SettingsFrame.ENABLE_PUSH: 'foo',
+ hyperframe.frame.SettingsFrame.MAX_CONCURRENT_STREAMS: 'bar',
+ hyperframe.frame.SettingsFrame.INITIAL_WINDOW_SIZE: 'deadbeef',
})
assert c.rfile.safe_read(2) == b"OK"
assert protocol.http2_settings[
- frame.SettingsFrame.ENABLE_PUSH] == 'foo'
+ hyperframe.frame.SettingsFrame.ENABLE_PUSH] == 'foo'
assert protocol.http2_settings[
- frame.SettingsFrame.MAX_CONCURRENT_STREAMS] == 'bar'
+ hyperframe.frame.SettingsFrame.MAX_CONCURRENT_STREAMS] == 'bar'
assert protocol.http2_settings[
- frame.SettingsFrame.INITIAL_WINDOW_SIZE] == 'deadbeef'
+ hyperframe.frame.SettingsFrame.INITIAL_WINDOW_SIZE] == 'deadbeef'
class TestCreateHeaders(object):
@@ -258,7 +258,7 @@ class TestCreateHeaders(object):
(b'server', b'version')])
protocol = HTTP2Protocol(self.c)
- protocol.http2_settings[frame.SettingsFrame.MAX_FRAME_SIZE] = 8
+ protocol.http2_settings[hyperframe.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')
@@ -281,7 +281,7 @@ class TestCreateBody(object):
def test_create_body_multiple_frames(self):
protocol = HTTP2Protocol(self.c)
- protocol.http2_settings[frame.SettingsFrame.MAX_FRAME_SIZE] = 5
+ protocol.http2_settings[hyperframe.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/test_basetypes.py b/test/netlib/test_basetypes.py
new file mode 100644
index 00000000..2a7eea81
--- /dev/null
+++ b/test/netlib/test_basetypes.py
@@ -0,0 +1,27 @@
+from netlib import basetypes
+
+class SerializableDummy(basetypes.Serializable):
+ def __init__(self, i):
+ self.i = i
+
+ def get_state(self):
+ return self.i
+
+ def set_state(self, i):
+ self.i = i
+
+ def from_state(self, state):
+ return type(self)(state)
+
+
+class TestSerializable:
+
+ def test_copy(self):
+ a = SerializableDummy(42)
+ assert a.i == 42
+ b = a.copy()
+ assert b.i == 42
+
+ a.set_state(1)
+ assert a.i == 1
+ assert b.i == 42
diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py
index e4c81a48..cd629d77 100644
--- a/test/netlib/test_utils.py
+++ b/test/netlib/test_utils.py
@@ -144,33 +144,6 @@ def test_parse_content_type():
assert v == ('text', 'html', {'charset': 'UTF-8'})
-class SerializableDummy(utils.Serializable):
- def __init__(self, i):
- self.i = i
-
- def get_state(self):
- return self.i
-
- def set_state(self, i):
- self.i = i
-
- def from_state(self, state):
- return type(self)(state)
-
-
-class TestSerializable:
-
- def test_copy(self):
- a = SerializableDummy(42)
- assert a.i == 42
- b = a.copy()
- assert b.i == 42
-
- a.set_state(1)
- assert a.i == 1
- assert b.i == 42
-
-
def test_safe_subn():
assert utils.safe_subn("foo", u"bar", "\xc2foo")