Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit c330397

Browse files
committed
chore: test create_signed_upload_url
1 parent f756460 commit c330397

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

storage3/_async/file_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def create_signed_upload_url(self, path: str) -> SignedUploadURL:
6767
response = await self._request("POST", f"/object/upload/sign/{_path}")
6868
data = response.json()
6969
full_url: urllib.parse.ParseResult = urllib.parse.urlparse(
70-
self._client.base_url + data["url"]
70+
str(self._client.base_url) + data["url"]
7171
)
7272
query_params = urllib.parse.parse_qs(full_url.query)
7373
if not query_params.get("token"):

storage3/_sync/file_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def create_signed_upload_url(self, path: str) -> SignedUploadURL:
6767
response = self._request("POST", f"/object/upload/sign/{_path}")
6868
data = response.json()
6969
full_url: urllib.parse.ParseResult = urllib.parse.urlparse(
70-
self._client.base_url + data["url"]
70+
str(self._client.base_url) + data["url"]
7171
)
7272
query_params = urllib.parse.parse_qs(full_url.query)
7373
if not query_params.get("token"):

tests/_async/test_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ async def test_client_upload(
223223
assert image_info.get("metadata", {}).get("mimetype") == file.mime_type
224224

225225

226+
@pytest.mark.parametrize(
227+
"path", ["foobar.txt", "example/nested.jpg", "/leading/slash.png"]
228+
)
229+
async def test_client_create_signed_upload_url(
230+
storage_file_client: AsyncBucketProxy, path: str
231+
) -> None:
232+
"""Ensure we can create signed URLs to upload files to a bucket"""
233+
data = await storage_file_client.create_signed_upload_url(path)
234+
assert data["path"] == path
235+
assert data["token"]
236+
expected_url = f"{storage_file_client._client.base_url}/object/upload/sign/{storage_file_client.id}/{path.lstrip('/')}"
237+
assert data["signed_url"].startswith(expected_url)
238+
239+
226240
async def test_client_create_signed_url(
227241
storage_file_client: AsyncBucketProxy, file: FileForTesting
228242
) -> None:

tests/_sync/test_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,20 @@ def test_client_upload(
221221
assert image_info.get("metadata", {}).get("mimetype") == file.mime_type
222222

223223

224+
@pytest.mark.parametrize(
225+
"path", ["foobar.txt", "example/nested.jpg", "/leading/slash.png"]
226+
)
227+
def test_client_create_signed_upload_url(
228+
storage_file_client: SyncBucketProxy, path: str
229+
) -> None:
230+
"""Ensure we can create signed URLs to upload files to a bucket"""
231+
data = storage_file_client.create_signed_upload_url(path)
232+
assert data["path"] == path
233+
assert data["token"]
234+
expected_url = f"{storage_file_client._client.base_url}/object/upload/sign/{storage_file_client.id}/{path.lstrip('/')}"
235+
assert data["signed_url"].startswith(expected_url)
236+
237+
224238
def test_client_create_signed_url(
225239
storage_file_client: SyncBucketProxy, file: FileForTesting
226240
) -> None:

0 commit comments

Comments
 (0)