Skip to content

Commit

Permalink
Adding system test to verify that requests never forms body when `str…
Browse files Browse the repository at this point in the history
…eam=True`.
  • Loading branch information
dhermes committed Aug 1, 2017
1 parent 73d3053 commit 19742bc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/system/requests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
PLAIN_TEXT = u'text/plain'
ENCRYPTED_ERR = (
b'The target object is encrypted by a customer-supplied encryption key.')
NO_BODY_ERR = (
u'The content for this response was already consumed')


@pytest.fixture(scope=u'module')
Expand Down Expand Up @@ -99,6 +101,29 @@ def test_download_full(add_files, authorized_transport):
check_tombstoned(download, authorized_transport)


def test_download_to_stream(add_files, authorized_transport):
for img_file in IMG_FILES:
with open(img_file, u'rb') as file_obj:
actual_contents = file_obj.read()

blob_name = os.path.basename(img_file)

# Create the actual download object.
media_url = utils.DOWNLOAD_URL_TEMPLATE.format(blob_name=blob_name)
stream = io.BytesIO()
download = resumable_requests.Download(media_url, stream=stream)
# Consume the resource.
response = download.consume(authorized_transport)
assert response.status_code == http_client.OK
with pytest.raises(RuntimeError) as exc_info:
getattr(response, u'content')
assert exc_info.value.args == (NO_BODY_ERR,)
assert response._content is False
assert response._content_consumed is True
assert stream.getvalue() == actual_contents
check_tombstoned(download, authorized_transport)


@pytest.fixture(scope=u'module')
def secret_file(authorized_transport):
blob_name = u'super-seekrit.txt'
Expand Down

0 comments on commit 19742bc

Please sign in to comment.