From f048be10416f51cea4e6c8c5b805df7b5d9c4d32 Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Mon, 8 Feb 2021 15:07:05 -0500 Subject: [PATCH] fix: set custom_time on uploads (#374) The custom_time property was incorrectly not included as a field that could be set on object upload. Fixes #372 --- google/cloud/storage/blob.py | 2 ++ tests/system/test_system.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/google/cloud/storage/blob.py b/google/cloud/storage/blob.py index 6127411df..f1cb5666b 100644 --- a/google/cloud/storage/blob.py +++ b/google/cloud/storage/blob.py @@ -96,6 +96,7 @@ "contentLanguage", _CONTENT_TYPE_FIELD, "crc32c", + "customTime", "md5Hash", "metadata", "name", @@ -1530,6 +1531,7 @@ def _get_writable_metadata(self): * ``contentLanguage`` * ``contentType`` * ``crc32c`` + * ``customTime`` * ``md5Hash`` * ``metadata`` * ``name`` diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 1ff17a61f..ec05b0c72 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -1027,6 +1027,19 @@ def test_upload_blob_owner(self): owner = same_blob.owner self.assertIn(user_email, owner["entity"]) + def test_upload_blob_custom_time(self): + blob = self.bucket.blob("CustomTimeBlob") + file_contents = b"Hello World" + current_time = datetime.datetime.now() + blob.custom_time = current_time + blob.upload_from_string(file_contents) + self.case_blobs_to_delete.append(blob) + + same_blob = self.bucket.blob("CustomTimeBlob") + same_blob.reload(projection="full") + custom_time = same_blob.custom_time.replace(tzinfo=None) + self.assertEqual(custom_time, current_time) + def test_blob_crc32_md5_hash(self): blob = self.bucket.blob("MyBuffer") file_contents = b"Hello World"