From 71b71a5f27c570e112cc55d6af99186fff6d599f Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Mon, 27 Feb 2023 20:38:26 +0000 Subject: [PATCH 1/3] address late comments on #76428 --- homeassistant/components/prosegur/camera.py | 2 +- tests/components/prosegur/conftest.py | 2 +- tests/components/prosegur/test_camera.py | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/prosegur/camera.py b/homeassistant/components/prosegur/camera.py index 40f8e18fb66c68..a87c6c177f036c 100644 --- a/homeassistant/components/prosegur/camera.py +++ b/homeassistant/components/prosegur/camera.py @@ -73,8 +73,8 @@ async def async_camera_image( ) -> bytes | None: """Return bytes of camera image.""" + _LOGGER.debug("Get image for %s", self._camera.description) try: - _LOGGER.debug("Get image for %s", self._camera.description) return await self._installation.get_image(self._auth, self._camera.id) except ProsegurException as err: diff --git a/tests/components/prosegur/conftest.py b/tests/components/prosegur/conftest.py index ea906fdcbff45e..3e221dea710599 100644 --- a/tests/components/prosegur/conftest.py +++ b/tests/components/prosegur/conftest.py @@ -51,7 +51,7 @@ async def init_integration( with patch( "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.async_block_till_done() diff --git a/tests/components/prosegur/test_camera.py b/tests/components/prosegur/test_camera.py index 75e4cbbc77380c..daea284be6bb96 100644 --- a/tests/components/prosegur/test_camera.py +++ b/tests/components/prosegur/test_camera.py @@ -28,12 +28,9 @@ async def test_camera_fail(hass, init_integration, mock_install, caplog): ) with caplog.at_level(logging.ERROR, logger="homeassistant.components.prosegur"): - try: + with pytest.raises(HomeAssistantError) as exc: await camera.async_get_image(hass, "camera.test_cam") - except HomeAssistantError as exc: - assert str(exc) == "Unable to get image" - else: - assert pytest.fail() + assert "Unable to get image" in str(exc.value) assert "Image test_cam doesn't exist" in caplog.text From 073ccf257a9527356e147f7d88e4760940db42ac Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Mon, 27 Feb 2023 22:18:08 +0000 Subject: [PATCH 2/3] adress review --- tests/components/prosegur/conftest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/components/prosegur/conftest.py b/tests/components/prosegur/conftest.py index 3e221dea710599..bd2ce231e28ff5 100644 --- a/tests/components/prosegur/conftest.py +++ b/tests/components/prosegur/conftest.py @@ -1,5 +1,5 @@ """Define test fixtures for Prosegur.""" -from unittest.mock import AsyncMock, patch +from unittest.mock import AsyncMock, MagicMock, patch from pyprosegur.installation import Camera import pytest @@ -30,9 +30,12 @@ def mock_config_entry() -> MockConfigEntry: @pytest.fixture def mock_install() -> AsyncMock: """Return the mocked alarm install.""" - install = AsyncMock() + install = MagicMock() install.contract = CONTRACT 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.request_image = AsyncMock() From 36d8cd1eeba8d43e33154e9b3e96ef5c6836b582 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Mon, 27 Feb 2023 22:29:35 +0000 Subject: [PATCH 3/3] extra tweaks --- homeassistant/components/prosegur/camera.py | 2 +- tests/components/prosegur/test_camera.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/prosegur/camera.py b/homeassistant/components/prosegur/camera.py index a87c6c177f036c..848b763903a24d 100644 --- a/homeassistant/components/prosegur/camera.py +++ b/homeassistant/components/prosegur/camera.py @@ -85,8 +85,8 @@ async def async_camera_image( async def async_request_image(self): """Request new image from the camera.""" + _LOGGER.debug("Request image for %s", self._camera.description) try: - _LOGGER.debug("Request image for %s", self._camera.description) await self._installation.request_image(self._auth, self._camera.id) except ProsegurException as err: diff --git a/tests/components/prosegur/test_camera.py b/tests/components/prosegur/test_camera.py index daea284be6bb96..40ab57e088b9ba 100644 --- a/tests/components/prosegur/test_camera.py +++ b/tests/components/prosegur/test_camera.py @@ -27,9 +27,11 @@ async def test_camera_fail(hass, init_integration, mock_install, caplog): return_value=b"ABC", side_effect=ProsegurException() ) - with caplog.at_level(logging.ERROR, logger="homeassistant.components.prosegur"): - with pytest.raises(HomeAssistantError) as exc: - await camera.async_get_image(hass, "camera.test_cam") + with caplog.at_level( + logging.ERROR, logger="homeassistant.components.prosegur" + ), pytest.raises(HomeAssistantError) as exc: + await camera.async_get_image(hass, "camera.test_cam") + assert "Unable to get image" in str(exc.value) assert "Image test_cam doesn't exist" in caplog.text