| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5034,6 +5034,19 @@ def hard_delete_time(self): | |||
| 5034 | 5034 | if hard_delete_time is not None: | |
| 5035 | 5035 | return _rfc3339_nanos_to_datetime(hard_delete_time) | |
| 5036 | 5036 | ||
| 5037 | + @property | ||
| 5038 | + def finalized_time(self): | ||
| 5039 | + """If this object has been soft-deleted, returns the time at which it will be permanently deleted. | ||
| 5040 | + | ||
| 5041 | + :rtype: :class:`datetime.datetime` or ``NoneType`` | ||
| 5042 | + :returns: | ||
| 5043 | + (readonly) The time that the object will be permanently deleted. | ||
| 5044 | + Note this property is only set for soft-deleted objects. | ||
| 5045 | + """ | ||
| 5046 | + finalize_time = self._properties.get("finalizedTime", None) | ||
| 5047 | + if finalize_time is not None: | ||
| 5048 | + return _rfc3339_nanos_to_datetime(finalize_time) | ||
| 5049 | + | ||
| 5037 | 5050 | ||
| 5038 | 5051 | def _get_host_name(connection): | |
| 5039 | 5052 | """Returns the host name from the given connection. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,7 @@ def blob_metadata(bucket_name, blob_name): | |||
| 34 | 34 | blob = bucket.get_blob(blob_name) | |
| 35 | 35 | ||
| 36 | 36 | print(f"Blob: {blob.name}") | |
| 37 | + print(f"Blob finalization: {blob.finalized_time}") | ||
| 37 | 38 | print(f"Bucket: {blob.bucket.name}") | |
| 38 | 39 | print(f"Storage class: {blob.storage_class}") | |
| 39 | 40 | print(f"ID: {blob.id}") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -228,6 +228,29 @@ def test__set_properties_w_kms_key_name(self): | |||
| 228 | 228 | ) | |
| 229 | 229 | self._set_properties_helper(kms_key_name=kms_resource) | |
| 230 | 230 | ||
| 231 | + def test_finalized_time_property_is_none(self): | ||
| 232 | + BLOB_NAME = "blob-name" | ||
| 233 | + bucket = _Bucket() | ||
| 234 | + blob = self._make_one(BLOB_NAME, bucket=bucket) | ||
| 235 | + self.assertIsNone(blob.finalized_time) | ||
| 236 | + | ||
| 237 | + def test_finalized_time_property_is_not_none(self): | ||
| 238 | + from google.cloud.storage import blob as blob_module | ||
| 239 | + | ||
| 240 | + BLOB_NAME = "blob-name" | ||
| 241 | + bucket = _Bucket() | ||
| 242 | + blob = self._make_one(BLOB_NAME, bucket=bucket) | ||
| 243 | + | ||
| 244 | + timestamp = "2024-07-29T12:34:56.123456Z" | ||
| 245 | + blob._properties["finalizedTime"] = timestamp | ||
| 246 | + | ||
| 247 | + mock_datetime = mock.Mock() | ||
| 248 | + with mock.patch.object( | ||
| 249 | + blob_module, "_rfc3339_nanos_to_datetime", return_value=mock_datetime | ||
| 250 | + ) as mocked: | ||
| 251 | + self.assertEqual(blob.finalized_time, mock_datetime) | ||
| 252 | + mocked.assert_called_once_with(timestamp) | ||
| 253 | + | ||
| 231 | 254 | def test_chunk_size_ctor(self): | |
| 232 | 255 | from google.cloud.storage.blob import Blob | |
| 233 | 256 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments