def test_construct_color_msg_with_header(self): msg = construct_color_msg( ViewerContext.deserialize({ "host": "example.com", "path": "/index", "response": { "code": 200, "headers": [ ("Content-Type", "application/xml"), ], "body": "response".encode("base64"), }, "request": { "method": "GET", "headers": [ ("Content-Type", "application/xml"), ], }, }), "header") self.assertEqual( msg, TextList([ StatusText(200, "GET", "example.com", "/index"), Request( HttpRequest(method="GET", headers=[("Content-Type", "application/xml") ])), Response( HttpResponse(code=200, headers=[("Content-Type", "application/xml") ])) ]))
def test_simple_response(self): response = HttpResponse(headers=[("Content-Type", "application/xml")]) expected = TextList([ ColorText("Response Headers:", fg_color="blue", attrs=["bold"]), Header([("Content-Type", "application/xml")]) ]) self.assertEqual(expected.__dict__, Response(response).__dict__)
def test_simple_request(self): request = HttpRequest(headers=[("Host", "github.com")]) expected = TextList([ ColorText("Request Headers:", fg_color="blue", attrs=["bold"]), Header([("Host", "github.com")]) ]) self.assertEqual(expected.__dict__, Request(request).__dict__)
def test_two_headers(self): expected = TextList([ ColorText("Header: Value", bg_color="blue"), ColorText("Host: github.com", bg_color="blue") ]) self.assertEqual( expected.__dict__, Header([("Header", "Value"), ("Host", "github.com")]).__dict__)
def test_status_error(self): self.assertEqual( TextList([ ColorText(400, fg_color="red", attrs=["bold"]), "GET", "http://github.com/index" ], delimiter=" ").__dict__, StatusText(400, "GET", "http://github.com", "/index").__dict__)
def test_empty(self): self.assertEqual("", str(TextList([])))
def test_comma_delimiter(self): self.assertEqual( "test,123", str(TextList([ColorText("test"), ColorText(123)], delimiter=",")))
def test_default_delimiter(self): self.assertEqual("test\n123", str(TextList([ColorText("test"), ColorText(123)])))