Esempio n. 1
0
    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")
                                          ]))
            ]))
Esempio n. 2
0
 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__)
Esempio n. 3
0
 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__)
Esempio n. 4
0
 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__)
Esempio n. 5
0
 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__)
Esempio n. 6
0
 def test_empty(self):
     self.assertEqual("", str(TextList([])))
Esempio n. 7
0
 def test_comma_delimiter(self):
     self.assertEqual(
         "test,123",
         str(TextList([ColorText("test"), ColorText(123)], delimiter=",")))
Esempio n. 8
0
 def test_default_delimiter(self):
     self.assertEqual("test\n123",
                      str(TextList([ColorText("test"),
                                    ColorText(123)])))