Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Making name= the first argument in Bucket() constructor. #737

Merged
merged 1 commit into from
Mar 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcloud/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def set_default_bucket(bucket=None):
connection = get_default_connection()

if bucket_name is not None and connection is not None:
bucket = Bucket(connection=connection, name=bucket_name)
bucket = Bucket(bucket_name, connection=connection)

if bucket is not None:
_implicit_environ._DEFAULTS.bucket = bucket
Expand Down
9 changes: 6 additions & 3 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ def get_items_from_response(self, response):
class Bucket(_PropertyMixin):
"""A class representing a Bucket on Cloud Storage.

:type name: string
:param name: The name of the bucket.

:type connection: :class:`gcloud.storage.connection.Connection`
:param connection: The connection to use when sending requests.

:type name: string
:param name: The name of the bucket.
:type properties: dictionary or ``NoneType``
:param properties: The properties associated with the bucket.
"""
_iterator_class = _BlobIterator

Expand All @@ -89,7 +92,7 @@ class Bucket(_PropertyMixin):
# ACL rules are lazily retrieved.
_acl = _default_object_acl = None

def __init__(self, connection=None, name=None, properties=None):
def __init__(self, name=None, connection=None, properties=None):
if name is None and properties is not None:
name = properties.get('name')
super(Bucket, self).__init__(name=name, properties=properties)
Expand Down
40 changes: 20 additions & 20 deletions gcloud/storage/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def test_reload_eager_missing(self):
NAME = 'name'
ROLE = 'role'
connection = _Connection({})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
acl.loaded = True
acl.entity('allUsers', ROLE)
Expand All @@ -556,7 +556,7 @@ def test_reload_eager_empty(self):
NAME = 'name'
ROLE = 'role'
connection = _Connection({'items': []})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
acl.loaded = True
acl.entity('allUsers', ROLE)
Expand All @@ -572,7 +572,7 @@ def test_reload_eager_nonempty(self):
ROLE = 'role'
connection = _Connection(
{'items': [{'entity': 'allUsers', 'role': ROLE}]})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
acl.loaded = True
self.assertTrue(acl.reload() is acl)
Expand All @@ -587,7 +587,7 @@ def test_reload_lazy(self):
ROLE = 'role'
connection = _Connection(
{'items': [{'entity': 'allUsers', 'role': ROLE}]})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
self.assertTrue(acl.reload() is acl)
self.assertEqual(list(acl), [{'entity': 'allUsers', 'role': ROLE}])
Expand All @@ -599,7 +599,7 @@ def test_reload_lazy(self):
def test_save_none_set_none_passed(self):
NAME = 'name'
connection = _Connection()
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
self.assertTrue(acl.save() is acl)
kw = connection._requested
Expand All @@ -608,7 +608,7 @@ def test_save_none_set_none_passed(self):
def test_save_existing_missing_none_passed(self):
NAME = 'name'
connection = _Connection({})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
acl.loaded = True
self.assertTrue(acl.save() is acl)
Expand All @@ -625,7 +625,7 @@ def test_save_no_arg(self):
ROLE = 'role'
AFTER = [{'entity': 'allUsers', 'role': ROLE}]
connection = _Connection({'acl': AFTER})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
acl.loaded = True
acl.entity('allUsers').grant(ROLE)
Expand All @@ -645,7 +645,7 @@ def test_save_w_arg(self):
STICKY = {'entity': 'allUsers', 'role': ROLE2}
new_acl = [{'entity': 'allUsers', 'role': ROLE1}]
connection = _Connection({'acl': [STICKY] + new_acl})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
acl.loaded = True
self.assertTrue(acl.save(new_acl) is acl)
Expand All @@ -666,7 +666,7 @@ def test_clear(self):
ROLE2 = 'role2'
STICKY = {'entity': 'allUsers', 'role': ROLE2}
connection = _Connection({'acl': [STICKY]})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
acl = self._makeOne(bucket)
acl.loaded = True
acl.entity('allUsers', ROLE1)
Expand Down Expand Up @@ -703,7 +703,7 @@ def test_reload_eager_missing(self):
ROLE = 'role'
after = {}
connection = _Connection(after)
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
acl.loaded = True
Expand All @@ -717,7 +717,7 @@ def test_reload_eager_empty(self):
ROLE = 'role'
after = {'items': []}
connection = _Connection(after)
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
acl.loaded = True
Expand All @@ -731,7 +731,7 @@ def test_reload_eager_nonempty(self):
ROLE = 'role'
after = {'items': [{'entity': 'allUsers', 'role': ROLE}]}
connection = _Connection(after)
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
acl.loaded = True
Expand All @@ -748,7 +748,7 @@ def test_reload_lazy(self):
ROLE = 'role'
after = {'items': [{'entity': 'allUsers', 'role': ROLE}]}
connection = _Connection(after)
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
self.assertTrue(acl.reload() is acl)
Expand All @@ -763,7 +763,7 @@ def test_save_none_set_none_passed(self):
NAME = 'name'
BLOB_NAME = 'blob-name'
connection = _Connection()
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
self.assertTrue(acl.save() is acl)
Expand All @@ -775,7 +775,7 @@ def test_save_existing_missing_none_passed(self):
NAME = 'name'
BLOB_NAME = 'blob-name'
connection = _Connection({'foo': 'Foo'})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
acl.loaded = True
Expand All @@ -791,7 +791,7 @@ def test_save_existing_set_none_passed(self):
NAME = 'name'
BLOB_NAME = 'blob-name'
connection = _Connection({'foo': 'Foo', 'acl': []})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
acl.loaded = True
Expand All @@ -809,7 +809,7 @@ def test_save_existing_set_new_passed(self):
ROLE = 'role'
new_acl = [{'entity': 'allUsers', 'role': ROLE}]
connection = _Connection({'foo': 'Foo', 'acl': new_acl})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
acl.loaded = True
Expand All @@ -828,7 +828,7 @@ def test_clear(self):
BLOB_NAME = 'blob-name'
ROLE = 'role'
connection = _Connection({'foo': 'Foo', 'acl': []})
bucket = _Bucket(connection, NAME)
bucket = _Bucket(NAME, connection)
blob = _Blob(bucket, BLOB_NAME)
acl = self._makeOne(blob)
acl.loaded = True
Expand Down Expand Up @@ -860,9 +860,9 @@ def path(self):

class _Bucket(object):

def __init__(self, connection, name):
self.connection = connection
def __init__(self, name, connection):
self.name = name
self.connection = connection

@property
def path(self):
Expand Down
Loading