Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support for metadata during object creation #287

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gcp_storage_emulator/handlers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def _create_resumable_upload(request, response, storage):
object_id,
content_type,
content_length,
metadata={**(request.data or {}), "name": object_id},
)
id = storage.create_resumable_upload(
request.params["bucket_name"],
Expand Down
18 changes: 18 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,24 @@ def test_upload_from_file_content_type_json(self):
self.assertEqual(blob.name, file_name)
self.assertEqual(blob.download_as_bytes(), content)

def test_upload_from_file_with_metadata(self):
file_name = "test.json"
content = b'[{"a": 1}]'
bucket = self._client.create_bucket("testbucket")
blob = bucket.blob(file_name)
blob.metadata = {"foo": "bar"}

with NamedTemporaryFile() as temp_file:
temp_file.write(content)
temp_file.flush()
temp_file.seek(0)
blob.upload_from_file(temp_file, content_type="application/json")

blob = bucket.get_blob(file_name)
self.assertEqual(blob.name, file_name)
self.assertEqual(blob.download_as_bytes(), content)
self.assertEqual(blob.metadata, {"foo": "bar"})


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