Skip to content

Commit

Permalink
Python Streaming Test Fix (#953)
Browse files Browse the repository at this point in the history
* Debugging test failure

* testing without header

* Adding header back again
  • Loading branch information
annatisch authored and amarzavery committed Apr 15, 2016
1 parent 29dc46d commit 91d73c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions ClientRuntimes/Python/msrest/msrest/service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 91d73c6

Please sign in to comment.