예제 #1
0
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_responses_w_forced_bodies(self):
     r1 = "HTTP/1.1 200 OK\r\nContent-Length: 6\r\n\r\n<body>"
     r2 = "HTTP/1.1 404 Not Found\r\n\r\n"
     r3  = "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n" \
           "4\r\nfoo \r\n7\r\nbar baz\r\n0\r\n\r\n"
     self.assertEqual(
         list(H.force_bodies(H.responses(S.IBytesStream(r1 + r2 + r3)))), [
             H.Response(status=200,
                        reason="OK",
                        headers={"Content-Length": "6"},
                        body="<body>"),
             H.Response(status=404, reason="Not Found", headers={},
                        body=""),
             H.Response(headers={"Transfer-Encoding": "chunked"},
                        body="foo bar baz")
         ])
예제 #2
0
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_response(self):
     x = H.Response("foo")
     y = H.response(x)
     z = H.response("foo")
     self.assertEqual(x, y)
     self.assertEqual(x, z)
     self.assertIs(x, y)
     self.assertIsNot(x, z)
예제 #3
0
파일: http_spec.py 프로젝트: obfusk/httpony
 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
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_init_data_str(self):
     x = H.Response("<body>")
     self.assertEqual(
         dict(x.iteritems()),
         dict(version="HTTP/1.1",
              status=200,
              reason="OK",
              headers=U.idict(),
              body=(b"<body>", )))
예제 #5
0
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_init_data_int(self):
     x = H.Response(500)
     self.assertEqual(
         dict(x.iteritems()),
         dict(version="HTTP/1.1",
              status=500,
              reason="Internal Server Error",
              headers=U.idict(),
              body=(b"", )))
예제 #6
0
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_init_data_tuple(self):
     x = H.Response((404, dict(Foo="bar"), "<body>"))
     self.assertEqual(
         dict(x.iteritems()),
         dict(version="HTTP/1.1",
              status=404,
              reason="Not Found",
              headers=U.idict(Foo="bar"),
              body=(b"<body>", )))
예제 #7
0
 def test_oops(self):
   req   = HTTP.Request(uri = "/nothing/to/see")
   resp  = Y()(req)
   self.assertEqual(resp, HTTP.Response(status = 404))
예제 #8
0
 def test_get_foo(self):
   req   = HTTP.Request(uri = "/bar/37")
   resp  = Y()(req)
   self.assertEqual(resp, HTTP.Response(body = "got bar w/ id 37"))
예제 #9
0
 def test_the_rest_post(self):
   req   = HTTP.Request(uri = "/some/where", method = "POST")
   resp  = X()(req)
   self.assertEqual(resp, HTTP.Response(status = 404,
                                        body = "some/where"))
예제 #10
0
 def test_the_rest(self):
   req   = HTTP.Request(uri = "/something/else")
   resp  = X()(req)
   self.assertEqual(resp, HTTP.Response(status = 404,
                                        body = "something/else"))
예제 #11
0
 def test_get_foo(self):
   req   = HTTP.Request(uri = "/foo/42")
   resp  = X()(req)
   self.assertEqual(resp, HTTP.Response(body = "got foo w/ id 42"))
예제 #12
0
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_eq(self):
     x = H.Response(200)
     y = H.Response(404)
     self.assertEqual(x, x)
     self.assertNotEqual(x, y)
예제 #13
0
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_init_data_wrong_tuple(self):
     with self.assertRaisesRegexp(
             TypeError, "tuple data argument "
             "must have either 2 or 3 elements"):
         H.Response((1, 2, 3, 4))
예제 #14
0
파일: http_spec.py 프로젝트: obfusk/httpony
 def test_init_data_no_mapping_etc(self):
     with self.assertRaisesRegexp(
             TypeError, "must be a mapping, "
             "tuple, int, str, bytes, "
             "or iterable"):
         H.Response(3.14)