diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/http/http1/test_protocol.py | 4 | ||||
-rw-r--r-- | test/http/http2/test_protocol.py | 74 |
2 files changed, 54 insertions, 24 deletions
diff --git a/test/http/http1/test_protocol.py b/test/http/http1/test_protocol.py index dcebbd5e..b196b7a3 100644 --- a/test/http/http1/test_protocol.py +++ b/test/http/http1/test_protocol.py @@ -297,10 +297,10 @@ class TestReadResponseNoContentLength(tservers.ServerTestBase): def test_read_response(): - def tst(data, method, limit, include_body=True): + def tst(data, method, body_size_limit, include_body=True): data = textwrap.dedent(data) return mock_protocol(data).read_response( - method, limit, include_body=include_body + method, body_size_limit, include_body=include_body ) tutils.raises("server disconnect", tst, "", "GET", None) diff --git a/test/http/http2/test_protocol.py b/test/http/http2/test_protocol.py index d3040266..b2d414d1 100644 --- a/test/http/http2/test_protocol.py +++ b/test/http/http2/test_protocol.py @@ -1,6 +1,6 @@ import OpenSSL -from netlib import tcp, odict +from netlib import tcp, odict, http from netlib.http import http2 from netlib.http.http2.frame import * from ... import tutils, tservers @@ -117,11 +117,11 @@ class TestClientStreamIds(): def test_client_stream_ids(self): assert self.protocol.current_stream_id is None - assert self.protocol.next_stream_id() == 1 + assert self.protocol._next_stream_id() == 1 assert self.protocol.current_stream_id == 1 - assert self.protocol.next_stream_id() == 3 + assert self.protocol._next_stream_id() == 3 assert self.protocol.current_stream_id == 3 - assert self.protocol.next_stream_id() == 5 + assert self.protocol._next_stream_id() == 5 assert self.protocol.current_stream_id == 5 @@ -131,11 +131,11 @@ class TestServerStreamIds(): def test_server_stream_ids(self): assert self.protocol.current_stream_id is None - assert self.protocol.next_stream_id() == 2 + assert self.protocol._next_stream_id() == 2 assert self.protocol.current_stream_id == 2 - assert self.protocol.next_stream_id() == 4 + assert self.protocol._next_stream_id() == 4 assert self.protocol.current_stream_id == 4 - assert self.protocol.next_stream_id() == 6 + assert self.protocol._next_stream_id() == 6 assert self.protocol.current_stream_id == 6 @@ -215,17 +215,36 @@ class TestCreateBody(): # TODO: add test for too large frames -class TestCreateRequest(): +class TestAssembleRequest(): c = tcp.TCPClient(("127.0.0.1", 0)) - def test_create_request_simple(self): - bytes = http2.HTTP2Protocol(self.c).create_request('GET', '/') + def test_assemble_request_simple(self): + bytes = http2.HTTP2Protocol(self.c).assemble_request(http.Request( + '', + 'GET', + 'https', + '', + '', + '/', + (2, 0), + None, + None, + )) assert len(bytes) == 1 assert bytes[0] == '00000d0105000000018284874188089d5c0b8170dc07'.decode('hex') - def test_create_request_with_body(self): - bytes = http2.HTTP2Protocol(self.c).create_request( - 'GET', '/', [(b'foo', b'bar')], 'foobar') + def test_assemble_request_with_body(self): + bytes = http2.HTTP2Protocol(self.c).assemble_request(http.Request( + '', + 'GET', + 'https', + '', + '', + '/', + (2, 0), + odict.ODictCaseless([('foo', 'bar')]), + 'foobar', + )) assert len(bytes) == 2 assert bytes[0] ==\ '0000150104000000018284874188089d5c0b8170dc07408294e7838c767f'.decode('hex') @@ -250,11 +269,12 @@ class TestReadResponse(tservers.ServerTestBase): c.connect() c.convert_to_ssl() protocol = http2.HTTP2Protocol(c) + protocol.connection_preface_performed = True resp = protocol.read_response() - assert resp.httpversion == "HTTP/2" - assert resp.status_code == "200" + assert resp.httpversion == (2, 0) + assert resp.status_code == 200 assert resp.msg == "" assert resp.headers.lst == [[':status', '200'], ['etag', 'foobar']] assert resp.body == b'foobar' @@ -275,12 +295,13 @@ class TestReadEmptyResponse(tservers.ServerTestBase): c.connect() c.convert_to_ssl() protocol = http2.HTTP2Protocol(c) + protocol.connection_preface_performed = True resp = protocol.read_response() assert resp.stream_id - assert resp.httpversion == "HTTP/2" - assert resp.status_code == "200" + assert resp.httpversion == (2, 0) + assert resp.status_code == 200 assert resp.msg == "" assert resp.headers.lst == [[':status', '200'], ['etag', 'foobar']] assert resp.body == b'' @@ -303,6 +324,7 @@ class TestReadRequest(tservers.ServerTestBase): c.connect() c.convert_to_ssl() protocol = http2.HTTP2Protocol(c, is_server=True) + protocol.connection_preface_performed = True resp = protocol.read_request() @@ -315,16 +337,24 @@ class TestCreateResponse(): c = tcp.TCPClient(("127.0.0.1", 0)) def test_create_response_simple(self): - bytes = http2.HTTP2Protocol(self.c, is_server=True).create_response(200) + bytes = http2.HTTP2Protocol(self.c, is_server=True).assemble_response(http.Response( + (2, 0), + 200, + )) assert len(bytes) == 1 assert bytes[0] ==\ '00000101050000000288'.decode('hex') def test_create_response_with_body(self): - bytes = http2.HTTP2Protocol(self.c, is_server=True).create_response( - 200, 1, [(b'foo', b'bar')], 'foobar') + bytes = http2.HTTP2Protocol(self.c, is_server=True).assemble_response(http.Response( + (2, 0), + 200, + '', + odict.ODictCaseless([('foo', 'bar')]), + 'foobar' + )) assert len(bytes) == 2 assert bytes[0] ==\ - '00000901040000000188408294e7838c767f'.decode('hex') + '00000901040000000288408294e7838c767f'.decode('hex') assert bytes[1] ==\ - '000006000100000001666f6f626172'.decode('hex') + '000006000100000002666f6f626172'.decode('hex') |