Skip to content

Commit

Permalink
Making Blob.storage_class settable. (#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes authored Apr 27, 2017
1 parent c9f29c9 commit ce043bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
25 changes: 14 additions & 11 deletions storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Blob(_PropertyMixin):
.. note::
This list does not include 'DURABLE_REDUCED_AVAILABILITY', which
is only documented for buckets (and deprectated.
is only documented for buckets (and deprecated).
.. note::
The documentation does *not* mention 'STANDARD', but it is the value
Expand Down Expand Up @@ -1220,18 +1220,21 @@ def size(self):
if size is not None:
return int(size)

@property
def storage_class(self):
"""Retrieve the storage class for the object.
storage_class = _scalar_property('storageClass')
"""Retrieve the storage class for the object.
See: https://cloud.google.com/storage/docs/storage-classes
This can only be set at blob / object **creation** time. If you'd
like to change the storage class **after** the blob / object already
exists in a bucket, call :meth:`update_storage_class` (which uses
the "storage.objects.rewrite" method).
:rtype: str or ``NoneType``
:returns: If set, one of "MULTI_REGIONAL", "REGIONAL",
"NEARLINE", "COLDLINE", "STANDARD", or
"DURABLE_REDUCED_AVAILABILITY", else ``None``.
"""
return self._properties.get('storageClass')
See: https://cloud.google.com/storage/docs/storage-classes
:rtype: str or ``NoneType``
:returns: If set, one of "MULTI_REGIONAL", "REGIONAL",
"NEARLINE", "COLDLINE", "STANDARD", or
"DURABLE_REDUCED_AVAILABILITY", else ``None``.
"""

@property
def time_deleted(self):
Expand Down
22 changes: 16 additions & 6 deletions storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,13 +2057,23 @@ def test_size_string_val(self):
properties={'size': str(SIZE)})
self.assertEqual(blob.size, SIZE)

def test_storage_class(self):
BLOB_NAME = 'blob-name'
def test_storage_class_getter(self):
blob_name = 'blob-name'
bucket = _Bucket()
STORAGE_CLASS = 'http://example.com/self/'
properties = {'storageClass': STORAGE_CLASS}
blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties)
self.assertEqual(blob.storage_class, STORAGE_CLASS)
storage_class = 'MULTI_REGIONAL'
properties = {'storageClass': storage_class}
blob = self._make_one(blob_name, bucket=bucket, properties=properties)
self.assertEqual(blob.storage_class, storage_class)

def test_storage_class_setter(self):
blob_name = 'blob-name'
bucket = _Bucket()
storage_class = 'COLDLINE'
blob = self._make_one(blob_name, bucket=bucket)
self.assertIsNone(blob.storage_class)
blob.storage_class = storage_class
self.assertEqual(blob.storage_class, storage_class)
self.assertEqual(blob._properties, {'storageClass': storage_class})

def test_time_deleted(self):
import datetime
Expand Down

0 comments on commit ce043bb

Please sign in to comment.