Skip to content

Commit

Permalink
fix: add "updated" as property for Bucket (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsg committed Feb 15, 2024
1 parent dcd6774 commit ae9a53b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions google/cloud/storage/bucket.py
Expand Up @@ -2618,6 +2618,21 @@ def time_created(self):
if value is not None:
return _rfc3339_nanos_to_datetime(value)

@property
def updated(self):
"""Retrieve the timestamp at which the bucket was last updated.
See https://cloud.google.com/storage/docs/json_api/v1/buckets
:rtype: :class:`datetime.datetime` or ``NoneType``
:returns: Datetime object parsed from RFC3339 valid timestamp, or
``None`` if the bucket's resource has not been loaded
from the server.
"""
value = self._properties.get("updated")
if value is not None:
return _rfc3339_nanos_to_datetime(value)

@property
def versioning_enabled(self):
"""Is versioning enabled for this bucket?
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_bucket.py
Expand Up @@ -2959,6 +2959,19 @@ def test_time_created_unset(self):
bucket = self._make_one()
self.assertIsNone(bucket.time_created)

def test_updated(self):
from google.cloud._helpers import _RFC3339_MICROS

TIMESTAMP = datetime.datetime(2023, 11, 5, 20, 34, 37, tzinfo=_UTC)
UPDATED = TIMESTAMP.strftime(_RFC3339_MICROS)
properties = {"updated": UPDATED}
bucket = self._make_one(properties=properties)
self.assertEqual(bucket.updated, TIMESTAMP)

def test_updated_unset(self):
bucket = self._make_one()
self.assertIsNone(bucket.updated)

def test_versioning_enabled_getter_missing(self):
NAME = "name"
bucket = self._make_one(name=NAME)
Expand Down

0 comments on commit ae9a53b

Please sign in to comment.