Skip to content

Commit

Permalink
Adjust handler to fetch upload details
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Oct 25, 2024
1 parent 1ab1084 commit 64e2f98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions hass_nabucasa/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FilesHandlerDownloadDetails(_FilesHandlerUrlResponse):
class FilesHandlerUploadDetails(_FilesHandlerUrlResponse):
"""Upload details from files handler."""

fields: dict[str, str]
headers: dict[str, str]


class FilesHandlerListEntry(TypedDict):
Expand Down Expand Up @@ -260,7 +260,7 @@ async def async_files_upload_details(
filename: str,
base64md5hash: str,
size: int,
homeassistant_version: str | None = None,
metadata: dict[str, str] | None = None,
) -> FilesHandlerUploadDetails:
"""Get files upload details."""
if TYPE_CHECKING:
Expand All @@ -271,9 +271,9 @@ async def async_files_upload_details(
json={
"storage_type": storage_type,
"filename": filename,
"homeassistant_version": homeassistant_version,
"md5": base64md5hash,
"size": size,
"metadata": metadata,
},
)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async def test_async_files_upload_detils(
"https://example.com/files/upload_details",
json={
"url": "https://example.com/some/path",
"fields": {"key": "value"},
"headers": {"key": "value"},
},
)
auth_cloud_mock.id_token = "mock-id-token"
Expand All @@ -337,22 +337,22 @@ async def test_async_files_upload_detils(
filename="test.txt",
base64md5hash=base64md5hash,
size=2,
homeassistant_version="1970.1.1",
metadata={"homeassistant_version": "1970.1.1"},
)

assert len(aioclient_mock.mock_calls) == 1
# 2 is the body
assert aioclient_mock.mock_calls[0][2] == {
"filename": "test.txt",
"storage_type": "test",
"homeassistant_version": "1970.1.1",
"metadata": {"homeassistant_version": "1970.1.1"},
"md5": base64md5hash,
"size": 2,
}

assert details == {
"url": "https://example.com/some/path",
"fields": {"key": "value"},
"headers": {"key": "value"},
}
assert "Fetched https://example.com/files/upload_details (200)" in caplog.text

Expand Down Expand Up @@ -387,9 +387,9 @@ async def test_async_files_upload_details_error(
assert aioclient_mock.mock_calls[0][2] == {
"filename": "test.txt",
"storage_type": "test",
"homeassistant_version": None,
"md5": base64md5hash,
"size": 2,
"metadata": None,
}

assert "Fetched https://example.com/files/upload_details (400) Boom!" in caplog.text

0 comments on commit 64e2f98

Please sign in to comment.