Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #143: off-by-one range in iterator.KeyIterator.get_headers. #196

Merged
merged 2 commits into from
Sep 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcloud/storage/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def has_more_data(self):

def get_headers(self):
start = self._bytes_written
end = self._bytes_written + self.key.CHUNK_SIZE
end = self._bytes_written + self.key.CHUNK_SIZE - 1

if self._total_bytes and end > self._total_bytes:
end = ''
Expand Down
6 changes: 2 additions & 4 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def test_save_default_object_acl_existing_set_new_passed(self):
bucket = self._makeOne(connection, NAME, metadata)
bucket.reload_default_object_acl()
self.assertTrue(bucket.save_default_object_acl(new_acl) is bucket)
# See: https://github.com/GoogleCloudPlatform/gcloud-python/issues/138
# See: https://github.com/GoogleCloudPlatform/gcloud-python/issues/139

This comment was marked as spam.

#self.assertEqual(list(bucket.default_object_acl), new_acl)
kw = connection._requested
self.assertEqual(len(kw), 1)
Expand All @@ -666,14 +666,12 @@ def test_clear_default_object_acl(self):
bucket = self._makeOne(connection, NAME, metadata)
bucket.reload_default_object_acl()
self.assertTrue(bucket.clear_default_object_acl() is bucket)
# See: https://github.com/GoogleCloudPlatform/gcloud-python/issues/138
# See: https://github.com/GoogleCloudPlatform/gcloud-python/issues/139
#self.assertEqual(list(bucket.default_object_acl), [])
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'PATCH')
self.assertEqual(kw[0]['path'], '/b/%s' % NAME)
# See: https://github.com/GoogleCloudPlatform/gcloud-python/issues/139
#self.assertEqual(list(bucket.default_object_acl), [])
#self.assertEqual(kw[0]['data'], {'defaultObjectAcl': []})
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})

Expand Down
34 changes: 17 additions & 17 deletions gcloud/storage/test_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,29 +206,29 @@ def test_ctor(self):

def test__iter__(self):
response1 = _Response(status=200)
response1['content-range'] = '0-10/15'
response1['content-range'] = '0-9/15'
response2 = _Response(status=200)
response2['content-range'] = '11-14/15'
connection = _Connection((response1, '01234567890'),
(response2, '1234'),
response2['content-range'] = '10-14/15'
connection = _Connection((response1, '0123456789'),
(response2, '01234'),
)
key = _Key(connection)
iterator = self._makeOne(key)
chunks = list(iterator)
self.assertEqual(len(chunks), 2)
self.assertEqual(chunks[0], '01234567890')
self.assertEqual(chunks[1], '1234')
self.assertEqual(chunks[0], '0123456789')
self.assertEqual(chunks[1], '01234')
self.assertEqual(iterator._bytes_written, 15)
self.assertEqual(iterator._total_bytes, 15)
kws = connection._requested
self.assertEqual(kws[0]['method'], 'GET')
self.assertEqual(kws[0]['url'],
self.assertEqual(kws[0]['url'],
'http://example.com/b/name/o/key?alt=media')
self.assertEqual(kws[0]['headers'], {'Range': 'bytes=0-10'})
self.assertEqual(kws[0]['headers'], {'Range': 'bytes=0-9'})
self.assertEqual(kws[1]['method'], 'GET')
self.assertEqual(kws[1]['url'],
self.assertEqual(kws[1]['url'],
'http://example.com/b/name/o/key?alt=media')
self.assertEqual(kws[1]['headers'], {'Range': 'bytes=11-'})
self.assertEqual(kws[1]['headers'], {'Range': 'bytes=10-'})

def test_reset(self):
connection = _Connection()
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_get_headers_new(self):
iterator = self._makeOne(key)
headers = iterator.get_headers()
self.assertEqual(len(headers), 1)
self.assertEqual(headers['Range'], 'bytes=0-10')
self.assertEqual(headers['Range'], 'bytes=0-9')

def test_get_headers_ok(self):
connection = _Connection()
Expand All @@ -285,7 +285,7 @@ def test_get_headers_ok(self):
iterator._total_bytes = 1000
headers = iterator.get_headers()
self.assertEqual(len(headers), 1)
self.assertEqual(headers['Range'], 'bytes=10-20')
self.assertEqual(headers['Range'], 'bytes=10-19')

def test_get_headers_off_end(self):
connection = _Connection()
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_get_next_chunk_underflow(self):

def test_get_next_chunk_200(self):
response = _Response(status=200)
response['content-range'] = '0-10/100'
response['content-range'] = '0-9/100'
connection = _Connection((response, 'CHUNK'))
key = _Key(connection)
iterator = self._makeOne(key)
Expand All @@ -323,9 +323,9 @@ def test_get_next_chunk_200(self):
self.assertEqual(iterator._total_bytes, 100)
kw, = connection._requested
self.assertEqual(kw['method'], 'GET')
self.assertEqual(kw['url'],
self.assertEqual(kw['url'],

This comment was marked as spam.

'http://example.com/b/name/o/key?alt=media')
self.assertEqual(kw['headers'], {'Range': 'bytes=0-10'})
self.assertEqual(kw['headers'], {'Range': 'bytes=0-9'})

def test_get_next_chunk_206(self):
response = _Response(status=206)
Expand All @@ -338,9 +338,9 @@ def test_get_next_chunk_206(self):
self.assertEqual(iterator._bytes_written, len(chunk))
kw, = connection._requested
self.assertEqual(kw['method'], 'GET')
self.assertEqual(kw['url'],
self.assertEqual(kw['url'],
'http://example.com/b/name/o/key?alt=media')
self.assertEqual(kw['headers'], {'Range': 'bytes=0-10'})
self.assertEqual(kw['headers'], {'Range': 'bytes=0-9'})

def test_get_next_chunk_416(self):
response = _Response(status=416)
Expand Down