From 91d73c6bd81deebe2fd83090d60d63f38a08932a Mon Sep 17 00:00:00 2001 From: annatisch Date: Fri, 15 Apr 2016 16:19:30 -0700 Subject: [PATCH] Python Streaming Test Fix (#953) * Debugging test failure * testing without header * Adding header back again --- .../Python/Python.Tests/AcceptanceTests/file_tests.py | 8 ++++++-- ClientRuntimes/Python/msrest/msrest/service_client.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py index 22511e8de15c7..c45c3e0db6836 100644 --- a/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py +++ b/AutoRest/Generators/Python/Python.Tests/AcceptanceTests/file_tests.py @@ -60,8 +60,8 @@ def test_callback(data, response, progress=[0]): self.assertTrue(len(data) > 0) self.assertIsNotNone(response) self.assertFalse(response._content_consumed) - total = float(response.headers.get('Content-Length', 0)) - if total: + total = float(response.headers['Content-Length']) + if total < 4096: progress[0] += len(data) print("Downloading... {}%".format(int(progress[0]*100/total))) @@ -94,7 +94,11 @@ def test_callback(data, response, progress=[0]): self.assertEqual(file_length, 0) + def add_headers(adapter, request, response, *args, **kwargs): + response.headers['Content-Length'] = str(3000 * 1024 * 1024) + file_length = 0 + client._client.add_hook('response', add_headers) stream = client.files.get_file_large(callback=test_callback) for data in stream: file_length += len(data) diff --git a/ClientRuntimes/Python/msrest/msrest/service_client.py b/ClientRuntimes/Python/msrest/msrest/service_client.py index 6c27b017e111a..a204089838ddc 100644 --- a/ClientRuntimes/Python/msrest/msrest/service_client.py +++ b/ClientRuntimes/Python/msrest/msrest/service_client.py @@ -230,6 +230,8 @@ def stream_download(self, data, callback): if callback and callable(callback): callback(chunk, response=data) yield chunk + data.close() + self._adapter.close() def stream_upload(self, data, callback): """Generator for streaming request body data.