Skip to content

Commit

Permalink
fix test_request on python 3 (web-platform-tests#11746)
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz authored and gsnedders committed Aug 16, 2018
1 parent 4d4c043 commit 9762614
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions tools/wptserve/tests/functional/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,38 @@ def handler(request, response):
finally:
InputFile.max_buffer_size = old_max_buf

@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_iter(self):
@wptserve.handlers.handler
def handler(request, response):
f = request.raw_input
return " ".join(line for line in f)
return b" ".join(line for line in f)

route = ("POST", "/test/test_iter", handler)
self.server.router.register(*route)
resp = self.request(route[1], method="POST", body="12345\nabcdef\r\nzyxwv")
resp = self.request(route[1], method="POST", body=b"12345\nabcdef\r\nzyxwv")
self.assertEqual(200, resp.getcode())
self.assertEqual(["12345\n", "abcdef\r\n", "zyxwv"], resp.read().split(" "))
self.assertEqual([b"12345\n", b"abcdef\r\n", b"zyxwv"], resp.read().split(b" "))

@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_iter_input_longer_than_buffer(self):
@wptserve.handlers.handler
def handler(request, response):
f = request.raw_input
return " ".join(line for line in f)
return b" ".join(line for line in f)

route = ("POST", "/test/test_iter", handler)
self.server.router.register(*route)

old_max_buf = InputFile.max_buffer_size
InputFile.max_buffer_size = 10
try:
resp = self.request(route[1], method="POST", body="12345\nabcdef\r\nzyxwv")
resp = self.request(route[1], method="POST", body=b"12345\nabcdef\r\nzyxwv")
self.assertEqual(200, resp.getcode())
self.assertEqual(["12345\n", "abcdef\r\n", "zyxwv"], resp.read().split(" "))
self.assertEqual([b"12345\n", b"abcdef\r\n", b"zyxwv"], resp.read().split(b" "))
finally:
InputFile.max_buffer_size = old_max_buf


class TestRequest(TestUsingServer):
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_body(self):
@wptserve.handlers.handler
def handler(request, response):
Expand All @@ -107,10 +104,9 @@ def handler(request, response):

route = ("POST", "/test/test_body", handler)
self.server.router.register(*route)
resp = self.request(route[1], method="POST", body="12345ab\ncdef")
self.assertEqual("12345ab\ncdef", resp.read())
resp = self.request(route[1], method="POST", body=b"12345ab\ncdef")
self.assertEqual(b"12345ab\ncdef", resp.read())

@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_route_match(self):
@wptserve.handlers.handler
def handler(request, response):
Expand All @@ -119,7 +115,7 @@ def handler(request, response):
route = ("GET", "/test/{match}_*", handler)
self.server.router.register(*route)
resp = self.request("/test/some_route")
self.assertEqual("some route", resp.read())
self.assertEqual(b"some route", resp.read())


class TestAuth(TestUsingServer):
Expand Down

0 comments on commit 9762614

Please sign in to comment.