From 649eeccb880e5c25254a71476615cf333ead0200 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 28 Oct 2015 12:56:10 -0400 Subject: [PATCH 1/2] Rename 'gcloud/_apitools' -> 'gcloud/streaming'. Works around a bug in 'nose', which forcibly ignores subpackages with leading '_'. See: http://stackoverflow.com/questions/23615924 https://github.com/nose-devs/nose/blob/master/nose/loader.py#L169. --- .coveragerc | 2 - gcloud/storage/blob.py | 4 +- gcloud/storage/test_blob.py | 12 +- gcloud/{_apitools => streaming}/__init__.py | 0 .../buffered_stream.py | 2 +- gcloud/{_apitools => streaming}/exceptions.py | 0 .../{_apitools => streaming}/http_wrapper.py | 4 +- .../{_apitools => streaming}/stream_slice.py | 2 +- .../test_buffered_stream.py | 6 +- .../test_exceptions.py | 4 +- .../test_http_wrapper.py | 66 ++--- .../test_stream_slice.py | 4 +- .../{_apitools => streaming}/test_transfer.py | 242 +++++++++--------- gcloud/{_apitools => streaming}/test_util.py | 16 +- gcloud/{_apitools => streaming}/transfer.py | 10 +- gcloud/{_apitools => streaming}/util.py | 4 +- tox.ini | 2 +- 17 files changed, 189 insertions(+), 191 deletions(-) rename gcloud/{_apitools => streaming}/__init__.py (100%) rename gcloud/{_apitools => streaming}/buffered_stream.py (97%) rename gcloud/{_apitools => streaming}/exceptions.py (100%) rename gcloud/{_apitools => streaming}/http_wrapper.py (99%) rename gcloud/{_apitools => streaming}/stream_slice.py (98%) rename gcloud/{_apitools => streaming}/test_buffered_stream.py (95%) rename gcloud/{_apitools => streaming}/test_exceptions.py (95%) rename gcloud/{_apitools => streaming}/test_http_wrapper.py (93%) rename gcloud/{_apitools => streaming}/test_stream_slice.py (94%) rename gcloud/{_apitools => streaming}/test_transfer.py (91%) rename gcloud/{_apitools => streaming}/test_util.py (81%) rename gcloud/{_apitools => streaming}/transfer.py (99%) rename gcloud/{_apitools => streaming}/util.py (97%) diff --git a/.coveragerc b/.coveragerc index 5f8115c03edd..77dd56b8e2e8 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,8 +3,6 @@ omit = */demo/* */demo.py */_generated/*.py - # Exclude the forked code until tests are complete. - */_apitools/*.py exclude_lines = # Re-enable the standard pragma pragma: NO COVER diff --git a/gcloud/storage/blob.py b/gcloud/storage/blob.py index 57330288e90d..409cd426ede6 100644 --- a/gcloud/storage/blob.py +++ b/gcloud/storage/blob.py @@ -25,8 +25,8 @@ import six from six.moves.urllib.parse import quote # pylint: disable=F0401 -from gcloud._apitools import http_wrapper -from gcloud._apitools import transfer +from gcloud.streaming import http_wrapper +from gcloud.streaming import transfer from gcloud._helpers import _RFC3339_MICROS from gcloud._helpers import UTC diff --git a/gcloud/storage/test_blob.py b/gcloud/storage/test_blob.py index ed5bd6bdd7da..0e8cbf7b42bc 100644 --- a/gcloud/storage/test_blob.py +++ b/gcloud/storage/test_blob.py @@ -409,8 +409,8 @@ def test_upload_from_file_resumable(self): from six.moves.urllib.parse import urlsplit from tempfile import NamedTemporaryFile from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper - from gcloud._apitools import transfer + from gcloud.streaming import http_wrapper + from gcloud.streaming import transfer BLOB_NAME = 'blob-name' UPLOAD_URL = 'http://example.com/upload/name/key' DATA = b'ABCDEF' @@ -470,7 +470,7 @@ def test_upload_from_file_w_slash_in_name(self): from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit from tempfile import NamedTemporaryFile - from gcloud._apitools import http_wrapper + from gcloud.streaming import http_wrapper BLOB_NAME = 'parent/child' UPLOAD_URL = 'http://example.com/upload/name/parent%2Fchild' DATA = b'ABCDEF' @@ -518,7 +518,7 @@ def _upload_from_filename_test_helper(self, properties=None, from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit from tempfile import NamedTemporaryFile - from gcloud._apitools import http_wrapper + from gcloud.streaming import http_wrapper BLOB_NAME = 'blob-name' UPLOAD_URL = 'http://example.com/upload/name/key' DATA = b'ABCDEF' @@ -584,7 +584,7 @@ def test_upload_from_string_w_bytes(self): from six.moves.http_client import OK from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit - from gcloud._apitools import http_wrapper + from gcloud.streaming import http_wrapper BLOB_NAME = 'blob-name' UPLOAD_URL = 'http://example.com/upload/name/key' DATA = b'ABCDEF' @@ -623,7 +623,7 @@ def test_upload_from_string_w_text(self): from six.moves.http_client import OK from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit - from gcloud._apitools import http_wrapper + from gcloud.streaming import http_wrapper BLOB_NAME = 'blob-name' UPLOAD_URL = 'http://example.com/upload/name/key' DATA = u'ABCDEF\u1234' diff --git a/gcloud/_apitools/__init__.py b/gcloud/streaming/__init__.py similarity index 100% rename from gcloud/_apitools/__init__.py rename to gcloud/streaming/__init__.py diff --git a/gcloud/_apitools/buffered_stream.py b/gcloud/streaming/buffered_stream.py similarity index 97% rename from gcloud/_apitools/buffered_stream.py rename to gcloud/streaming/buffered_stream.py index 7daf5d2b0e6a..0920ea0499e2 100644 --- a/gcloud/_apitools/buffered_stream.py +++ b/gcloud/streaming/buffered_stream.py @@ -4,7 +4,7 @@ This class reads ahead to detect if we are at the end of the stream. """ -from gcloud._apitools import exceptions +from gcloud.streaming import exceptions # TODO(user): Consider replacing this with a StringIO. diff --git a/gcloud/_apitools/exceptions.py b/gcloud/streaming/exceptions.py similarity index 100% rename from gcloud/_apitools/exceptions.py rename to gcloud/streaming/exceptions.py diff --git a/gcloud/_apitools/http_wrapper.py b/gcloud/streaming/http_wrapper.py similarity index 99% rename from gcloud/_apitools/http_wrapper.py rename to gcloud/streaming/http_wrapper.py index fa5c24032f96..f9e7673b9933 100644 --- a/gcloud/_apitools/http_wrapper.py +++ b/gcloud/streaming/http_wrapper.py @@ -16,8 +16,8 @@ from six.moves import http_client from six.moves.urllib import parse -from gcloud._apitools import exceptions -from gcloud._apitools import util +from gcloud.streaming import exceptions +from gcloud.streaming import util __all__ = [ 'CheckResponse', diff --git a/gcloud/_apitools/stream_slice.py b/gcloud/streaming/stream_slice.py similarity index 98% rename from gcloud/_apitools/stream_slice.py rename to gcloud/streaming/stream_slice.py index 9cbde994d77f..df3023d2b4ce 100644 --- a/gcloud/_apitools/stream_slice.py +++ b/gcloud/streaming/stream_slice.py @@ -1,7 +1,7 @@ # pylint: skip-file """Small helper class to provide a small slice of a stream.""" -from gcloud._apitools import exceptions +from gcloud.streaming import exceptions class StreamSlice(object): diff --git a/gcloud/_apitools/test_buffered_stream.py b/gcloud/streaming/test_buffered_stream.py similarity index 95% rename from gcloud/_apitools/test_buffered_stream.py rename to gcloud/streaming/test_buffered_stream.py index f0bcd8793e49..01764bbee5a6 100644 --- a/gcloud/_apitools/test_buffered_stream.py +++ b/gcloud/streaming/test_buffered_stream.py @@ -5,7 +5,7 @@ class Test_BufferedStream(unittest2.TestCase): def _getTargetClass(self): - from gcloud._apitools.buffered_stream import BufferedStream + from gcloud.streaming.buffered_stream import BufferedStream return BufferedStream def _makeOne(self, *args, **kw): @@ -63,7 +63,7 @@ def test__bytes_remaining_start_zero_shorter_than_buffer(self): def test_read_w_none(self): from io import BytesIO - from gcloud._apitools.exceptions import NotYetImplementedError + from gcloud.streaming.exceptions import NotYetImplementedError CONTENT = b'CONTENT GOES HERE' START = 0 BUFSIZE = 4 @@ -74,7 +74,7 @@ def test_read_w_none(self): def test_read_w_negative_size(self): from io import BytesIO - from gcloud._apitools.exceptions import NotYetImplementedError + from gcloud.streaming.exceptions import NotYetImplementedError CONTENT = b'CONTENT GOES HERE' START = 0 BUFSIZE = 4 diff --git a/gcloud/_apitools/test_exceptions.py b/gcloud/streaming/test_exceptions.py similarity index 95% rename from gcloud/_apitools/test_exceptions.py rename to gcloud/streaming/test_exceptions.py index 643ed6c3a99f..02af5339cb75 100644 --- a/gcloud/_apitools/test_exceptions.py +++ b/gcloud/streaming/test_exceptions.py @@ -5,7 +5,7 @@ class Test_HttpError(unittest2.TestCase): def _getTargetClass(self): - from gcloud._apitools.exceptions import HttpError + from gcloud.streaming.exceptions import HttpError return HttpError def _makeOne(self, *args, **kw): @@ -46,7 +46,7 @@ class _Response(object): class Test_RetryAfterError(unittest2.TestCase): def _getTargetClass(self): - from gcloud._apitools.exceptions import RetryAfterError + from gcloud.streaming.exceptions import RetryAfterError return RetryAfterError def _makeOne(self, *args, **kw): diff --git a/gcloud/_apitools/test_http_wrapper.py b/gcloud/streaming/test_http_wrapper.py similarity index 93% rename from gcloud/_apitools/test_http_wrapper.py rename to gcloud/streaming/test_http_wrapper.py index 947eea9032ce..ea7cf6aa6b74 100644 --- a/gcloud/_apitools/test_http_wrapper.py +++ b/gcloud/streaming/test_http_wrapper.py @@ -5,7 +5,7 @@ class Test__Httplib2Debuglevel(unittest2.TestCase): def _getTargetClass(self): - from gcloud._apitools.http_wrapper import _Httplib2Debuglevel + from gcloud.streaming.http_wrapper import _Httplib2Debuglevel return _Httplib2Debuglevel def _makeOne(self, *args, **kw): @@ -13,7 +13,7 @@ def _makeOne(self, *args, **kw): def test_wo_loggable_body_wo_http(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT request = _Request() LEVEL = 1 @@ -24,7 +24,7 @@ def test_wo_loggable_body_wo_http(self): def test_w_loggable_body_wo_http(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT request = _Request(loggable_body=object()) LEVEL = 1 @@ -36,7 +36,7 @@ def test_w_loggable_body_wo_http(self): def test_w_loggable_body_w_http(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT class _Connection(object): debuglevel = 0 @@ -64,7 +64,7 @@ def set_debuglevel(self, value): class Test_Request(unittest2.TestCase): def _getTargetClass(self): - from gcloud._apitools.http_wrapper import Request + from gcloud.streaming.http_wrapper import Request return Request def _makeOne(self, *args, **kw): @@ -79,7 +79,7 @@ def test_ctor_defaults(self): self.assertEqual(request.loggable_body, None) def test_loggable_body_setter_w_body_None(self): - from gcloud._apitools.exceptions import RequestError + from gcloud.streaming.exceptions import RequestError request = self._makeOne(body=None) with self.assertRaises(RequestError): request.loggable_body = 'abc' @@ -104,7 +104,7 @@ def test_body_setter_w_non_string(self): class Test_Response(unittest2.TestCase): def _getTargetClass(self): - from gcloud._apitools.http_wrapper import Response + from gcloud.streaming.http_wrapper import Response return Response def _makeOne(self, *args, **kw): @@ -203,23 +203,23 @@ def test_is_redirect_w_code_w_location(self): class Test_CheckResponse(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.http_wrapper import CheckResponse + from gcloud.streaming.http_wrapper import CheckResponse return CheckResponse(*args, **kw) def test_w_none(self): - from gcloud._apitools.exceptions import RequestError + from gcloud.streaming.exceptions import RequestError with self.assertRaises(RequestError): self._callFUT(None) def test_w_TOO_MANY_REQUESTS(self): - from gcloud._apitools.exceptions import BadStatusCodeError - from gcloud._apitools.http_wrapper import TOO_MANY_REQUESTS + from gcloud.streaming.exceptions import BadStatusCodeError + from gcloud.streaming.http_wrapper import TOO_MANY_REQUESTS with self.assertRaises(BadStatusCodeError): self._callFUT(_Response(TOO_MANY_REQUESTS)) def test_w_50x(self): - from gcloud._apitools.exceptions import BadStatusCodeError + from gcloud.streaming.exceptions import BadStatusCodeError with self.assertRaises(BadStatusCodeError): self._callFUT(_Response(500)) @@ -228,7 +228,7 @@ def test_w_50x(self): self._callFUT(_Response(503)) def test_w_retry_after(self): - from gcloud._apitools.exceptions import RetryAfterError + from gcloud.streaming.exceptions import RetryAfterError with self.assertRaises(RetryAfterError): self._callFUT(_Response(200, 20)) @@ -240,7 +240,7 @@ def test_pass(self): class Test_RebuildHttpConnections(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.http_wrapper import RebuildHttpConnections + from gcloud.streaming.http_wrapper import RebuildHttpConnections return RebuildHttpConnections(*args, **kw) def test_wo_connections(self): @@ -259,13 +259,13 @@ class Test_HandleExceptionsAndRebuildHttpConnections(unittest2.TestCase): URL = 'http://example.com/api' def _callFUT(self, *args, **kw): - from gcloud._apitools.http_wrapper import ( + from gcloud.streaming.http_wrapper import ( HandleExceptionsAndRebuildHttpConnections) return HandleExceptionsAndRebuildHttpConnections(*args, **kw) def _monkeyMUT(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT _logged = [] def _debug(msg, *args): @@ -433,7 +433,7 @@ def test_w_ValueError(self): def test_w_RequestError(self): import random from gcloud._testing import _Monkey - from gcloud._apitools.exceptions import RequestError + from gcloud.streaming.exceptions import RequestError exc = RequestError('uh oh') retry_args = self._build_retry_args(exc) monkey, logged, slept = self._monkeyMUT() @@ -448,7 +448,7 @@ def test_w_RequestError(self): def test_w_BadStatusCodeError(self): import random from gcloud._testing import _Monkey - from gcloud._apitools.exceptions import BadStatusCodeError + from gcloud.streaming.exceptions import BadStatusCodeError response = _Response(500) exc = BadStatusCodeError.FromResponse(response) retry_args = self._build_retry_args(exc) @@ -462,8 +462,8 @@ def test_w_BadStatusCodeError(self): logged, slept, 'Response returned status %s, retrying', (500,)) def test_w_RetryAfterError(self): - from gcloud._apitools.exceptions import RetryAfterError - from gcloud._apitools.http_wrapper import TOO_MANY_REQUESTS + from gcloud.streaming.exceptions import RetryAfterError + from gcloud.streaming.http_wrapper import TOO_MANY_REQUESTS RETRY_AFTER = 25 response = _Response(TOO_MANY_REQUESTS, RETRY_AFTER) exc = RetryAfterError.FromResponse(response) @@ -500,7 +500,7 @@ def _raises(): class Test__MakeRequestNoRetry(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.http_wrapper import _MakeRequestNoRetry + from gcloud.streaming.http_wrapper import _MakeRequestNoRetry return _MakeRequestNoRetry(*args, **kw) def _verify_requested(self, http, request, @@ -516,7 +516,7 @@ def _verify_requested(self, http, request, def test_defaults_wo_connections(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT INFO = {'status': '200'} CONTENT = 'CONTENT' _http = _Http((INFO, CONTENT)) @@ -535,7 +535,7 @@ def test_defaults_wo_connections(self): def test_w_explicit_redirections(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT INFO = {'status': '200'} CONTENT = 'CONTENT' _http = _Http((INFO, CONTENT)) @@ -555,7 +555,7 @@ def test_w_explicit_redirections(self): def test_w_http_connections_miss(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT INFO = {'status': '200'} CONTENT = 'CONTENT' CONN_TYPE = object() @@ -576,7 +576,7 @@ def test_w_http_connections_miss(self): def test_w_http_connections_hit(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT INFO = {'status': '200'} CONTENT = 'CONTENT' CONN_TYPE = object() @@ -597,8 +597,8 @@ def test_w_http_connections_hit(self): def test_w_request_returning_None(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT - from gcloud._apitools.exceptions import RequestError + from gcloud.streaming import http_wrapper as MUT + from gcloud.streaming.exceptions import RequestError INFO = None CONTENT = None CONN_TYPE = object() @@ -615,7 +615,7 @@ def test_w_request_returning_None(self): class Test_MakeRequest(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.http_wrapper import MakeRequest + from gcloud.streaming.http_wrapper import MakeRequest return MakeRequest(*args, **kw) def test_wo_exception(self): @@ -724,12 +724,12 @@ def _retry(args): class Test__RegisterHttpFactory(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.http_wrapper import _RegisterHttpFactory + from gcloud.streaming.http_wrapper import _RegisterHttpFactory return _RegisterHttpFactory(*args, **kw) def test_it(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT _factories = [] FACTORY = object() @@ -742,13 +742,13 @@ def test_it(self): class Test_GetHttp(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.http_wrapper import GetHttp + from gcloud.streaming.http_wrapper import GetHttp return GetHttp(*args, **kw) def test_wo_registered_factories(self): from httplib2 import Http from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT _factories = [] with _Monkey(MUT, _HTTP_FACTORIES=_factories): @@ -758,7 +758,7 @@ def test_wo_registered_factories(self): def test_w_registered_factories(self): from gcloud._testing import _Monkey - from gcloud._apitools import http_wrapper as MUT + from gcloud.streaming import http_wrapper as MUT FOUND = object() diff --git a/gcloud/_apitools/test_stream_slice.py b/gcloud/streaming/test_stream_slice.py similarity index 94% rename from gcloud/_apitools/test_stream_slice.py rename to gcloud/streaming/test_stream_slice.py index 7deee2d89f78..fabb68a49eea 100644 --- a/gcloud/_apitools/test_stream_slice.py +++ b/gcloud/streaming/test_stream_slice.py @@ -5,7 +5,7 @@ class Test_StreamSlice(unittest2.TestCase): def _getTargetClass(self): - from gcloud._apitools.stream_slice import StreamSlice + from gcloud.streaming.stream_slice import StreamSlice return StreamSlice def _makeOne(self, *args, **kw): @@ -41,7 +41,7 @@ def test___nonzero___nonempty(self): def test_read_exhausted(self): from io import BytesIO - from gcloud._apitools.exceptions import StreamExhausted + from gcloud.streaming.exceptions import StreamExhausted CONTENT = b'' MAXSIZE = 4 stream = BytesIO(CONTENT) diff --git a/gcloud/_apitools/test_transfer.py b/gcloud/streaming/test_transfer.py similarity index 91% rename from gcloud/_apitools/test_transfer.py rename to gcloud/streaming/test_transfer.py index f94b9d62703c..d8a11ee3341b 100644 --- a/gcloud/_apitools/test_transfer.py +++ b/gcloud/streaming/test_transfer.py @@ -6,7 +6,7 @@ class Test__Transfer(unittest2.TestCase): URL = 'http://example.com/api' def _getTargetClass(self): - from gcloud._apitools.transfer import _Transfer + from gcloud.streaming.transfer import _Transfer return _Transfer def _makeOne(self, *args, **kw): @@ -60,14 +60,14 @@ def test_bytes_http_setter(self): self.assertTrue(xfer.bytes_http is BYTES_HTTP) def test_num_retries_setter_invalid(self): - from gcloud._apitools.exceptions import TypecheckError + from gcloud.streaming.exceptions import TypecheckError stream = _Stream() xfer = self._makeOne(stream) with self.assertRaises(TypecheckError): xfer.num_retries = object() def test_num_retries_setter_negative(self): - from gcloud._apitools.exceptions import InvalidDataError + from gcloud.streaming.exceptions import InvalidDataError stream = _Stream() xfer = self._makeOne(stream) with self.assertRaises(InvalidDataError): @@ -101,7 +101,7 @@ def test__Initialize_w_existing_http(self): self.assertTrue(xfer.url is self.URL) def test__Initialize_already_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError URL_2 = 'http://example.com/other' HTTP_1, HTTP_2 = object(), object() stream = _Stream() @@ -118,7 +118,7 @@ def test_EnsureInitialized_hit(self): xfer.EnsureInitialized() # no raise def test_EnsureInitialized_miss(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError stream = _Stream() xfer = self._makeOne(stream) with self.assertRaises(TransferInvalidError): @@ -130,7 +130,7 @@ def test_EnsureUninitialized_hit(self): xfer.EnsureUninitialized() # no raise def test_EnsureUninitialized_miss(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError stream = _Stream() HTTP = object() xfer = self._makeOne(stream) @@ -152,7 +152,7 @@ class Test_Download(unittest2.TestCase): URL = "http://example.com/api" def _getTargetClass(self): - from gcloud._apitools.transfer import Download + from gcloud.streaming.transfer import Download return Download def _makeOne(self, *args, **kw): @@ -183,7 +183,7 @@ def test_ctor_w_total_size(self): def test_FromFile_w_existing_file_no_override(self): import os - from gcloud._apitools.exceptions import InvalidUserInputError + from gcloud.streaming.exceptions import InvalidUserInputError klass = self._getTargetClass() with _tempdir() as tempdir: filename = os.path.join(tempdir, 'file.out') @@ -262,7 +262,7 @@ def test__SetTotal_w_content_range_w_asterisk_total(self): self.assertEqual(download.total_size, 0) def test_InitializeDownload_already_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError request = _Request() download = self._makeOne(_Stream()) download._Initialize(None, self.URL) @@ -270,7 +270,7 @@ def test_InitializeDownload_already_initialized(self): download.InitializeDownload(request, http=object()) def test_InitializeDownload_wo_http_or_client(self): - from gcloud._apitools.exceptions import UserError + from gcloud.streaming.exceptions import UserError request = _Request() download = self._makeOne(_Stream()) with self.assertRaises(UserError): @@ -297,8 +297,8 @@ def test_InitializeDownload_w_client_wo_autotransfer(self): def test_InitializeDownload_w_autotransfer_failing(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.exceptions import HttpError + from gcloud.streaming import transfer as MUT + from gcloud.streaming.exceptions import HttpError request = _Request() http = object() download = self._makeOne(_Stream(), auto_transfer=True) @@ -317,7 +317,7 @@ def test_InitializeDownload_w_autotransfer_failing(self): def test_InitializeDownload_w_autotransfer_w_content_location(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT REDIRECT_URL = 'http://example.com/other' request = _Request() http = object() @@ -338,7 +338,7 @@ def test_InitializeDownload_w_autotransfer_w_content_location(self): self.assertTrue(requester._requested[0][0] is request) def test__NormalizeStartEnd_w_end_w_start_lt_0(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError request = _Request() download = self._makeOne(_Stream()) @@ -346,7 +346,7 @@ def test__NormalizeStartEnd_w_end_w_start_lt_0(self): download._NormalizeStartEnd(-1, 0) def test__NormalizeStartEnd_w_end_w_start_gt_total(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError request = _Request() download = self._makeOne(_Stream()) download._SetTotal({'content-range': 'bytes 0-1/2'}) @@ -355,7 +355,7 @@ def test__NormalizeStartEnd_w_end_w_start_gt_total(self): download._NormalizeStartEnd(3, 0) def test__NormalizeStartEnd_w_end_lt_start(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError request = _Request() download = self._makeOne(_Stream()) download._SetTotal({'content-range': 'bytes 0-1/2'}) @@ -430,7 +430,7 @@ def test__ComputeEndByte_w_start_ge_0_wo_end_w_total_size(self): self.assertEqual(download._ComputeEndByte(0, use_chunks=False), 9) def test__GetChunk_not_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError request = _Request() http = object() download = self._makeOne(_Stream()) @@ -441,7 +441,7 @@ def test__GetChunk_not_initialized(self): def test__GetChunk_wo_additional_headers(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT request = _Request() http = object() download = self._makeOne(_Stream()) @@ -463,7 +463,7 @@ def test__GetChunk_wo_additional_headers(self): def test__GetChunk_w_additional_headers(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT request = _Request() http = object() headers = {'foo': 'bar'} @@ -485,7 +485,7 @@ def test__GetChunk_w_additional_headers(self): self.assertEqual(request.headers['foo'], 'bar') def test__ProcessResponse_w_FORBIDDEN(self): - from gcloud._apitools.exceptions import HttpError + from gcloud.streaming.exceptions import HttpError from six.moves import http_client download = self._makeOne(_Stream()) response = _makeResponse(http_client.FORBIDDEN) @@ -493,7 +493,7 @@ def test__ProcessResponse_w_FORBIDDEN(self): download._ProcessResponse(response) def test__ProcessResponse_w_NOT_FOUND(self): - from gcloud._apitools.exceptions import HttpError + from gcloud.streaming.exceptions import HttpError from six.moves import http_client download = self._makeOne(_Stream()) response = _makeResponse(http_client.NOT_FOUND) @@ -501,7 +501,7 @@ def test__ProcessResponse_w_NOT_FOUND(self): download._ProcessResponse(response) def test__ProcessResponse_w_other_error(self): - from gcloud._apitools.exceptions import TransferRetryError + from gcloud.streaming.exceptions import TransferRetryError from six.moves import http_client download = self._makeOne(_Stream()) response = _makeResponse(http_client.BAD_REQUEST) @@ -555,7 +555,7 @@ def test__ProcessResponse_w_NO_CONTENT(self): self.assertEqual(download.encoding, None) def test_GetRange_not_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError request = _Request() http = object() download = self._makeOne(_Stream()) @@ -565,7 +565,7 @@ def test_GetRange_not_initialized(self): def test_GetRange_wo_total_size_complete(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) REQ_RANGE = 'bytes=0-%d' % (LEN,) @@ -594,7 +594,7 @@ def test_GetRange_wo_total_size_complete(self): def test_GetRange_wo_total_size_wo_end(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) START = 5 @@ -625,7 +625,7 @@ def test_GetRange_wo_total_size_wo_end(self): def test_GetRange_w_total_size_partial_w_additional_headers(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) PARTIAL_LEN = 5 @@ -658,8 +658,8 @@ def test_GetRange_w_total_size_partial_w_additional_headers(self): def test_GetRange_w_empty_chunk(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.exceptions import TransferRetryError + from gcloud.streaming import transfer as MUT + from gcloud.streaming.exceptions import TransferRetryError CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) START = 5 @@ -691,7 +691,7 @@ def test_GetRange_w_empty_chunk(self): def test_GetRange_w_total_size_wo_use_chunks(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) CHUNK_SIZE = 3 @@ -721,7 +721,7 @@ def test_GetRange_w_total_size_wo_use_chunks(self): def test_GetRange_w_multiple_chunks(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDE' LEN = len(CONTENT) CHUNK_SIZE = 3 @@ -786,8 +786,8 @@ def _stream_media(additional_headers=None, use_chunks=False): def test_StreamMedia_not_initialized(self): from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming import transfer as MUT + from gcloud.streaming.exceptions import TransferInvalidError download = self._makeOne(_Stream()) with _Monkey(MUT, http_wrapper=_Dummy()): @@ -797,7 +797,7 @@ def test_StreamMedia_not_initialized(self): def test_StreamMedia_w_initial_response_complete(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) RESP_RANGE = 'bytes 0-%d/%d' % (LEN - 1, LEN,) @@ -819,7 +819,7 @@ def test_StreamMedia_w_initial_response_complete(self): def test_StreamMedia_w_initial_response_incomplete(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CHUNK_SIZE = 3 CONTENT = 'ABCDEF' LEN = len(CONTENT) @@ -857,7 +857,7 @@ def test_StreamMedia_w_initial_response_incomplete(self): def test_StreamMedia_wo_initial_response_wo_total_size(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) CHUNK_SIZE = 123 @@ -888,7 +888,7 @@ def test_StreamMedia_wo_initial_response_wo_total_size(self): def test_StreamMedia_wo_initial_response_w_addl_headers_wo_chunks(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT + from gcloud.streaming import transfer as MUT CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) CHUNK_SIZE = 123 @@ -924,7 +924,7 @@ class Test_Upload(unittest2.TestCase): UPLOAD_URL = 'http://example.com/upload/id=foobar' def _getTargetClass(self): - from gcloud._apitools.transfer import Upload + from gcloud.streaming.transfer import Upload return Upload def _makeOne(self, stream, mime_type=MIME_TYPE, *args, **kw): @@ -951,7 +951,7 @@ def test_ctor_w_kwds(self): self.assertEqual(upload.chunksize, CHUNK_SIZE) def test_FromFile_w_nonesuch_file(self): - from gcloud._apitools.exceptions import NotFoundError + from gcloud.streaming.exceptions import NotFoundError klass = self._getTargetClass() filename = '~nosuchuser/file.txt' with self.assertRaises(NotFoundError): @@ -959,7 +959,7 @@ def test_FromFile_w_nonesuch_file(self): def test_FromFile_wo_mimetype_w_unguessable_filename(self): import os - from gcloud._apitools.exceptions import InvalidUserInputError + from gcloud.streaming.exceptions import InvalidUserInputError klass = self._getTargetClass() CONTENT = 'EXISTING FILE W/ UNGUESSABLE MIMETYPE' with _tempdir() as tempdir: @@ -1002,7 +1002,7 @@ def test_FromFile_w_mimetype_w_auto_transfer_w_kwds(self): self.assertEqual(upload.chunksize, CHUNK_SIZE) def test_FromStream_wo_mimetype(self): - from gcloud._apitools.exceptions import InvalidUserInputError + from gcloud.streaming.exceptions import InvalidUserInputError klass = self._getTargetClass() stream = _Stream() with self.assertRaises(InvalidUserInputError): @@ -1033,7 +1033,7 @@ def test_FromStream_explicit(self): self.assertEqual(upload.chunksize, CHUNK_SIZE) def test_strategy_setter_invalid(self): - from gcloud._apitools.exceptions import UserError + from gcloud.streaming.exceptions import UserError upload = self._makeOne(_Stream()) with self.assertRaises(UserError): upload.strategy = object() @@ -1041,19 +1041,19 @@ def test_strategy_setter_invalid(self): upload.strategy = 'unknown' def test_strategy_setter_SIMPLE_UPLOAD(self): - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.transfer import SIMPLE_UPLOAD upload = self._makeOne(_Stream()) upload.strategy = SIMPLE_UPLOAD self.assertEqual(upload.strategy, SIMPLE_UPLOAD) def test_strategy_setter_RESUMABLE_UPLOAD(self): - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD upload = self._makeOne(_Stream()) upload.strategy = RESUMABLE_UPLOAD self.assertEqual(upload.strategy, RESUMABLE_UPLOAD) def test_total_size_setter_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError SIZE = 123 upload = self._makeOne(_Stream) http = object() @@ -1069,7 +1069,7 @@ def test_total_size_setter_not_initialized(self): self.assertEqual(upload.total_size, SIZE) def test__SetDefaultUploadStrategy_w_existing_strategy(self): - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD config = _Dummy( resumable_path='/resumable/endpoint', simple_multipart=True, @@ -1082,7 +1082,7 @@ def test__SetDefaultUploadStrategy_w_existing_strategy(self): self.assertEqual(upload.strategy, RESUMABLE_UPLOAD) def test__SetDefaultUploadStrategy_wo_resumable_path(self): - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.transfer import SIMPLE_UPLOAD config = _Dummy( resumable_path=None, simple_multipart=True, @@ -1094,8 +1094,8 @@ def test__SetDefaultUploadStrategy_wo_resumable_path(self): self.assertEqual(upload.strategy, SIMPLE_UPLOAD) def test__SetDefaultUploadStrategy_w_total_size_gt_threshhold(self): - from gcloud._apitools.transfer import _RESUMABLE_UPLOAD_THRESHOLD - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import _RESUMABLE_UPLOAD_THRESHOLD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD config = _UploadConfig() request = _Request() upload = self._makeOne( @@ -1104,7 +1104,7 @@ def test__SetDefaultUploadStrategy_w_total_size_gt_threshhold(self): self.assertEqual(upload.strategy, RESUMABLE_UPLOAD) def test__SetDefaultUploadStrategy_w_body_wo_multipart(self): - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' config = _UploadConfig() config.simple_multipart = False @@ -1114,7 +1114,7 @@ def test__SetDefaultUploadStrategy_w_body_wo_multipart(self): self.assertEqual(upload.strategy, RESUMABLE_UPLOAD) def test__SetDefaultUploadStrategy_w_body_w_multipart_wo_simple_path(self): - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' config = _UploadConfig() config.simple_path = None @@ -1124,7 +1124,7 @@ def test__SetDefaultUploadStrategy_w_body_w_multipart_wo_simple_path(self): self.assertEqual(upload.strategy, RESUMABLE_UPLOAD) def test__SetDefaultUploadStrategy_w_body_w_multipart_w_simple_path(self): - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.transfer import SIMPLE_UPLOAD CONTENT = 'ABCDEFGHIJ' config = _UploadConfig() request = _Request(body=CONTENT) @@ -1133,7 +1133,7 @@ def test__SetDefaultUploadStrategy_w_body_w_multipart_w_simple_path(self): self.assertEqual(upload.strategy, SIMPLE_UPLOAD) def test_ConfigureRequest_w_total_size_gt_max_size(self): - from gcloud._apitools.exceptions import InvalidUserInputError + from gcloud.streaming.exceptions import InvalidUserInputError MAX_SIZE = 1000 config = _UploadConfig() config.max_size = MAX_SIZE @@ -1144,7 +1144,7 @@ def test_ConfigureRequest_w_total_size_gt_max_size(self): upload.ConfigureRequest(config, request, url_builder) def test_ConfigureRequest_w_invalid_mimetype(self): - from gcloud._apitools.exceptions import InvalidUserInputError + from gcloud.streaming.exceptions import InvalidUserInputError config = _UploadConfig() config.accept = ('text/*',) request = _Request() @@ -1154,7 +1154,7 @@ def test_ConfigureRequest_w_invalid_mimetype(self): upload.ConfigureRequest(config, request, url_builder) def test_ConfigureRequest_w_simple_wo_body(self): - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.transfer import SIMPLE_UPLOAD CONTENT = 'CONTENT' config = _UploadConfig() request = _Request() @@ -1173,7 +1173,7 @@ def test_ConfigureRequest_w_simple_wo_body(self): def test_ConfigureRequest_w_simple_w_body(self): from email.parser import Parser - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.transfer import SIMPLE_UPLOAD CONTENT = 'CONTENT' BODY = 'BODY' config = _UploadConfig() @@ -1215,7 +1215,7 @@ def test_ConfigureRequest_w_simple_w_body(self): self.assertTrue('' in request.loggable_body) def test_ConfigureRequest_w_resumable_wo_total_size(self): - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'CONTENT' config = _UploadConfig() request = _Request() @@ -1232,7 +1232,7 @@ def test_ConfigureRequest_w_resumable_wo_total_size(self): {'X-Upload-Content-Type': self.MIME_TYPE}) def test_ConfigureRequest_w_resumable_w_total_size(self): - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'CONTENT' LEN = len(CONTENT) config = _UploadConfig() @@ -1252,14 +1252,14 @@ def test_ConfigureRequest_w_resumable_w_total_size(self): 'X-Upload-Content-Length': '%d' % (LEN,)}) def test_RefreshResumableUploadState_w_simple_strategy(self): - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.transfer import SIMPLE_UPLOAD upload = self._makeOne(_Stream()) upload.strategy = SIMPLE_UPLOAD upload.RefreshResumableUploadState() # no-op def test_RefreshResumableUploadState_not_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.exceptions import TransferInvalidError + from gcloud.streaming.transfer import RESUMABLE_UPLOAD upload = self._makeOne(_Stream()) upload.strategy = RESUMABLE_UPLOAD with self.assertRaises(TransferInvalidError): @@ -1268,8 +1268,8 @@ def test_RefreshResumableUploadState_not_initialized(self): def test_RefreshResumableUploadState_w_OK(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) RESP_RANGE = 'bytes 0-%d/%d' % (LEN - 1, LEN,) @@ -1296,8 +1296,8 @@ def test_RefreshResumableUploadState_w_OK(self): def test_RefreshResumableUploadState_w_CREATED(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) RESP_RANGE = 'bytes 0-%d/%d' % (LEN - 1, LEN,) @@ -1322,10 +1322,10 @@ def test_RefreshResumableUploadState_w_CREATED(self): self.assertTrue(upload._final_response is response) def test_RefreshResumableUploadState_w_RESUME_INCOMPLETE_w_range(self): - from gcloud._apitools import transfer as MUT - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming import transfer as MUT + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud._testing import _Monkey - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) LAST = 5 @@ -1351,10 +1351,10 @@ def test_RefreshResumableUploadState_w_RESUME_INCOMPLETE_w_range(self): self.assertFalse(upload._final_response is response) def test_RefreshResumableUploadState_w_RESUME_INCOMPLETE_wo_range(self): - from gcloud._apitools import transfer as MUT - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming import transfer as MUT + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud._testing import _Monkey - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) LAST = 5 @@ -1381,10 +1381,10 @@ def test_RefreshResumableUploadState_w_RESUME_INCOMPLETE_wo_range(self): def test_RefreshResumableUploadState_w_error(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.exceptions import HttpError - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.exceptions import HttpError + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) http = object() @@ -1419,15 +1419,15 @@ def test__GetRangeHeaderFromResponse_w_range(self): self.assertEqual(upload._GetRangeHeaderFromResponse(response), '123') def test_InitializeUpload_no_strategy(self): - from gcloud._apitools.exceptions import UserError + from gcloud.streaming.exceptions import UserError request = _Request() upload = self._makeOne(_Stream()) with self.assertRaises(UserError): upload.InitializeUpload(request, http=object()) def test_InitializeUpload_wo_client_wo_http(self): - from gcloud._apitools.exceptions import UserError - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.exceptions import UserError + from gcloud.streaming.transfer import SIMPLE_UPLOAD request = _Request() upload = self._makeOne(_Stream()) upload.strategy = SIMPLE_UPLOAD @@ -1435,15 +1435,15 @@ def test_InitializeUpload_wo_client_wo_http(self): upload.InitializeUpload(request) def test_InitializeUpload_simple_w_http(self): - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.transfer import SIMPLE_UPLOAD request = _Request() upload = self._makeOne(_Stream()) upload.strategy = SIMPLE_UPLOAD upload.InitializeUpload(request, http=object()) # no-op def test_InitializeUpload_resumable_already_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.exceptions import TransferInvalidError + from gcloud.streaming.transfer import RESUMABLE_UPLOAD request = _Request() upload = self._makeOne(_Stream()) upload.strategy = RESUMABLE_UPLOAD @@ -1454,10 +1454,10 @@ def test_InitializeUpload_resumable_already_initialized(self): def test_InitializeUpload_w_http_resumable_not_initialized_w_error(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.exceptions import HttpError - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.exceptions import HttpError + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) request = _Request() @@ -1476,9 +1476,9 @@ def test_InitializeUpload_w_http_resumable_not_initialized_w_error(self): def test_InitializeUpload_w_http_wo_auto_transfer_w_OK(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) request = _Request() @@ -1503,9 +1503,9 @@ def test_InitializeUpload_w_http_wo_auto_transfer_w_OK(self): def test_InitializeUpload_w_client_w_auto_transfer_w_OK(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' LEN = len(CONTENT) FINALIZED_URL = 'http://example.com/upload?id=foobar&final' @@ -1548,7 +1548,7 @@ def test__ValidateChunkSize_wo__server_chunk_granularity(self): upload._ValidateChunksize(123) # no-op def test__ValidateChunkSize_w__server_chunk_granularity_miss(self): - from gcloud._apitools.exceptions import ConfigurationValueError + from gcloud.streaming.exceptions import ConfigurationValueError upload = self._makeOne(_Stream()) upload._server_chunk_granularity = 100 with self.assertRaises(ConfigurationValueError): @@ -1560,16 +1560,16 @@ def test__ValidateChunkSize_w__server_chunk_granularity_hit(self): upload._ValidateChunksize(400) def test__StreamMedia_w_simple_strategy(self): - from gcloud._apitools.exceptions import InvalidUserInputError - from gcloud._apitools.transfer import SIMPLE_UPLOAD + from gcloud.streaming.exceptions import InvalidUserInputError + from gcloud.streaming.transfer import SIMPLE_UPLOAD upload = self._makeOne(_Stream()) upload.strategy = SIMPLE_UPLOAD with self.assertRaises(InvalidUserInputError): upload._StreamMedia() def test__StreamMedia_w_use_chunks_invalid_chunk_size(self): - from gcloud._apitools.exceptions import ConfigurationValueError - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.exceptions import ConfigurationValueError + from gcloud.streaming.transfer import RESUMABLE_UPLOAD upload = self._makeOne(_Stream(), chunksize=1024) upload.strategy = RESUMABLE_UPLOAD upload._server_chunk_granularity = 100 @@ -1577,8 +1577,8 @@ def test__StreamMedia_w_use_chunks_invalid_chunk_size(self): upload._StreamMedia(use_chunks=True) def test__StreamMedia_not_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.exceptions import TransferInvalidError + from gcloud.streaming.transfer import RESUMABLE_UPLOAD upload = self._makeOne(_Stream(), chunksize=1024) upload.strategy = RESUMABLE_UPLOAD upload._server_chunk_granularity = 128 @@ -1586,7 +1586,7 @@ def test__StreamMedia_not_initialized(self): upload._StreamMedia() def test__StreamMedia_already_complete_w_unseekable_stream(self): - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD http = object() stream = object() response = object() @@ -1599,8 +1599,8 @@ def test__StreamMedia_already_complete_w_unseekable_stream(self): self.assertTrue(upload._StreamMedia() is response) def test__StreamMedia_already_complete_w_seekable_stream_unsynced(self): - from gcloud._apitools.exceptions import CommunicationError - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.exceptions import CommunicationError + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) @@ -1616,7 +1616,7 @@ def test__StreamMedia_already_complete_w_seekable_stream_unsynced(self): def test__StreamMedia_already_complete_w_seekable_stream_synced(self): import os - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) @@ -1633,9 +1633,9 @@ def test__StreamMedia_already_complete_w_seekable_stream_synced(self): def test__StreamMedia_incomplete(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) @@ -1679,10 +1679,10 @@ def test__StreamMedia_incomplete(self): def test__StreamMedia_incomplete_w_transfer_error_w_addl_headers(self): from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.exceptions import CommunicationError - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.exceptions import CommunicationError + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) @@ -1751,8 +1751,8 @@ def test_StreamInChunks_explicit(self): def test__SendMediaRequest_wo_error(self): from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming import transfer as MUT + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE CONTENT = 'ABCDEFGHIJ' bytes_http = object() stream = _Stream(CONTENT) @@ -1782,10 +1782,10 @@ def test__SendMediaRequest_wo_error(self): def test__SendMediaRequest_w_error(self): from six.moves import http_client from gcloud._testing import _Monkey - from gcloud._apitools import transfer as MUT - from gcloud._apitools.exceptions import HttpError - from gcloud._apitools.http_wrapper import RESUME_INCOMPLETE - from gcloud._apitools.transfer import RESUMABLE_UPLOAD + from gcloud.streaming import transfer as MUT + from gcloud.streaming.exceptions import HttpError + from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE + from gcloud.streaming.transfer import RESUMABLE_UPLOAD CONTENT = 'ABCDEFGHIJ' bytes_http = object() http = object() @@ -1825,13 +1825,13 @@ def test__SendMediaRequest_w_error(self): self.assertTrue(second_http is http) def test__SendMediaBody_not_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError upload = self._makeOne(_Stream()) with self.assertRaises(TransferInvalidError): upload._SendMediaBody(0) def test__SendMediaBody_wo_total_size(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError http = object() upload = self._makeOne(_Stream()) upload._Initialize(http, _Request.URL) @@ -1839,7 +1839,7 @@ def test__SendMediaBody_wo_total_size(self): upload._SendMediaBody(0) def test__SendMediaBody_wo_additional_headers_start_lt_total_size(self): - from gcloud._apitools.stream_slice import StreamSlice + from gcloud.streaming.stream_slice import StreamSlice SIZE = 1234 http = object() stream = _Stream() @@ -1873,7 +1873,7 @@ def _send_media_request(request, end): self.assertEqual(end, SIZE) def test__SendMediaBody_w_additional_headers_start_eq_total_size(self): - from gcloud._apitools.stream_slice import StreamSlice + from gcloud.streaming.stream_slice import StreamSlice SIZE = 1234 http = object() stream = _Stream() @@ -1908,7 +1908,7 @@ def _send_media_request(request, end): self.assertEqual(end, SIZE) def test__SendChunk_not_initialized(self): - from gcloud._apitools.exceptions import TransferInvalidError + from gcloud.streaming.exceptions import TransferInvalidError upload = self._makeOne(_Stream()) with self.assertRaises(TransferInvalidError): upload._SendChunk(0) @@ -1977,7 +1977,7 @@ def _send_media_request(request, end): self.assertEqual(end, CHUNK_SIZE) def test__SendChunk_w_total_size_stream_not_exhausted(self): - from gcloud._apitools.stream_slice import StreamSlice + from gcloud.streaming.stream_slice import StreamSlice CONTENT = 'ABCDEFGHIJ' SIZE = len(CONTENT) CHUNK_SIZE = SIZE - 5 @@ -2011,7 +2011,7 @@ def _send_media_request(request, end): self.assertEqual(end, CHUNK_SIZE) def test__SendChunk_w_total_size_stream_exhausted_w_addl_headers(self): - from gcloud._apitools.stream_slice import StreamSlice + from gcloud.streaming.stream_slice import StreamSlice CONTENT = 'ABCDEFGHIJ' SIZE = len(CONTENT) CHUNK_SIZE = 1000 diff --git a/gcloud/_apitools/test_util.py b/gcloud/streaming/test_util.py similarity index 81% rename from gcloud/_apitools/test_util.py rename to gcloud/streaming/test_util.py index c6fa5f6368e3..3930eb2decf4 100644 --- a/gcloud/_apitools/test_util.py +++ b/gcloud/streaming/test_util.py @@ -5,25 +5,25 @@ class Test_TypeCheck(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.util import Typecheck + from gcloud.streaming.util import Typecheck return Typecheck(*args, **kw) def test_pass(self): self.assertEqual(self._callFUT(123, int), 123) def test_fail_w_explicit_msg(self): - from gcloud._apitools.exceptions import TypecheckError + from gcloud.streaming.exceptions import TypecheckError with self.assertRaises(TypecheckError) as err: self._callFUT(123, str, 'foo') self.assertEqual(err.exception.args, ('foo',)) def test_fail_w_single_type_no_msg(self): - from gcloud._apitools.exceptions import TypecheckError + from gcloud.streaming.exceptions import TypecheckError with self.assertRaises(TypecheckError) as err: self._callFUT(123, str) def test_fail_w_tuple_no_msg(self): - from gcloud._apitools.exceptions import TypecheckError + from gcloud.streaming.exceptions import TypecheckError with self.assertRaises(TypecheckError) as err: self._callFUT(123, (list, tuple)) @@ -31,7 +31,7 @@ def test_fail_w_tuple_no_msg(self): class Test_CalculateWaitForRetry(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.util import CalculateWaitForRetry + from gcloud.streaming.util import CalculateWaitForRetry return CalculateWaitForRetry(*args, **kw) def test_w_negative_jitter_lt_max_wait(self): @@ -50,11 +50,11 @@ def test_w_positive_jitter_gt_max_wait(self): class Test_AcceptableMimeType(unittest2.TestCase): def _callFUT(self, *args, **kw): - from gcloud._apitools.util import AcceptableMimeType + from gcloud.streaming.util import AcceptableMimeType return AcceptableMimeType(*args, **kw) def test_pattern_wo_slash(self): - from gcloud._apitools.exceptions import InvalidUserInputError + from gcloud.streaming.exceptions import InvalidUserInputError with self.assertRaises(InvalidUserInputError) as err: self._callFUT(['text/*'], 'BOGUS') self.assertEqual( @@ -62,7 +62,7 @@ def test_pattern_wo_slash(self): ('Invalid MIME type: "BOGUS"',)) def test_accept_pattern_w_semicolon(self): - from gcloud._apitools.exceptions import GeneratedClientError + from gcloud.streaming.exceptions import GeneratedClientError with self.assertRaises(GeneratedClientError) as err: self._callFUT(['text/*;charset=utf-8'], 'text/plain') self.assertEqual( diff --git a/gcloud/_apitools/transfer.py b/gcloud/streaming/transfer.py similarity index 99% rename from gcloud/_apitools/transfer.py rename to gcloud/streaming/transfer.py index 32de47f37dc0..6630525707ba 100644 --- a/gcloud/_apitools/transfer.py +++ b/gcloud/streaming/transfer.py @@ -14,11 +14,11 @@ import six from six.moves import http_client -from gcloud._apitools import buffered_stream -from gcloud._apitools import exceptions -from gcloud._apitools import http_wrapper -from gcloud._apitools import stream_slice -from gcloud._apitools import util +from gcloud.streaming import buffered_stream +from gcloud.streaming import exceptions +from gcloud.streaming import http_wrapper +from gcloud.streaming import stream_slice +from gcloud.streaming import util __all__ = [ 'Download', diff --git a/gcloud/_apitools/util.py b/gcloud/streaming/util.py similarity index 97% rename from gcloud/_apitools/util.py rename to gcloud/streaming/util.py index 7631a516bab7..1e07d7b90d84 100644 --- a/gcloud/_apitools/util.py +++ b/gcloud/streaming/util.py @@ -8,14 +8,14 @@ - Typecheck - AcceptableMimeType -``gcloud._apitools.http_wrapper`` uses: +``gcloud.streaming.http_wrapper`` uses: - CalculateWaitForRetry """ import random -from gcloud._apitools import exceptions +from gcloud.streaming import exceptions def Typecheck(arg, arg_type, msg=None): diff --git a/tox.ini b/tox.ini index e241e1e2e345..12423f1a79db 100644 --- a/tox.ini +++ b/tox.ini @@ -55,7 +55,7 @@ deps = {[testenv:docs]deps} passenv = {[testenv:docs]passenv} [pep8] -exclude = gcloud/datastore/_datastore_v1_pb2.py,gcloud/bigtable/_generated/*,docs/conf.py,gcloud/_apitools/* +exclude = gcloud/datastore/_datastore_v1_pb2.py,gcloud/bigtable/_generated/*,docs/conf.py,gcloud/streaming/* verbose = 1 [testenv:lint] From 137894754aff0c8cc7314f4fb2c3d3f9734b6f6e Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 28 Oct 2015 14:28:45 -0400 Subject: [PATCH 2/2] Fix Py3k testing glitches. --- gcloud/streaming/test_transfer.py | 92 +++++++++++++++---------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/gcloud/streaming/test_transfer.py b/gcloud/streaming/test_transfer.py index d8a11ee3341b..cabf65396ff9 100644 --- a/gcloud/streaming/test_transfer.py +++ b/gcloud/streaming/test_transfer.py @@ -204,7 +204,7 @@ def test_FromFile_w_existing_file_w_override_wo_auto_transfer(self): self.assertFalse(download.auto_transfer) del download # closes stream with open(filename, 'rb') as fileobj: - self.assertEqual(fileobj.read(), '') + self.assertEqual(fileobj.read(), b'') def test_FromStream_defaults(self): stream = _Stream() @@ -566,7 +566,7 @@ def test_GetRange_wo_total_size_complete(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) REQ_RANGE = 'bytes=0-%d' % (LEN,) RESP_RANGE = 'bytes 0-%d/%d' % (LEN - 1, LEN) @@ -595,7 +595,7 @@ def test_GetRange_wo_total_size_wo_end(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) START = 5 CHUNK_SIZE = 123 @@ -626,7 +626,7 @@ def test_GetRange_w_total_size_partial_w_additional_headers(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) PARTIAL_LEN = 5 REQ_RANGE = 'bytes=0-%d' % (PARTIAL_LEN,) @@ -660,7 +660,7 @@ def test_GetRange_w_empty_chunk(self): from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT from gcloud.streaming.exceptions import TransferRetryError - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) START = 5 CHUNK_SIZE = 123 @@ -692,7 +692,7 @@ def test_GetRange_w_total_size_wo_use_chunks(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) CHUNK_SIZE = 3 REQ_RANGE = 'bytes=0-%d' % (LEN - 1,) @@ -722,7 +722,7 @@ def test_GetRange_w_multiple_chunks(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDE' + CONTENT = b'ABCDE' LEN = len(CONTENT) CHUNK_SIZE = 3 REQ_RANGE_1 = 'bytes=0-%d' % (CHUNK_SIZE - 1,) @@ -754,7 +754,7 @@ def test_GetRange_w_multiple_chunks(self): self.assertEqual(request_1.headers, {'range': REQ_RANGE_1}) self.assertTrue(requester._requested[1][0] is request_2) self.assertEqual(request_2.headers, {'range': REQ_RANGE_2}) - self.assertEqual(stream._written, ['ABC', 'DE']) + self.assertEqual(stream._written, [b'ABC', b'DE']) self.assertEqual(download.total_size, LEN) def test_StreamInChunks_wo_additional_headers(self): @@ -798,7 +798,7 @@ def test_StreamMedia_w_initial_response_complete(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) RESP_RANGE = 'bytes 0-%d/%d' % (LEN - 1, LEN,) stream = _Stream() @@ -821,7 +821,7 @@ def test_StreamMedia_w_initial_response_incomplete(self): from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT CHUNK_SIZE = 3 - CONTENT = 'ABCDEF' + CONTENT = b'ABCDEF' LEN = len(CONTENT) RESP_RANGE_1 = 'bytes 0-%d/%d' % (CHUNK_SIZE - 1, LEN,) REQ_RANGE_2 = 'bytes=%d-%d' % (CHUNK_SIZE, LEN - 1) @@ -858,7 +858,7 @@ def test_StreamMedia_wo_initial_response_wo_total_size(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) CHUNK_SIZE = 123 REQ_RANGE = 'bytes=0-%d' % (CHUNK_SIZE - 1) @@ -889,7 +889,7 @@ def test_StreamMedia_wo_initial_response_w_addl_headers_wo_chunks(self): from six.moves import http_client from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) CHUNK_SIZE = 123 REQ_RANGE = 'bytes=0-' @@ -961,10 +961,10 @@ def test_FromFile_wo_mimetype_w_unguessable_filename(self): import os from gcloud.streaming.exceptions import InvalidUserInputError klass = self._getTargetClass() - CONTENT = 'EXISTING FILE W/ UNGUESSABLE MIMETYPE' + CONTENT = b'EXISTING FILE W/ UNGUESSABLE MIMETYPE' with _tempdir() as tempdir: filename = os.path.join(tempdir, 'file.unguessable') - with open(filename, 'w') as fileobj: + with open(filename, 'wb') as fileobj: fileobj.write(CONTENT) with self.assertRaises(InvalidUserInputError): klass.FromFile(filename) @@ -972,10 +972,10 @@ def test_FromFile_wo_mimetype_w_unguessable_filename(self): def test_FromFile_wo_mimetype_w_guessable_filename(self): import os klass = self._getTargetClass() - CONTENT = 'EXISTING FILE W/ GUESSABLE MIMETYPE' + CONTENT = b'EXISTING FILE W/ GUESSABLE MIMETYPE' with _tempdir() as tempdir: filename = os.path.join(tempdir, 'file.txt') - with open(filename, 'w') as fileobj: + with open(filename, 'wb') as fileobj: fileobj.write(CONTENT) upload = klass.FromFile(filename) self.assertEqual(upload.mime_type, 'text/plain') @@ -985,11 +985,11 @@ def test_FromFile_wo_mimetype_w_guessable_filename(self): def test_FromFile_w_mimetype_w_auto_transfer_w_kwds(self): import os klass = self._getTargetClass() - CONTENT = 'EXISTING FILE W/ GUESSABLE MIMETYPE' + CONTENT = b'EXISTING FILE W/ GUESSABLE MIMETYPE' CHUNK_SIZE = 3 with _tempdir() as tempdir: filename = os.path.join(tempdir, 'file.unguessable') - with open(filename, 'w') as fileobj: + with open(filename, 'wb') as fileobj: fileobj.write(CONTENT) upload = klass.FromFile( filename, @@ -1105,7 +1105,7 @@ def test__SetDefaultUploadStrategy_w_total_size_gt_threshhold(self): def test__SetDefaultUploadStrategy_w_body_wo_multipart(self): from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' config = _UploadConfig() config.simple_multipart = False request = _Request(body=CONTENT) @@ -1115,7 +1115,7 @@ def test__SetDefaultUploadStrategy_w_body_wo_multipart(self): def test__SetDefaultUploadStrategy_w_body_w_multipart_wo_simple_path(self): from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' config = _UploadConfig() config.simple_path = None request = _Request(body=CONTENT) @@ -1125,7 +1125,7 @@ def test__SetDefaultUploadStrategy_w_body_w_multipart_wo_simple_path(self): def test__SetDefaultUploadStrategy_w_body_w_multipart_w_simple_path(self): from gcloud.streaming.transfer import SIMPLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' config = _UploadConfig() request = _Request(body=CONTENT) upload = self._makeOne(_Stream(), total_size=len(CONTENT)) @@ -1155,7 +1155,7 @@ def test_ConfigureRequest_w_invalid_mimetype(self): def test_ConfigureRequest_w_simple_wo_body(self): from gcloud.streaming.transfer import SIMPLE_UPLOAD - CONTENT = 'CONTENT' + CONTENT = b'CONTENT' config = _UploadConfig() request = _Request() url_builder = _Dummy(query_params={}) @@ -1174,8 +1174,8 @@ def test_ConfigureRequest_w_simple_wo_body(self): def test_ConfigureRequest_w_simple_w_body(self): from email.parser import Parser from gcloud.streaming.transfer import SIMPLE_UPLOAD - CONTENT = 'CONTENT' - BODY = 'BODY' + CONTENT = b'CONTENT' + BODY = b'BODY' config = _UploadConfig() request = _Request(body=BODY) request.headers['content-type'] = 'text/plain' @@ -1204,19 +1204,19 @@ def test_ConfigureRequest_w_simple_w_body(self): self.assertEqual(dict(text_msg._headers), {'Content-Type': 'text/plain', 'MIME-Version': '1.0'}) - self.assertEqual(text_msg._payload, BODY) + self.assertEqual(text_msg._payload, BODY.decode('ascii')) app_msg = parser.parsestr(chunks[1].strip()) self.assertEqual(dict(app_msg._headers), {'Content-Type': self.MIME_TYPE, 'Content-Transfer-Encoding': 'binary', 'MIME-Version': '1.0'}) - self.assertEqual(app_msg._payload, CONTENT) + self.assertEqual(app_msg._payload, CONTENT.decode('ascii')) self.assertTrue('' in request.loggable_body) def test_ConfigureRequest_w_resumable_wo_total_size(self): from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'CONTENT' + CONTENT = b'CONTENT' config = _UploadConfig() request = _Request() url_builder = _Dummy(query_params={}) @@ -1233,7 +1233,7 @@ def test_ConfigureRequest_w_resumable_wo_total_size(self): def test_ConfigureRequest_w_resumable_w_total_size(self): from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'CONTENT' + CONTENT = b'CONTENT' LEN = len(CONTENT) config = _UploadConfig() request = _Request() @@ -1270,7 +1270,7 @@ def test_RefreshResumableUploadState_w_OK(self): from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) RESP_RANGE = 'bytes 0-%d/%d' % (LEN - 1, LEN,) http = object() @@ -1298,7 +1298,7 @@ def test_RefreshResumableUploadState_w_CREATED(self): from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) RESP_RANGE = 'bytes 0-%d/%d' % (LEN - 1, LEN,) http = object() @@ -1326,7 +1326,7 @@ def test_RefreshResumableUploadState_w_RESUME_INCOMPLETE_w_range(self): from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud._testing import _Monkey from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) LAST = 5 http = object() @@ -1355,7 +1355,7 @@ def test_RefreshResumableUploadState_w_RESUME_INCOMPLETE_wo_range(self): from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud._testing import _Monkey from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) LAST = 5 http = object() @@ -1385,7 +1385,7 @@ def test_RefreshResumableUploadState_w_error(self): from gcloud.streaming.exceptions import HttpError from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) http = object() stream = _Stream() @@ -1458,7 +1458,7 @@ def test_InitializeUpload_w_http_resumable_not_initialized_w_error(self): from gcloud.streaming.exceptions import HttpError from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) request = _Request() upload = self._makeOne(_Stream()) @@ -1479,7 +1479,7 @@ def test_InitializeUpload_w_http_wo_auto_transfer_w_OK(self): from gcloud.streaming import transfer as MUT from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) request = _Request() upload = self._makeOne(_Stream(), auto_transfer=False) @@ -1506,7 +1506,7 @@ def test_InitializeUpload_w_client_w_auto_transfer_w_OK(self): from gcloud.streaming import transfer as MUT from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' LEN = len(CONTENT) FINALIZED_URL = 'http://example.com/upload?id=foobar&final' http = object() @@ -1601,7 +1601,7 @@ def test__StreamMedia_already_complete_w_unseekable_stream(self): def test__StreamMedia_already_complete_w_seekable_stream_unsynced(self): from gcloud.streaming.exceptions import CommunicationError from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) response = object() @@ -1617,7 +1617,7 @@ def test__StreamMedia_already_complete_w_seekable_stream_unsynced(self): def test__StreamMedia_already_complete_w_seekable_stream_synced(self): import os from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) stream.seek(0, os.SEEK_END) @@ -1636,7 +1636,7 @@ def test__StreamMedia_incomplete(self): from gcloud.streaming import transfer as MUT from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) upload = self._makeOne(stream, chunksize=6) @@ -1683,7 +1683,7 @@ def test__StreamMedia_incomplete_w_transfer_error_w_addl_headers(self): from gcloud.streaming.exceptions import CommunicationError from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' http = object() stream = _Stream(CONTENT) headers = {'foo': 'bar'} @@ -1753,7 +1753,7 @@ def test__SendMediaRequest_wo_error(self): from gcloud._testing import _Monkey from gcloud.streaming import transfer as MUT from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' bytes_http = object() stream = _Stream(CONTENT) upload = self._makeOne(stream) @@ -1786,7 +1786,7 @@ def test__SendMediaRequest_w_error(self): from gcloud.streaming.exceptions import HttpError from gcloud.streaming.http_wrapper import RESUME_INCOMPLETE from gcloud.streaming.transfer import RESUMABLE_UPLOAD - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' bytes_http = object() http = object() stream = _Stream(CONTENT) @@ -1914,7 +1914,7 @@ def test__SendChunk_not_initialized(self): upload._SendChunk(0) def test__SendChunk_wo_total_size_stream_exhausted(self): - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' SIZE = len(CONTENT) http = object() upload = self._makeOne(_Stream(CONTENT), chunksize=1000) @@ -1945,7 +1945,7 @@ def _send_media_request(request, end): self.assertEqual(end, SIZE) def test__SendChunk_wo_total_size_stream_not_exhausted(self): - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' SIZE = len(CONTENT) CHUNK_SIZE = SIZE - 5 http = object() @@ -1978,7 +1978,7 @@ def _send_media_request(request, end): def test__SendChunk_w_total_size_stream_not_exhausted(self): from gcloud.streaming.stream_slice import StreamSlice - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' SIZE = len(CONTENT) CHUNK_SIZE = SIZE - 5 http = object() @@ -2012,7 +2012,7 @@ def _send_media_request(request, end): def test__SendChunk_w_total_size_stream_exhausted_w_addl_headers(self): from gcloud.streaming.stream_slice import StreamSlice - CONTENT = 'ABCDEFGHIJ' + CONTENT = b'ABCDEFGHIJ' SIZE = len(CONTENT) CHUNK_SIZE = 1000 http = object()