Prosegur late review comments (#88859)

* address late comments on #76428

* adress review

* extra tweaks
This commit is contained in:
Diogo Gomes 2023-02-28 07:16:22 +00:00 committed by GitHub
parent 7b3cab1bfe
commit 07c25b3dd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 12 deletions

View file

@ -73,8 +73,8 @@ class ProsegurCamera(Camera):
) -> bytes | None: ) -> bytes | None:
"""Return bytes of camera image.""" """Return bytes of camera image."""
_LOGGER.debug("Get image for %s", self._camera.description)
try: try:
_LOGGER.debug("Get image for %s", self._camera.description)
return await self._installation.get_image(self._auth, self._camera.id) return await self._installation.get_image(self._auth, self._camera.id)
except ProsegurException as err: except ProsegurException as err:
@ -85,8 +85,8 @@ class ProsegurCamera(Camera):
async def async_request_image(self): async def async_request_image(self):
"""Request new image from the camera.""" """Request new image from the camera."""
_LOGGER.debug("Request image for %s", self._camera.description)
try: try:
_LOGGER.debug("Request image for %s", self._camera.description)
await self._installation.request_image(self._auth, self._camera.id) await self._installation.request_image(self._auth, self._camera.id)
except ProsegurException as err: except ProsegurException as err:

View file

@ -1,5 +1,5 @@
"""Define test fixtures for Prosegur.""" """Define test fixtures for Prosegur."""
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, MagicMock, patch
from pyprosegur.installation import Camera from pyprosegur.installation import Camera
import pytest import pytest
@ -30,9 +30,12 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture @pytest.fixture
def mock_install() -> AsyncMock: def mock_install() -> AsyncMock:
"""Return the mocked alarm install.""" """Return the mocked alarm install."""
install = AsyncMock() install = MagicMock()
install.contract = CONTRACT install.contract = CONTRACT
install.cameras = [Camera("1", "test_cam")] install.cameras = [Camera("1", "test_cam")]
install.arm = AsyncMock()
install.disarm = AsyncMock()
install.arm_partially = AsyncMock()
install.get_image = AsyncMock(return_value=b"ABC") install.get_image = AsyncMock(return_value=b"ABC")
install.request_image = AsyncMock() install.request_image = AsyncMock()
@ -51,7 +54,7 @@ async def init_integration(
with patch( with patch(
"pyprosegur.installation.Installation.retrieve", return_value=mock_install "pyprosegur.installation.Installation.retrieve", return_value=mock_install
), patch("pyprosegur.auth.Auth.login", return_value=AsyncMock()): ), patch("pyprosegur.auth.Auth.login"):
await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()

View file

@ -27,13 +27,12 @@ async def test_camera_fail(hass, init_integration, mock_install, caplog):
return_value=b"ABC", side_effect=ProsegurException() return_value=b"ABC", side_effect=ProsegurException()
) )
with caplog.at_level(logging.ERROR, logger="homeassistant.components.prosegur"): with caplog.at_level(
try: logging.ERROR, logger="homeassistant.components.prosegur"
await camera.async_get_image(hass, "camera.test_cam") ), pytest.raises(HomeAssistantError) as exc:
except HomeAssistantError as exc: await camera.async_get_image(hass, "camera.test_cam")
assert str(exc) == "Unable to get image"
else: assert "Unable to get image" in str(exc.value)
assert pytest.fail()
assert "Image test_cam doesn't exist" in caplog.text assert "Image test_cam doesn't exist" in caplog.text