From 16d6fea9b87689c176f24089884a5c887fb8b253 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 8 Jun 2014 17:42:24 -1000 Subject: [PATCH] Fix bytes endpoint in python3 --- httpbin/core.py | 2 +- test_httpbin.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/httpbin/core.py b/httpbin/core.py index 7404260..c8b5e20 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -458,7 +458,7 @@ def random_bytes(n): random.seed(int(params['seed'])) response = make_response() - response.data = bytes().join(chr(random.randint(0, 255)) for i in xrange(n)) + response.data = os.urandom(n) response.content_type = 'application/octet-stream' return response diff --git a/test_httpbin.py b/test_httpbin.py index bedd41c..eabd9c4 100755 --- a/test_httpbin.py +++ b/test_httpbin.py @@ -129,6 +129,10 @@ class HttpbinTestCase(unittest.TestCase): self.assertEqual(len(response.get_data()), 400) self.assertEqual(response.status_code, 200) + def test_get_bytes(self): + response = self.app.get('/bytes/1024') + self.assertEqual(len(response.get_data()), 1024) + self.assertEqual(response.status_code, 200) if __name__ == '__main__':