示例#1
0
 def test_get_with_handler_and_base_uri(self):
     c = C.Client("example.com", handler=X)
     x = c.get("/foo")
     y = c.get("/bar")
     z = c.get("example.org/baz")
     self.assertEqual(U.STR(x.force_body),
                      repr(["GET", "http://example.com/foo"]))
     self.assertEqual(U.STR(y.force_body),
                      repr(["GET", "http://example.com/bar"]))
     self.assertEqual(U.STR(z.force_body),
                      repr(["GET", "http://example.org/baz"]))
示例#2
0
 def test_get_with_handler_headers(self):
     c = C.Client(handler=X)
     x = c.get("example.com/headers")
     self.assertEqual(
         U.STR(x.force_body),
         repr([("Accept", "*/*"), ("Host", "example.com"),
               ("User-Agent", httpony.DEFAULT_USER_AGENT)]))
示例#3
0
 def test_unparse(self):
     x = H.Response(status=200,
                    headers=dict(Foo="bar", X="42"),
                    body="<body>")
     self.assertRegexpMatches(
         U.STR(x.unparse()),
         "\\AHTTP/1.1 200 OK\r\n((Foo|X|Content-Length): "
         "(bar|42|6)\r\n)+\r\n<body>\\Z")
示例#4
0
 def test_unparse(self):
     x = H.Request(method="POST",
                   uri="/foo",
                   headers=dict(Foo="bar", X="42"),
                   body="<body>")
     self.assertRegexpMatches(
         U.STR(x.unparse()),
         "\\APOST /foo HTTP/1.1\r\n((Foo|X|Content-Length): "
         "(bar|42|6)\r\n)+\r\n<body>\\Z")
示例#5
0
 def test_unparse_chunked(self):
     x = H.Request(method="POST",
                   uri="/foo",
                   headers=dict(Foo="bar", X="42"),
                   body=(x for x in ["<bo", "dy>"]))
     self.assertRegexpMatches(
         U.STR(x.unparse()),
         "\\APOST /foo HTTP/1.1\r\n((Foo|X|Transfer-Encoding): "
         "(bar|42|chunked)\r\n)+"
         "\r\n3\r\n<bo\r\n3\r\ndy>\r\n0\r\n\r\n\\Z")
示例#6
0
 def test_post_with_handler(self):
     c = C.Client(handler=X)
     x = c.post("example.com/foo")
     self.assertEqual(U.STR(x.force_body),
                      repr(["POST", "http://example.com/foo"]))