From a07e43df8b3988f137b48957f978ad570d9dc782 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 17 Sep 2015 02:39:42 +0200 Subject: http1: add assemble_body function --- test/http/http1/test_assemble.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/http/http1/test_assemble.py b/test/http/http1/test_assemble.py index 8a0a54f1..cdc8bda9 100644 --- a/test/http/http1/test_assemble.py +++ b/test/http/http1/test_assemble.py @@ -4,8 +4,8 @@ from netlib.http import CONTENT_MISSING, Headers from netlib.http.http1.assemble import ( assemble_request, assemble_request_head, assemble_response, assemble_response_head, _assemble_request_line, _assemble_request_headers, - _assemble_response_headers -) + _assemble_response_headers, + assemble_body) from netlib.tutils import treq, raises, tresp @@ -50,6 +50,17 @@ def test_assemble_response_head(): assert b"message" not in c +def test_assemble_body(): + c = list(assemble_body(Headers(), [b"body"])) + assert c == [b"body"] + + c = list(assemble_body(Headers(transfer_encoding="chunked"), [b"123456789a", b""])) + assert c == [b"a\r\n123456789a\r\n", b"0\r\n\r\n"] + + c = list(assemble_body(Headers(transfer_encoding="chunked"), [b"123456789a"])) + assert c == [b"a\r\n123456789a\r\n", b"0\r\n\r\n"] + + def test_assemble_request_line(): assert _assemble_request_line(treq()) == b"GET /path HTTP/1.1" @@ -83,8 +94,7 @@ def test_assemble_response_headers(): r = tresp(body=b"") r.headers["Transfer-Encoding"] = b"chunked" c = _assemble_response_headers(r) - assert b"Content-Length" in c - assert b"Transfer-Encoding" not in c + assert b"Transfer-Encoding" in c assert b"Proxy-Connection" not in _assemble_response_headers( tresp(headers=Headers(Proxy_Connection=b"42")) -- cgit v1.2.3