Skip to content

Commit

Permalink
fix: set custom_time on uploads (#374)
Browse files Browse the repository at this point in the history
The custom_time property was incorrectly not included as a field
that could be set on object upload.

Fixes #372
  • Loading branch information
tritone authored Feb 8, 2021
1 parent 5c60d24 commit f048be1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"contentLanguage",
_CONTENT_TYPE_FIELD,
"crc32c",
"customTime",
"md5Hash",
"metadata",
"name",
Expand Down Expand Up @@ -1530,6 +1531,7 @@ def _get_writable_metadata(self):
* ``contentLanguage``
* ``contentType``
* ``crc32c``
* ``customTime``
* ``md5Hash``
* ``metadata``
* ``name``
Expand Down
13 changes: 13 additions & 0 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f048be1

Please sign in to comment.