Fix Google Tasks parsing of remove responses (#115258)

This commit is contained in:
Allen Porter 2024-04-08 22:39:31 -07:00 committed by GitHub
parent d4500cf945
commit 4a7a22641e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -112,8 +112,9 @@ class AsyncConfigEntryAuth:
raise GoogleTasksApiError( raise GoogleTasksApiError(
f"Google Tasks API responded with error ({exception.status_code})" f"Google Tasks API responded with error ({exception.status_code})"
) from exception ) from exception
data = json.loads(response) if response:
_raise_if_error(data) data = json.loads(response)
_raise_if_error(data)
for task_id in task_ids: for task_id in task_ids:
batch.add( batch.add(

View File

@ -156,7 +156,7 @@ def create_response_object(api_response: dict | list) -> tuple[Response, bytes]:
def create_batch_response_object( def create_batch_response_object(
content_ids: list[str], api_responses: list[dict | list | Response] content_ids: list[str], api_responses: list[dict | list | Response | None]
) -> tuple[Response, bytes]: ) -> tuple[Response, bytes]:
"""Create a batch response in the multipart/mixed format.""" """Create a batch response in the multipart/mixed format."""
assert len(api_responses) == len(content_ids) assert len(api_responses) == len(content_ids)
@ -166,7 +166,7 @@ def create_batch_response_object(
body = "" body = ""
if isinstance(api_response, Response): if isinstance(api_response, Response):
status = api_response.status status = api_response.status
else: elif api_response is not None:
body = json.dumps(api_response) body = json.dumps(api_response)
content.extend( content.extend(
[ [
@ -194,7 +194,7 @@ def create_batch_response_object(
def create_batch_response_handler( def create_batch_response_handler(
api_responses: list[dict | list | Response], api_responses: list[dict | list | Response | None],
) -> Callable[[Any], tuple[Response, bytes]]: ) -> Callable[[Any], tuple[Response, bytes]]:
"""Create a fake http2lib response handler that supports generating batch responses. """Create a fake http2lib response handler that supports generating batch responses.
@ -598,11 +598,11 @@ async def test_partial_update_status(
[ [
LIST_TASK_LIST_RESPONSE, LIST_TASK_LIST_RESPONSE,
LIST_TASKS_RESPONSE_MULTIPLE, LIST_TASKS_RESPONSE_MULTIPLE,
[EMPTY_RESPONSE, EMPTY_RESPONSE, EMPTY_RESPONSE], # Delete batch [None, None, None], # Delete batch empty responses
LIST_TASKS_RESPONSE, # refresh after delete LIST_TASKS_RESPONSE, # refresh after delete
] ]
) )
) ),
], ],
) )
async def test_delete_todo_list_item( async def test_delete_todo_list_item(