diff --git a/aiven/client/client.py b/aiven/client/client.py index 2c6d408..300bb00 100644 --- a/aiven/client/client.py +++ b/aiven/client/client.py @@ -175,7 +175,7 @@ def verify( time.sleep(0.2) # Check API is actually returning data or not - if response.status_code == HTTPStatus.NO_CONTENT or response.headers.get("Content-Length", "0") == "0": + if response.status_code == HTTPStatus.NO_CONTENT or len(response.content) == 0: return {} result = response.json() diff --git a/tests/test_cli.py b/tests/test_cli.py index ec52239..fafaef4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -157,7 +157,7 @@ def test_service_user_create() -> None: def test_service_topic_create(command_line: str, expected_post_data: Mapping[str, str | int | None]) -> None: client = AivenClient("") session = MagicMock(spec=Session) - session.post.return_value = MagicMock(status_code=200, json=MagicMock(return_value={})) + session.post.return_value = MagicMock(status_code=200, json=MagicMock(return_value={}), content=b"{}", reason="OK") client.session = session cli = build_aiven_cli(client) assert cli.run(args=command_line.split(" ")) is None @@ -258,7 +258,9 @@ def get_service_topic(self, project: str, service: str, topic: str) -> Mapping: client = TestAivenClient() session = MagicMock(spec=Session) - session.put.return_value = MagicMock(status_code=200, json=MagicMock(return_value={"message": "updated"})) + session.put.return_value = MagicMock( + status_code=200, json=MagicMock(return_value={"message": "updated"}), content=b'{"message":"updated"}', reason="OK" + ) client.session = session cli = build_aiven_cli(client) assert cli.run(args=command_line.split(" ")) is None diff --git a/tests/test_client.py b/tests/test_client.py index 819cd5a..90c9140 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -9,6 +9,7 @@ from typing import Any from unittest import mock +import json import pytest @@ -16,6 +17,10 @@ class MockResponse: def __init__(self, status_code: int, json_data: dict[str, Any] | None = None, headers: dict[str, str] | None = None): self.status_code = status_code self.json_data = json_data + if json_data is not None: + self.content = json.dumps(json_data).encode("utf-8") + else: + self.content = b"" self.headers = {} if headers is None else headers def json(self) -> Any: @@ -26,7 +31,7 @@ def json(self) -> Any: "response", [ MockResponse(status_code=HTTPStatus.NO_CONTENT), - MockResponse(status_code=HTTPStatus.CREATED, headers={"Content-Length": "0"}), + MockResponse(status_code=HTTPStatus.CREATED), ], ) def test_no_content_returned_from_api(response: MockResponse) -> None: