Skip to content
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
19 changes: 11 additions & 8 deletions gcloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,23 @@ def reload(self):
self._properties = self.connection.api_request(
method='GET', path=self.path, query_params=query_params)

def _patch_properties(self, properties):
"""Update particular fields of this object's properties.
def _patch_property(self, name, value):
"""Update field of this object's properties.

This method will only update the fields provided and will not
This method will only update the field provided and will not
touch the other fields.

It **will not** reload the properties from the server. The behavior is
local only and syncing occurs via :meth:`patch`.

:type properties: dict
:param properties: The dictionary of values to update.
:type name: string
:param name: The field name to update.

:type value: object
:param value: The value being updated.
"""
self._changes.update(properties.keys())
self._properties.update(properties)
self._changes.add(name)
self._properties[name] = value

def patch(self):
"""Sends all changed properties in a PATCH request.
Expand All @@ -95,7 +98,7 @@ def _getter(self):

def _setter(self, value):
"""Scalar property setter."""
self._patch_properties({fieldname: value})
self._patch_property(fieldname, value)

return property(_getter, _setter)

Expand Down
2 changes: 1 addition & 1 deletion gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def metadata(self, value):

:type value: dict
"""
self._patch_properties({'metadata': value})
self._patch_property('metadata', value)

@property
def metageneration(self):
Expand Down
18 changes: 8 additions & 10 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def cors(self, entries):
:type entries: list of dictionaries
:param entries: A sequence of mappings describing each CORS policy.
"""
self._patch_properties({'cors': entries})
self._patch_property('cors', entries)

@property
def etag(self):
Expand Down Expand Up @@ -550,7 +550,7 @@ def lifecycle_rules(self, rules):
:rtype: list(dict)
:returns: A sequence of mappings describing each lifecycle rule.
"""
self._patch_properties({'lifecycle': {'rule': rules}})
self._patch_property('lifecycle', {'rule': rules})

location = _scalar_property('location')
"""Retrieve location configured for this bucket.
Expand Down Expand Up @@ -586,14 +586,14 @@ def enable_logging(self, bucket_name, object_prefix=''):
:param object_prefix: prefix for access log filenames
"""
info = {'logBucket': bucket_name, 'logObjectPrefix': object_prefix}
self._patch_properties({'logging': info})
self._patch_property('logging', info)

def disable_logging(self):
"""Disable access logging for this bucket.

See: https://cloud.google.com/storage/docs/accesslogs#disabling
"""
self._patch_properties({'logging': None})
self._patch_property('logging', None)

@property
def metageneration(self):
Expand Down Expand Up @@ -682,7 +682,7 @@ def versioning_enabled(self, value):
:type value: convertible to boolean
:param value: should versioning be anabled for the bucket?
"""
self._patch_properties({'versioning': {'enabled': bool(value)}})
self._patch_property('versioning', {'enabled': bool(value)})

def configure_website(self, main_page_suffix=None, not_found_page=None):
"""Configure website-related properties.
Expand Down Expand Up @@ -719,12 +719,10 @@ def configure_website(self, main_page_suffix=None, not_found_page=None):
:param not_found_page: The file to use when a page isn't found.
"""
data = {
'website': {
'mainPageSuffix': main_page_suffix,
'notFoundPage': not_found_page,
},
'mainPageSuffix': main_page_suffix,
'notFoundPage': not_found_page,
}
self._patch_properties(data)
self._patch_property('website', data)

def disable_website(self):
"""Disable the website configuration for this bucket.
Expand Down
10 changes: 5 additions & 5 deletions gcloud/storage/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def test_reload(self):
self.assertEqual(kw[0]['path'], '/path')
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})

def test__patch_properties(self):
def test__patch_property(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
derived._patch_properties({'foo': 'Foo'})
derived._patch_property('foo', 'Foo')
derived.patch()
kw = connection._requested
self.assertEqual(len(kw), 1)
Expand Down Expand Up @@ -89,13 +89,13 @@ def __init__(self, **kw):
def test_setter(self):

class Test(object):
def _patch_properties(self, mapping):
self._patched = mapping.copy()
def _patch_property(self, name, value):
self._patched = (name, value)
do_re_mi = self._callFUT('solfege')

test = Test()
test.do_re_mi = 'Latido'
self.assertEqual(test._patched, {'solfege': 'Latido'})
self.assertEqual(test._patched, ('solfege', 'Latido'))


class Test__base64_md5hash(unittest2.TestCase):
Expand Down