From be6e9b796f402199c24de3e3b1deecc0f200462c Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 26 Sep 2014 15:18:31 -0400 Subject: [PATCH] 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)