Skip to content

Commit

Permalink
If content is None, save it as b"" (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
oittaa authored Dec 14, 2021
1 parent f90f512 commit bc3687a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gcp_storage_emulator/handlers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def upload_partial(request, response, storage, *args, **kwargs):
response["Range"] = "bytes=0-{}".format(m_dict["end"])
return
else:
data = request.data
data = request.data or b""

obj = _checksums(data, obj)
obj["size"] = str(len(data))
Expand Down
8 changes: 8 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,14 @@ def test_resumable_upload_large_file(self):
self.assertEqual(len(fetched_content), len(content))
self.assertEqual(fetched_content, content)

def test_empty_blob(self):
bucket = self._client.create_bucket("testbucket")
bucket.blob("empty_blob").open("w").close()

blob = bucket.get_blob("empty_blob")
fetched_content = blob.download_as_bytes()
self.assertEqual(fetched_content, b"")


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

0 comments on commit bc3687a

Please sign in to comment.