Skip to content

Commit bc3687a

Browse files
authored
If content is None, save it as b"" (#109)
1 parent f90f512 commit bc3687a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

gcp_storage_emulator/handlers/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def upload_partial(request, response, storage, *args, **kwargs):
263263
response["Range"] = "bytes=0-{}".format(m_dict["end"])
264264
return
265265
else:
266-
data = request.data
266+
data = request.data or b""
267267

268268
obj = _checksums(data, obj)
269269
obj["size"] = str(len(data))

tests/test_server.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,14 @@ def test_resumable_upload_large_file(self):
772772
self.assertEqual(len(fetched_content), len(content))
773773
self.assertEqual(fetched_content, content)
774774

775+
def test_empty_blob(self):
776+
bucket = self._client.create_bucket("testbucket")
777+
bucket.blob("empty_blob").open("w").close()
778+
779+
blob = bucket.get_blob("empty_blob")
780+
fetched_content = blob.download_as_bytes()
781+
self.assertEqual(fetched_content, b"")
782+
775783

776784
class HttpEndpointsTest(ServerBaseCase):
777785
"""Tests for the HTTP endpoints defined by server.HANDLERS."""

0 commit comments

Comments
 (0)