Skip to content

Commit

Permalink
alt=media query parameter (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
oittaa committed Mar 26, 2021
1 parent 259e12c commit 8a797dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gcp_storage_emulator/handlers/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ def upload_partial(request, response, storage, *args, **kwargs):


def get(request, response, storage, *args, **kwargs):
if request.query.get("alt") and request.query.get("alt")[0] == "media":
return download(request, response, storage)
try:
obj = storage.get_file_obj(
request.params["bucket_name"], request.params["object_id"]
Expand Down
24 changes: 24 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,30 @@ def test_download_by_url(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, content.encode("utf-8"))

def test_download_by_dl_api_url(self):
""" Objects should be downloadable over HTTP from the emulator client. """
content = "Here is some content"
bucket = self._client.create_bucket("stillabucket")
blob = bucket.blob("something.txt")
blob.upload_from_string(content)

url = self._url("/download/storage/v1/b/stillabucket/o/something.txt")
response = requests.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, content.encode("utf-8"))

def test_download_by_api_media_url(self):
""" Objects should be downloadable over HTTP from the emulator client. """
content = "Here is some content"
bucket = self._client.create_bucket("newishbucket")
blob = bucket.blob("something.txt")
blob.upload_from_string(content)

url = self._url("/storage/v1/b/newishbucket/o/something.txt")
response = requests.get(url, params={"alt": "media"})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, content.encode("utf-8"))

def test_download_file_within_folder(self):
"""Cloud Storage allows folders within buckets, so the download URL should allow for this."""
content = "Here is some content"
Expand Down

0 comments on commit 8a797dd

Please sign in to comment.