Exemplo n.º 1
0
 def test_split_readlines(self):
     s = S.IBytesStream("foo\nbar\nbaz\n")
     t, d = s.split(10)
     y = [b"foo\n", b"bar\n", b"ba"]
     z = [b"z\n"]
     self.assertEqual(list(t), y)
     self.assertEqual(list(d), z)
Exemplo n.º 2
0
 def test_split_chunks_forced(self):
     s = S.IBytesStream("foo\nbar\nbaz\n")
     t, d = s.split(10)
     y = [b"fo", b"o\n", b"ba", b"r\n", b"ba"]
     z = b"z\n"
     self.assertEqual(d.read(), z)
     self.assertEqual(list(t.readchunks(2)), y)
Exemplo n.º 3
0
 def test_splitchunked_readlines(self):
     s = S.IBytesStream("3\nfoo\n7\nbar\nbaz\n0\nqux")
     t, d = s.splitchunked(chunker)
     y = [b"foobar\n", b"baz"]
     z = [b"qux"]
     self.assertEqual(list(t), y)
     self.assertEqual(list(d), z)
Exemplo n.º 4
0
 def test_splitchunked_readline(self):
     s = S.IBytesStream("3\nfoo\n7\nbar\nbaz\n0\nqux")
     t, d = s.splitchunked(chunker, 1)  # test bufsize too
     y = [b"foobar\n", b"baz"]
     z = b"qux"
     self.assertEqual(t.readline(), y[0])
     self.assertEqual(d.readline(), z)
     self.assertEqual(t.readline(), y[1])
Exemplo n.º 5
0
 def test_split_readline(self):
     s = S.IBytesStream("foo\nbar\nbaz\n")
     t, d = s.split(10, 1)  # test bufsize too
     y = [b"foo\n", b"bar\n", b"ba"]
     z = b"z\n"
     self.assertEqual(t.readline(), y[0])
     self.assertEqual(t.readline(), y[1])
     self.assertEqual(d.readline(), z)
     self.assertEqual(t.readline(), y[2])
Exemplo n.º 6
0
 def test_requests_w_forced_bodies(self):
     r1 = "GET /foo HTTP/1.1\r\nContent-Length: 7\r\n\r\n<body1>"
     r2 = "GET /bar HTTP/1.1\r\nContent-Length: 7\r\n\r\n<body2>"
     self.assertEqual(
         list(H.force_bodies(H.requests(S.IBytesStream(r1 + r2)))), [
             H.Request(method="GET",
                       uri="/foo",
                       headers={"Content-Length": "7"},
                       body="<body1>"),
             H.Request(method="GET",
                       uri="/bar",
                       headers={"Content-Length": "7"},
                       body="<body2>")
         ])
Exemplo n.º 7
0
 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")
         ])
Exemplo n.º 8
0
 def test_init_body_IStream(self):
     x = H.Request(body=S.IBytesStream("<body>"))
     self.assertIsInstance(x.body, type(x for x in []))
     self.assertEqual(b"".join(x.body), b"<body>")
Exemplo n.º 9
0
 def test_splitchunked(self):
     s = S.IBytesStream("3\nfoo\n7\nbar\nbaz\n0\nqux")
     t, d = s.splitchunked(chunker)
     self.assertEqual(t.read(), b"foobar\nbaz")
     self.assertEqual(d.read(), b"qux")
Exemplo n.º 10
0
 def test_readchunks(self):
     s = S.IBytesStream("foo\nbar\nbaz\n")
     y = [b"foo\nbar\n", b"baz\n"]
     self.assertEqual(list(s.readchunks(8)), y)
Exemplo n.º 11
0
 def test_readlines(self):
     s = S.IBytesStream("foo\nbar\nbaz\n")
     y = [b"foo\n", b"bar\n", b"baz\n"]
     self.assertEqual(list(s), y)
Exemplo n.º 12
0
 def test_readline(self):
     s = S.IBytesStream("foo\nbar\nbaz\n")
     y = b"foo\n"
     z = b"bar\n"
     self.assertEqual(s.readline(), y)
     self.assertEqual(s.readline(), z)
Exemplo n.º 13
0
 def test_read_n(self):
     s = S.IBytesStream("foo bar baz")
     y = b"foo bar"
     self.assertEqual(s.read(7), y)
Exemplo n.º 14
0
 def test_splitchunked_chunks(self):
     s = S.IBytesStream("3\nfoo\n7\nbar\nbaz\n0\nqux")
     t, d = s.splitchunked(chunker)
     self.assertEqual(list(t.readchunks(2)),
                      [b"fo", b"ob", b"ar", b"\nb", b"az"])
     self.assertEqual(d.read(), b"qux")