Skip to content

Commit

Permalink
Review Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelnucfin committed Feb 4, 2018
1 parent 1d0aae7 commit fb2b43b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def test__do_multipart_upload_bad_size(self):

def _initiate_resumable_helper(
self, size=None, extra_headers=None, chunk_size=None,
num_retries=None, user_project=None):
num_retries=None, user_project=None, predefined_acl=None):
from google.resumable_media.requests import ResumableUpload

bucket = _Bucket(name='whammy', user_project=user_project)
Expand All @@ -1013,7 +1013,6 @@ def _initiate_resumable_helper(
data = b'hello hallo halo hi-low'
stream = io.BytesIO(data)
content_type = u'text/plain'
predefined_acl = 'private'
upload, transport = blob._initiate_resumable_upload(
client, stream, content_type, size, num_retries,
extra_headers=extra_headers,
Expand All @@ -1027,7 +1026,8 @@ def _initiate_resumable_helper(
'/o?uploadType=resumable')
if user_project is not None:
upload_url += '&userProject={}'.format(user_project)
upload_url += '&predefinedAcl={}'.format(predefined_acl)
if predefined_acl is not None:
upload_url += '&predefinedAcl={}'.format(predefined_acl)
self.assertEqual(upload.upload_url, upload_url)
if extra_headers is None:
self.assertEqual(upload._headers, {})
Expand Down Expand Up @@ -1094,6 +1094,9 @@ def test__initiate_resumable_upload_with_extra_headers(self):
def test__initiate_resumable_upload_with_retry(self):
self._initiate_resumable_helper(num_retries=11)

def test__initiate_resumable_upload_with_predefined_acl(self):
self._initiate_resumable_helper(predefined_acl='private')

def _make_resumable_transport(self, headers1, headers2,
headers3, total_bytes):
from google import resumable_media
Expand Down Expand Up @@ -1162,7 +1165,7 @@ def _do_resumable_upload_call2(blob, content_type, data,
return mock.call(
'PUT', resumable_url, data=payload, headers=expected_headers)

def _do_resumable_helper(self, use_size=False, num_retries=None):
def _do_resumable_helper(self, use_size=False, num_retries=None, predefined_acl=None):
bucket = _Bucket(name='yesterday')
blob = self._make_one(u'blob-name', bucket=bucket)
blob.chunk_size = blob._CHUNK_SIZE_MULTIPLE
Expand All @@ -1187,7 +1190,6 @@ def _do_resumable_helper(self, use_size=False, num_retries=None):
client = mock.Mock(_http=transport, spec=['_http'])
stream = io.BytesIO(data)
content_type = u'text/html'
predefined_acl = 'private'
response = blob._do_resumable_upload(
client, stream, content_type, size, num_retries, None)

Expand All @@ -1213,7 +1215,7 @@ def test__do_resumable_upload_with_size(self):
def test__do_resumable_upload_with_retry(self):
self._do_resumable_helper(num_retries=6)

def _do_upload_helper(self, chunk_size=None, num_retries=None):
def _do_upload_helper(self, chunk_size=None, num_retries=None, predefined_acl=None):
blob = self._make_one(u'blob-name', bucket=None)

# Create a fake response.
Expand All @@ -1233,7 +1235,6 @@ def _do_upload_helper(self, chunk_size=None, num_retries=None):
stream = mock.sentinel.stream
content_type = u'video/mp4'
size = 12345654321
predefined_acl = 'private'
# Make the request and check the mocks.
created_json = blob._do_upload(
client, stream, content_type, size, num_retries, predefined_acl)
Expand Down Expand Up @@ -1264,7 +1265,6 @@ def _upload_from_file_helper(self, side_effect=None, **kwargs):
from google.cloud.storage.acl import ACL

blob = self._make_one('blob-name', bucket=None)
blob._acl = mock.create_autospec(ACL)
# Mock low-level upload helper on blob (it is tested elsewhere).
created_json = {'updated': '2017-01-01T09:09:09.081Z'}
blob._do_upload = mock.Mock(return_value=created_json, spec=[])
Expand Down Expand Up @@ -1294,7 +1294,6 @@ def _upload_from_file_helper(self, side_effect=None, **kwargs):
blob._do_upload.assert_called_once_with(
client, stream, content_type,
len(data), num_retries, predefined_acl)

return stream

def test_upload_from_file_success(self):
Expand Down

0 comments on commit fb2b43b

Please sign in to comment.