From 7e2214ce14f4771f34a43cf9e9a6c2c8477ca4f8 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 8 Jun 2014 17:42:43 -1000 Subject: [PATCH] fix byte streaming endpoint in python3 --- httpbin/core.py | 2 +- test_httpbin.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/httpbin/core.py b/httpbin/core.py index c8b5e20..9b81d68 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -481,7 +481,7 @@ def stream_random_bytes(n): chunks = [] for i in xrange(n): - chunks.append(chr(random.randint(0, 255))) + chunks.append(os.urandom(1)) if len(chunks) == chunk_size: yield(bytes().join(chunks)) chunks = [] diff --git a/test_httpbin.py b/test_httpbin.py index eabd9c4..624b64b 100755 --- a/test_httpbin.py +++ b/test_httpbin.py @@ -134,6 +134,11 @@ class HttpbinTestCase(unittest.TestCase): self.assertEqual(len(response.get_data()), 1024) self.assertEqual(response.status_code, 200) + def test_stream_bytes(self): + response = self.app.get('/stream-bytes/1024') + self.assertEqual(len(response.get_data()), 1024) + self.assertEqual(response.status_code, 200) + if __name__ == '__main__': unittest.main()