diff --git a/gcloud/datastore/__init__.py b/gcloud/datastore/__init__.py index bff7408255cf3..0de26dddcb2eb 100644 --- a/gcloud/datastore/__init__.py +++ b/gcloud/datastore/__init__.py @@ -71,8 +71,7 @@ def get_connection(client_email, private_key_path): def get_dataset(dataset_id, client_email, private_key_path): - """Shortcut method to establish a connection to a particular - dataset in the Cloud Datastore. + """Shortcut method to establish a connection to a particular dataset in the Cloud Datastore. You'll generally use this as the first call to working with the API: diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index 60744ee41a3ae..05b6f3b1f1d4c 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -72,7 +72,8 @@ def _request(self, dataset_id, method, data): """ headers = { 'Content-Type': 'application/x-protobuf', - 'Content-Length': str(len(data)), } + 'Content-Length': str(len(data)), + } headers, content = self.http.request( uri=self.build_api_url(dataset_id=dataset_id, method=method), method='POST', headers=headers, body=data) @@ -98,7 +99,7 @@ def build_api_url(cls, dataset_id, method, base_url=None, api_version=None): :type dataset_id: string :param dataset_id: The ID of the dataset to connect to. - This is usually your project name in the cloud console. + This is usually your project name in the cloud console. :type method: string :param method: The API method to call (ie, runQuery, lookup, ...). @@ -133,7 +134,7 @@ def dataset(self, *args, **kwargs): """Factory method for Dataset objects. :param args: All args and kwargs will be passed along to the - :class:`gcloud.datastore.dataset.Dataset` initializer. + :class:`gcloud.datastore.dataset.Dataset` initializer. :rtype: :class:`gcloud.datastore.dataset.Dataset` :returns: A dataset object that will use this connection as its transport. diff --git a/gcloud/datastore/dataset.py b/gcloud/datastore/dataset.py index c5bfe7b4a321e..556a82a8f08ec 100644 --- a/gcloud/datastore/dataset.py +++ b/gcloud/datastore/dataset.py @@ -91,7 +91,8 @@ def get_entities(self, keys): entity_pbs = self.connection().lookup( dataset_id=self.id(), - key_pbs=[k.to_protobuf() for k in keys]) + key_pbs=[k.to_protobuf() for k in keys] + ) entities = [] for entity_pb in entity_pbs: diff --git a/gcloud/datastore/entity.py b/gcloud/datastore/entity.py index 6ec029c3967bf..d56ac4b4eb3f7 100644 --- a/gcloud/datastore/entity.py +++ b/gcloud/datastore/entity.py @@ -44,7 +44,7 @@ class Entity(dict): - :func:`gcloud.datastore.dataset.Dataset.get_entity` - to retrive an existing entity. + to retrive an existing entity. >>> dataset.get_entity(key) @@ -71,8 +71,7 @@ def __init__(self, dataset=None, kind=None): self._key = None def dataset(self): - """Get the :class:`gcloud.datastore.dataset.Dataset` - in which this entity belonds. + """Get the :class:`gcloud.datastore.dataset.Dataset` in which this entity belongs. .. note:: This is based on the :class:`gcloud.datastore.key.Key` set on the entity. @@ -120,14 +119,13 @@ def kind(self): @classmethod def from_key(cls, key): - """Factory method for creating an entity based on the - :class:`gcloud.datastore.key.Key`. + """Factory method for creating an entity based on the :class:`gcloud.datastore.key.Key`. :type key: :class:`gcloud.datastore.key.Key` :param key: The key for the entity. :returns: The :class:`Entity` derived from the - :class:`gcloud.datastore.key.Key`. + :class:`gcloud.datastore.key.Key`. """ return cls().key(key) @@ -139,10 +137,10 @@ def from_protobuf(cls, pb, dataset=None): The protobuf should be one returned from the Cloud Datastore Protobuf API. :type key: :class:`gcloud.datastore.datastore_v1_pb2.Entity` - :param key: The Protobuf representing the entity. + :param key: The Protobuf representing the entity. :returns: The :class:`Entity` derived from the - :class:`gcloud.datastore.datastore_v1_pb2.Entity`. + :class:`gcloud.datastore.datastore_v1_pb2.Entity`. """ # This is here to avoid circular imports. diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py index 48a894d15260f..4b67333b3cbec 100644 --- a/gcloud/datastore/query.py +++ b/gcloud/datastore/query.py @@ -46,7 +46,8 @@ class Query(object): '<=': datastore_pb.PropertyFilter.LESS_THAN_OR_EQUAL, '>': datastore_pb.PropertyFilter.GREATER_THAN, '>=': datastore_pb.PropertyFilter.GREATER_THAN_OR_EQUAL, - '=': datastore_pb.PropertyFilter.EQUAL, } + '=': datastore_pb.PropertyFilter.EQUAL, + } """Mapping of operator strings and their protobuf equivalents.""" def __init__(self, kind=None, dataset=None): @@ -62,8 +63,7 @@ def _clone(self): return clone def to_protobuf(self): - """Convert the :class:`Query` instance to a - :class:`gcloud.datastore.datastore_v1_pb2.Query`. + """Convert the :class:`Query` instance to a :class:`gcloud.datastore.datastore_v1_pb2.Query`. :rtype: :class:`gclouddatstore.datastore_v1_pb2.Query` :returns: A Query protobuf that can be sent to the protobuf API. diff --git a/gcloud/datastore/test___init__.py b/gcloud/datastore/test___init__.py index 4d2da1ba11f98..e22c373a0d9d3 100644 --- a/gcloud/datastore/test___init__.py +++ b/gcloud/datastore/test___init__.py @@ -28,7 +28,9 @@ def test_it(self): self.assertEqual(client._called_with, {'service_account_name': CLIENT_EMAIL, 'private_key': PRIVATE_KEY, - 'scope': SCOPE, }) + 'scope': SCOPE, + } + ) class Test_get_dataset(unittest2.TestCase): @@ -61,4 +63,6 @@ def test_it(self): self.assertEqual(client._called_with, {'service_account_name': CLIENT_EMAIL, 'private_key': PRIVATE_KEY, - 'scope': SCOPE, }) + 'scope': SCOPE, + } + ) diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py index aeba6867d0146..b8424486346c1 100644 --- a/gcloud/datastore/test_connection.py +++ b/gcloud/datastore/test_connection.py @@ -63,8 +63,11 @@ def test__request_w_200(self): {'uri': URI, 'method': 'POST', 'headers': {'Content-Type': 'application/x-protobuf', - 'Content-Length': '4', }, - 'body': DATA, }) + 'Content-Length': '4', + }, + 'body': DATA, + } + ) def test__request_not_200(self): DATASET_ID = 'DATASET' @@ -101,7 +104,8 @@ def FromString(cls, pb): conn.API_VERSION, 'datasets', DATASET_ID, - METHOD, ]) + METHOD, + ]) http = conn._http = Http({'status': '200'}, 'CONTENT') response = conn._rpc(DATASET_ID, METHOD, ReqPB(), RspPB) self.assertTrue(isinstance(response, RspPB)) @@ -110,8 +114,10 @@ def FromString(cls, pb): {'uri': URI, 'method': 'POST', 'headers': {'Content-Type': 'application/x-protobuf', - 'Content-Length': '5', }, - 'body': b'REQPB', }) + 'Content-Length': '5', + }, + 'body': b'REQPB', + }) def test_build_api_url_w_default_base_version(self): DATASET_ID = 'DATASET' @@ -122,7 +128,8 @@ def test_build_api_url_w_default_base_version(self): klass.API_VERSION, 'datasets', DATASET_ID, - METHOD, ]) + METHOD, + ]) self.assertEqual(klass.build_api_url(DATASET_ID, METHOD), URI) def test_build_api_url_w_explicit_base_version(self): @@ -200,7 +207,8 @@ def test_begin_transaction_default_serialize(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'beginTransaction', ]) + 'beginTransaction', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) self.assertEqual(conn.begin_transaction(DATASET_ID), TRANSACTION) cw = http._called_with @@ -208,7 +216,8 @@ def test_begin_transaction_default_serialize(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '2', }) + 'Content-Length': '2', + }) rq_class = datastore_pb.BeginTransactionRequest request = rq_class() request.ParseFromString(cw['body']) @@ -228,7 +237,8 @@ def test_begin_transaction_explicit_serialize(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'beginTransaction', ]) + 'beginTransaction', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) self.assertEqual(conn.begin_transaction(DATASET_ID, True), TRANSACTION) cw = http._called_with @@ -236,7 +246,8 @@ def test_begin_transaction_explicit_serialize(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '2', }) + 'Content-Length': '2', + }) rq_class = datastore_pb.BeginTransactionRequest request = rq_class() request.ParseFromString(cw['body']) @@ -277,7 +288,8 @@ def id(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'rollback', ]) + 'rollback', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) self.assertEqual(conn.rollback_transaction(DATASET_ID), None) cw = http._called_with @@ -285,7 +297,8 @@ def id(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '6', }) + 'Content-Length': '6', + }) rq_class = datastore_pb.RollbackRequest request = rq_class() request.ParseFromString(cw['body']) @@ -305,7 +318,8 @@ def test_run_query_wo_namespace_empty_result(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'runQuery', ]) + 'runQuery', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) self.assertEqual(conn.run_query(DATASET_ID, q_pb), []) cw = http._called_with @@ -313,7 +327,8 @@ def test_run_query_wo_namespace_empty_result(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '14', }) + 'Content-Length': '14', + }) rq_class = datastore_pb.RunQueryRequest request = rq_class() request.ParseFromString(cw['body']) @@ -338,7 +353,8 @@ def test_run_query_w_namespace_nonempty_result(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'runQuery', ]) + 'runQuery', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.run_query(DATASET_ID, q_pb, 'NS') returned, = result # One entity. @@ -347,7 +363,8 @@ def test_run_query_w_namespace_nonempty_result(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '16', }) + 'Content-Length': '16', + }) rq_class = datastore_pb.RunQueryRequest request = rq_class() request.ParseFromString(cw['body']) @@ -377,7 +394,8 @@ def test_lookup_single_key_empty_response(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '26', }) + 'Content-Length': '26', + }) rq_class = datastore_pb.LookupRequest request = rq_class() request.ParseFromString(cw['body']) @@ -403,7 +421,8 @@ def test_lookup_single_key_nonempty_response(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'lookup', ]) + 'lookup', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) found = conn.lookup(DATASET_ID, key_pb) self.assertEqual(found.key.path_element[0].kind, 'Kind') @@ -413,7 +432,8 @@ def test_lookup_single_key_nonempty_response(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '26', }) + 'Content-Length': '26', + }) rq_class = datastore_pb.LookupRequest request = rq_class() request.ParseFromString(cw['body']) @@ -446,7 +466,8 @@ def test_lookup_multiple_keys_empty_response(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '52', }) + 'Content-Length': '52', + }) rq_class = datastore_pb.LookupRequest request = rq_class() request.ParseFromString(cw['body']) @@ -476,7 +497,8 @@ def test_commit_wo_transaction(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.commit(DATASET_ID, mutation) self.assertEqual(result.index_updates, 0) @@ -486,7 +508,8 @@ def test_commit_wo_transaction(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '47', }) + 'Content-Length': '47', + }) rq_class = datastore_pb.CommitRequest request = rq_class() request.ParseFromString(cw['body']) @@ -519,7 +542,8 @@ def id(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.commit(DATASET_ID, mutation) self.assertEqual(result.index_updates, 0) @@ -529,7 +553,8 @@ def id(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '53', }) + 'Content-Length': '53', + }) rq_class = datastore_pb.CommitRequest request = rq_class() request.ParseFromString(cw['body']) @@ -552,7 +577,8 @@ def test_save_entity_wo_transaction_w_upsert(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.save_entity(DATASET_ID, key_pb, {'foo': 'Foo'}) self.assertEqual(result, True) @@ -561,7 +587,8 @@ def test_save_entity_wo_transaction_w_upsert(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '47', }) + 'Content-Length': '47', + }) rq_class = datastore_pb.CommitRequest request = rq_class() request.ParseFromString(cw['body']) @@ -600,7 +627,8 @@ def test_save_entity_wo_transaction_w_auto_id(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.save_entity(DATASET_ID, key_pb, {'foo': 'Foo'}) self.assertEqual(result, updated_key_pb) @@ -609,7 +637,8 @@ def test_save_entity_wo_transaction_w_auto_id(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '44', }) + 'Content-Length': '44', + }) rq_class = datastore_pb.CommitRequest request = rq_class() request.ParseFromString(cw['body']) @@ -653,7 +682,8 @@ def mutation(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.save_entity(DATASET_ID, key_pb, {'foo': 'Foo'}) self.assertEqual(result, True) @@ -686,7 +716,8 @@ def test_delete_entities_wo_transaction(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '30', }) + 'Content-Length': '30', + }) rq_class = datastore_pb.CommitRequest request = rq_class() request.ParseFromString(cw['body']) @@ -725,7 +756,8 @@ def mutation(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.delete_entities(DATASET_ID, [key_pb]) self.assertEqual(result, True) @@ -748,7 +780,8 @@ def test_delete_entity_wo_transaction(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.delete_entity(DATASET_ID, key_pb) self.assertEqual(result.index_updates, 0) @@ -758,7 +791,8 @@ def test_delete_entity_wo_transaction(self): self.assertEqual(cw['method'], 'POST') self.assertEqual(cw['headers'], {'Content-Type': 'application/x-protobuf', - 'Content-Length': '30', }) + 'Content-Length': '30', + }) rq_class = datastore_pb.CommitRequest request = rq_class() request.ParseFromString(cw['body']) @@ -797,7 +831,8 @@ def mutation(self): conn.API_VERSION, 'datasets', DATASET_ID, - 'commit', ]) + 'commit', + ]) http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString()) result = conn.delete_entity(DATASET_ID, key_pb) self.assertEqual(result, True) diff --git a/gcloud/datastore/test_key.py b/gcloud/datastore/test_key.py index 7e77568933baa..50908e68b6f97 100644 --- a/gcloud/datastore/test_key.py +++ b/gcloud/datastore/test_key.py @@ -185,7 +185,8 @@ def test_from_path_nested(self): key = self._getTargetClass().from_path('abc', 'def', 'ghi', 123) self.assertEqual(key.kind(), 'ghi') self.assertEqual(key.path(), [{'kind': 'abc', 'name': 'def'}, - {'kind': 'ghi', 'id': 123}, ]) + {'kind': 'ghi', 'id': 123}, + ]) def test_is_partial_no_name_or_id(self): key = self._makeOne() diff --git a/gcloud/datastore/test_query.py b/gcloud/datastore/test_query.py index 17264254877b1..3d350625b7626 100644 --- a/gcloud/datastore/test_query.py +++ b/gcloud/datastore/test_query.py @@ -197,7 +197,8 @@ def test_fetch_default_limit(self): [{'kind': _KIND, 'id': _ID}]) self.assertEqual(connection._called_with, {'dataset_id': _DATASET, - 'query_pb': query.to_protobuf(), }) + 'query_pb': query.to_protobuf(), + }) def test_fetch_explicit_limit(self): from gcloud.datastore.datastore_v1_pb2 import Entity @@ -221,7 +222,8 @@ def test_fetch_explicit_limit(self): [{'kind': _KIND, 'id': _ID}]) self.assertEqual(connection._called_with, {'dataset_id': _DATASET, - 'query_pb': limited.to_protobuf(), }) + 'query_pb': limited.to_protobuf(), + }) class _Dataset(object): diff --git a/gcloud/storage/acl.py b/gcloud/storage/acl.py index 0daa49ec024c7..3c873bcaecc08 100644 --- a/gcloud/storage/acl.py +++ b/gcloud/storage/acl.py @@ -379,8 +379,7 @@ def save(self): class DefaultObjectACL(BucketACL): - """A subclass of BucketACL representing the - default object ACL for a bucket.""" + """A subclass of BucketACL representing the default object ACL for a bucket.""" def save(self): """Save this ACL as the default object ACL for the current bucket.""" diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index 5c4f14f5f01d2..89621240cfba3 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -102,8 +102,7 @@ def get_all_keys(self): return list(self) def new_key(self, key): - """Given a path name (or a Key), return a :class:`gcloud.storage.key.Key` - object. + """Given a path name (or a Key), return a :class:`gcloud.storage.key.Key` object. This is really useful when you're not sure if you have a Key object or a string path name. @@ -355,7 +354,9 @@ def configure_website(self, main_page_suffix=None, not_found_page=None): """ data = {'website': {'mainPageSuffix': main_page_suffix, - 'notFoundPage': not_found_page, }} + 'notFoundPage': not_found_page, + } + } return self.patch_metadata(data) def disable_website(self): diff --git a/gcloud/storage/iterator.py b/gcloud/storage/iterator.py index e76013eba1c82..e7f75428f1f05 100644 --- a/gcloud/storage/iterator.py +++ b/gcloud/storage/iterator.py @@ -146,8 +146,7 @@ def __init__(self, connection): super(BucketIterator, self).__init__(connection=connection, path='/b') def get_items_from_response(self, response): - """Factory method which yields :class:`gcloud.storage.bucket.Bucket` - items from a response. + """Factory method which yields :class:`gcloud.storage.bucket.Bucket` items from a response. :type response: dict :param response: The JSON API response for a page of buckets. @@ -175,8 +174,7 @@ def __init__(self, bucket): connection=bucket.connection, path=bucket.path + '/o') def get_items_from_response(self, response): - """Factory method which yields :class:`gcloud.storage.key.Key` - items from a response. + """Factory method which yields :class:`gcloud.storage.key.Key` items from a response. :type response: dict :param response: The JSON API response for a page of keys. diff --git a/gcloud/storage/key.py b/gcloud/storage/key.py index d144283c9f06d..06a3d3d69dacb 100644 --- a/gcloud/storage/key.py +++ b/gcloud/storage/key.py @@ -208,7 +208,8 @@ def set_contents_from_file(self, fh, rewind=False, size=None, # Set up a resumable upload session. headers = { 'X-Upload-Content-Type': content_type or 'application/unknown', - 'X-Upload-Content-Length': total_bytes} + 'X-Upload-Content-Length': total_bytes + } upload_url = self.connection.build_api_url( path=self.bucket.path + '/o', @@ -231,7 +232,8 @@ def set_contents_from_file(self, fh, rewind=False, size=None, end = bytes_uploaded + chunk_size - 1 headers = { - 'Content-Range': 'bytes %d-%d/%d' % (start, end, total_bytes), } + 'Content-Range': 'bytes %d-%d/%d' % (start, end, total_bytes), + } response, content = self.connection.make_request( content_type='text/plain', diff --git a/gcloud/storage/test___init__.py b/gcloud/storage/test___init__.py index 099568aca1aa2..fe640bdfea4db 100644 --- a/gcloud/storage/test___init__.py +++ b/gcloud/storage/test___init__.py @@ -29,7 +29,8 @@ def test_it(self): self.assertEqual(client._called_with, {'service_account_name': CLIENT_EMAIL, 'private_key': PRIVATE_KEY, - 'scope': SCOPE, }) + 'scope': SCOPE, + }) class Test_get_bucket(unittest2.TestCase): diff --git a/gcloud/storage/test_connection.py b/gcloud/storage/test_connection.py index 32f03919b4791..495a78b8b309a 100644 --- a/gcloud/storage/test_connection.py +++ b/gcloud/storage/test_connection.py @@ -55,9 +55,12 @@ def test___iter___empty(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - 'b?project=%s' % PROJECT, ]) + 'b?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') keys = list(conn) self.assertEqual(len(keys), 0) self.assertEqual(http._called_with['method'], 'GET') @@ -70,9 +73,11 @@ def test___iter___non_empty(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - 'b?project=%s' % PROJECT, ]) + 'b?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, + 'content-type': 'application/json', + }, '{"items": [{"name": "%s"}]}' % KEY) keys = list(conn) self.assertEqual(len(keys), 1) @@ -88,9 +93,12 @@ def test___contains___miss(self): 'storage', conn.API_VERSION, 'b', - 'nonesuch?project=%s' % PROJECT, ]) + 'nonesuch?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '404', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') self.assertFalse(NONESUCH in conn) self.assertEqual(http._called_with['method'], 'GET') self.assertEqual(http._called_with['uri'], URI) @@ -103,9 +111,11 @@ def test___contains___hit(self): 'storage', conn.API_VERSION, 'b', - 'key?project=%s' % PROJECT, ]) + 'key?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, + 'content-type': 'application/json', + }, '{"name": "%s"}' % KEY) self.assertTrue(KEY in conn) self.assertEqual(http._called_with['method'], 'GET') @@ -118,7 +128,8 @@ def test_build_api_url_no_extra_query_params(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - 'foo?project=%s' % PROJECT, ]) + 'foo?project=%s' % PROJECT, + ]) self.assertEqual(conn.build_api_url('/foo'), URI) def test_build_api_url_w_extra_query_params(self): @@ -145,7 +156,9 @@ def test_make_request_no_data_no_content_type_no_headers(self): conn = self._makeOne(PROJECT) URI = 'http://example.com/test' http = conn._http = Http({'status': '200', - 'content-type': 'text/plain', }, '') + 'content-type': 'text/plain', + }, + '') headers, content = conn.make_request('GET', URI) self.assertEqual(headers['status'], '200') self.assertEqual(headers['content-type'], 'text/plain') @@ -155,14 +168,17 @@ def test_make_request_no_data_no_content_type_no_headers(self): self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, + }) def test_make_request_w_data_no_extra_headers(self): PROJECT = 'project' conn = self._makeOne(PROJECT) URI = 'http://example.com/test' http = conn._http = Http({'status': '200', - 'content-type': 'text/plain', }, '') + 'content-type': 'text/plain', + }, + '') headers, content = conn.make_request('GET', URI, {}, 'application/json') self.assertEqual(http._called_with['method'], 'GET') @@ -171,14 +187,17 @@ def test_make_request_w_data_no_extra_headers(self): self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', 'Content-Length': 0, - 'Content-Type': 'application/json', }) + 'Content-Type': 'application/json', + }) def test_make_request_w_extra_headers(self): PROJECT = 'project' conn = self._makeOne(PROJECT) URI = 'http://example.com/test' http = conn._http = Http({'status': '200', - 'content-type': 'text/plain', }, '') + 'content-type': 'text/plain', + }, + '') headers, content = conn.make_request('GET', URI, headers={'X-Foo': 'foo'}) self.assertEqual(http._called_with['method'], 'GET') @@ -187,7 +206,8 @@ def test_make_request_w_extra_headers(self): self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', 'Content-Length': 0, - 'X-Foo': 'foo', }) + 'X-Foo': 'foo', + }) def test_api_request_defaults(self): PROJECT = 'project' @@ -199,14 +219,17 @@ def test_api_request_defaults(self): 'None?project=%s' % PROJECT) # XXX http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') self.assertEqual(conn.api_request('GET'), {}) self.assertEqual(http._called_with['method'], 'GET') self.assertEqual(http._called_with['uri'], URI) self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, + }) def test_api_request_w_path(self): PROJECT = 'project' @@ -214,16 +237,20 @@ def test_api_request_w_path(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - '?project=%s' % PROJECT, ]) + '?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') self.assertEqual(conn.api_request('GET', '/'), {}) self.assertEqual(http._called_with['method'], 'GET') self.assertEqual(http._called_with['uri'], URI) self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, + }) def test_api_request_w_non_json_response(self): PROJECT = 'project' @@ -231,9 +258,12 @@ def test_api_request_w_non_json_response(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - '?project=%s' % PROJECT, ]) + '?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'text/plain', }, 'CONTENT') + 'content-type': 'text/plain', + }, + 'CONTENT') self.assertRaises(TypeError, conn.api_request, 'GET', '/') def test_api_request_wo_json_expected(self): @@ -242,9 +272,11 @@ def test_api_request_wo_json_expected(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - '?project=%s' % PROJECT, ]) + '?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'text/plain', }, + 'content-type': 'text/plain', + }, 'CONTENT') self.assertEqual(conn.api_request('GET', '/', expect_json=False), 'CONTENT') @@ -257,9 +289,12 @@ def test_api_request_w_query_params(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - '?project=%s&foo=bar' % PROJECT, ]) + '?project=%s&foo=bar' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') self.assertEqual(conn.api_request('GET', '/', {'foo': 'bar'}), {}) self.assertEqual(http._called_with['method'], 'GET') uri = http._called_with['uri'] @@ -273,7 +308,8 @@ def test_api_request_w_query_params(self): self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, + }) def test_api_request_w_data(self): import json @@ -284,9 +320,12 @@ def test_api_request_w_data(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - '?project=%s' % PROJECT, ]) + '?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') self.assertEqual(conn.api_request('POST', '/', data=DATA), {}) self.assertEqual(http._called_with['method'], 'POST') self.assertEqual(http._called_with['uri'], URI) @@ -294,7 +333,8 @@ def test_api_request_w_data(self): self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', 'Content-Length': len(DATAJ), - 'Content-Type': 'application/json', }) + 'Content-Type': 'application/json', + }) def test_api_request_w_404(self): from gcloud.storage.exceptions import NotFoundError @@ -303,9 +343,12 @@ def test_api_request_w_404(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - '?project=%s' % PROJECT, ]) + '?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '404', - 'content-type': 'text/plain', }, '') + 'content-type': 'text/plain', + }, + '') self.assertRaises(NotFoundError, conn.api_request, 'GET', '/') def test_api_request_w_500(self): @@ -315,9 +358,12 @@ def test_api_request_w_500(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - '?project=%s' % PROJECT, ]) + '?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '500', - 'content-type': 'text/plain', }, '') + 'content-type': 'text/plain', + }, + '') self.assertRaises(ConnectionError, conn.api_request, 'GET', '/') def test_get_all_buckets_empty(self): @@ -326,9 +372,12 @@ def test_get_all_buckets_empty(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - 'b?project=%s' % PROJECT, ]) + 'b?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') keys = conn.get_all_buckets() self.assertEqual(len(keys), 0) self.assertEqual(http._called_with['method'], 'GET') @@ -341,9 +390,11 @@ def test_get_all_buckets_non_empty(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - 'b?project=%s' % PROJECT, ]) + 'b?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, + 'content-type': 'application/json', + }, '{"items": [{"name": "%s"}]}' % KEY) keys = conn.get_all_buckets() self.assertEqual(len(keys), 1) @@ -360,9 +411,12 @@ def test_get_bucket_miss(self): 'storage', conn.API_VERSION, 'b', - 'nonesuch?project=%s' % PROJECT, ]) + 'nonesuch?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '404', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') self.assertRaises(NotFoundError, conn.get_bucket, NONESUCH) self.assertEqual(http._called_with['method'], 'GET') self.assertEqual(http._called_with['uri'], URI) @@ -376,9 +430,11 @@ def test_get_bucket_hit(self): 'storage', conn.API_VERSION, 'b', - 'key?project=%s' % PROJECT, ]) + 'key?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, + 'content-type': 'application/json', + }, '{"name": "%s"}' % KEY) bucket = conn.get_bucket(KEY) self.assertTrue(isinstance(bucket, Bucket)) @@ -395,9 +451,12 @@ def test_lookup_miss(self): 'storage', conn.API_VERSION, 'b', - 'nonesuch?project=%s' % PROJECT, ]) + 'nonesuch?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '404', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') self.assertEqual(conn.lookup(NONESUCH), None) self.assertEqual(http._called_with['method'], 'GET') self.assertEqual(http._called_with['uri'], URI) @@ -411,9 +470,11 @@ def test_lookup_hit(self): 'storage', conn.API_VERSION, 'b', - 'key?project=%s' % PROJECT, ]) + 'key?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, + 'content-type': 'application/json', + }, '{"name": "%s"}' % KEY) bucket = conn.lookup(KEY) self.assertTrue(isinstance(bucket, Bucket)) @@ -430,9 +491,11 @@ def test_create_bucket_ok(self): URI = '/'.join([conn.API_BASE_URL, 'storage', conn.API_VERSION, - 'b?project=%s' % PROJECT, ]) + 'b?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, + 'content-type': 'application/json', + }, '{"name": "%s"}' % KEY) bucket = conn.create_bucket(KEY) self.assertTrue(isinstance(bucket, Bucket)) @@ -467,9 +530,12 @@ def __iter__(self): 'storage', conn.API_VERSION, 'b', - 'key?project=%s' % PROJECT, ]) + 'key?project=%s' % PROJECT, + ]) http = conn._http = Http({'status': '200', - 'content-type': 'application/json', }, '{}') + 'content-type': 'application/json', + }, + '{}') def _new_bucket(name): return _Bucket(name) diff --git a/gcloud/storage/test_iterator.py b/gcloud/storage/test_iterator.py index 8f36caeb640b1..b2ec43afdbd95 100644 --- a/gcloud/storage/test_iterator.py +++ b/gcloud/storage/test_iterator.py @@ -72,7 +72,9 @@ def test_get_query_params_w_token(self): TOKEN = 'token' iterator = self._makeOne(connection, PATH) iterator.next_page_token = TOKEN - self.assertEqual(iterator.get_query_params(), {'pageToken': TOKEN, }) + self.assertEqual(iterator.get_query_params(), + {'pageToken': TOKEN, + }) def test_get_next_page_response_new_no_token_in_response(self): PATH = '/foo' @@ -209,7 +211,8 @@ def test__iter__(self): response2 = _Response(status=200) response2['content-range'] = '11-14/15' connection = _Connection((response1, '01234567890'), - (response2, '1234'), ) + (response2, '1234'), + ) key = _Key(connection) iterator = self._makeOne(key) chunks = list(iterator) diff --git a/gcloud/storage/test_key.py b/gcloud/storage/test_key.py index c89382ab23c85..e37ca259697eb 100644 --- a/gcloud/storage/test_key.py +++ b/gcloud/storage/test_key.py @@ -161,7 +161,8 @@ def test_set_contents_from_file(self): chunk2_response = _Response() connection = _Connection((loc_response, ''), (chunk1_response, ''), - (chunk2_response, ''), ) + (chunk2_response, ''), + ) bucket = _Bucket(connection) key = self._makeOne(bucket, KEY) key.CHUNK_SIZE = 5 @@ -205,7 +206,8 @@ def test_set_contents_from_filename(self): chunk2_response = _Response() connection = _Connection((loc_response, ''), (chunk1_response, ''), - (chunk2_response, ''), ) + (chunk2_response, ''), + ) bucket = _Bucket(connection) key = self._makeOne(bucket, KEY) key.CHUNK_SIZE = 5 diff --git a/gcloud/test_credentials.py b/gcloud/test_credentials.py index adb83c0c2db81..69a06ec4ef0de 100644 --- a/gcloud/test_credentials.py +++ b/gcloud/test_credentials.py @@ -23,7 +23,8 @@ def test_get_for_service_account_wo_scope(self): self.assertEqual(client._called_with, {'service_account_name': CLIENT_EMAIL, 'private_key': PRIVATE_KEY, - 'scope': None, }) + 'scope': None, + }) def test_get_for_service_account_w_scope(self): from tempfile import NamedTemporaryFile @@ -43,7 +44,8 @@ def test_get_for_service_account_w_scope(self): self.assertEqual(client._called_with, {'service_account_name': CLIENT_EMAIL, 'private_key': PRIVATE_KEY, - 'scope': SCOPE, }) + 'scope': SCOPE, + }) class _Client(object):