From 1823b0fb21785625e53e7611582803c540731a91 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 26 Sep 2014 14:23:42 -0400 Subject: [PATCH 1/2] Fix issue # in test comment. --- gcloud/storage/test_bucket.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gcloud/storage/test_bucket.py b/gcloud/storage/test_bucket.py index fa5f0e9e5b14..15cc91d13ccc 100644 --- a/gcloud/storage/test_bucket.py +++ b/gcloud/storage/test_bucket.py @@ -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 #self.assertEqual(list(bucket.default_object_acl), new_acl) kw = connection._requested self.assertEqual(len(kw), 1) @@ -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'}) From be6e9b796f402199c24de3e3b1deecc0f200462c Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 26 Sep 2014 15:18:31 -0400 Subject: [PATCH 2/2] Fix #143: off-by-one range in iterator.KeyIterator.get_headers. --- gcloud/storage/iterator.py | 2 +- gcloud/storage/test_iterator.py | 34 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/gcloud/storage/iterator.py b/gcloud/storage/iterator.py index fab97e26e2d0..b2dfcff8ba11 100644 --- a/gcloud/storage/iterator.py +++ b/gcloud/storage/iterator.py @@ -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 = '' diff --git a/gcloud/storage/test_iterator.py b/gcloud/storage/test_iterator.py index c8c8feb87573..8841ddae3e46 100644 --- a/gcloud/storage/test_iterator.py +++ b/gcloud/storage/test_iterator.py @@ -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() @@ -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() @@ -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() @@ -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) @@ -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'], '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) @@ -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)