From 324171a451acaa524d2d9d7596b19c98f0483c97 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 08:37:38 +0000 Subject: [PATCH 1/2] Bump aioresponses from 0.7.7 to 0.7.8 Bumps [aioresponses](https://github.com/pnuckowski/aioresponses) from 0.7.7 to 0.7.8. - [Release notes](https://github.com/pnuckowski/aioresponses/releases) - [Commits](https://github.com/pnuckowski/aioresponses/compare/0.7.7...0.7.8) --- updated-dependencies: - dependency-name: aioresponses dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0111c749..5c56cd8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ server = [ "home-assistant-chip-core==2024.11.4", ] test = [ - "aioresponses==0.7.7", + "aioresponses==0.7.8", "codespell==2.3.0", "isort==5.13.2", "mypy==1.14.1", From 7ce548e5e613a791552e438ad2c035da109f9319 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 20 Jan 2025 14:14:58 +0100 Subject: [PATCH 2/2] Include DCL URL in test cases The new responses library seem to require the full URL to be included in the mocked response. --- tests/server/ota/test_dcl.py | 47 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/tests/server/ota/test_dcl.py b/tests/server/ota/test_dcl.py index eb507aba..0509d98b 100644 --- a/tests/server/ota/test_dcl.py +++ b/tests/server/ota/test_dcl.py @@ -8,6 +8,7 @@ from aioresponses import aioresponses import pytest +from matter_server.server.helpers import DCL_PRODUCTION_URL from matter_server.server.ota.dcl import check_for_update @@ -24,22 +25,31 @@ def mock_aioresponse(): yield m +def mock_dcl_version( + aioresponse, vid: int, pid: int, version: int | None = None, suffix: str = "" +) -> dict: + """Test.""" + if version: + data = _load_fixture(f"{vid}-{pid}-{version}{suffix}.json") + url = DCL_PRODUCTION_URL + f"/dcl/model/versions/{vid}/{pid}/{version}" + else: + data = _load_fixture(f"{vid}-{pid}{suffix}.json") + url = DCL_PRODUCTION_URL + f"/dcl/model/versions/{vid}/{pid}" + aioresponse.get(url=url, status=200, payload=data) + return data + + @pytest.fixture(name="get_software_versions", autouse=True) def _mock_get_software_versions(aioresponse) -> None: """Mock the _get_software_versions function.""" - data = _load_fixture("4447-8194.json") - aioresponse.get(url="/dcl/model/versions/4447/8194", status=200, payload=data) - aioresponse.get( - url="/dcl/model/versions/4447/8194/1000", - payload=_load_fixture("4447-8194-1000.json"), - ) + mock_dcl_version(aioresponse, 4447, 8194) + mock_dcl_version(aioresponse, 4447, 8194, 1000) async def test_check_updates(aioresponse): """Test the case where the latest software version is applicable.""" # Call the function with a current software version of 1000 - data = _load_fixture("4447-8194-1011-valid.json") - aioresponse.get(url="/dcl/model/versions/4447/8194/1011", status=200, payload=data) + data = mock_dcl_version(aioresponse, 4447, 8194, 1011, "-valid") result = await check_for_update(MagicMock(), 4447, 8194, 1000) assert result == data["modelVersion"] @@ -48,8 +58,7 @@ async def test_check_updates(aioresponse): async def test_check_updates_not_applicable(aioresponse): """Test the case where the latest software version is not applicable.""" # Call the function with a current software version of 2000 - data = _load_fixture("4447-8194-1011-valid.json") - aioresponse.get(url="/dcl/model/versions/4447/8194/1011", status=200, payload=data) + mock_dcl_version(aioresponse, 4447, 8194, 1011, "-valid") result = await check_for_update(MagicMock(), 4447, 8194, 2000) assert result is None @@ -57,8 +66,7 @@ async def test_check_updates_not_applicable(aioresponse): async def test_check_updates_not_applicable_not_valid(aioresponse): """Test the case where the latest software version is not valid.""" - data = _load_fixture("4447-8194-1011-invalid.json") - aioresponse.get(url="/dcl/model/versions/4447/8194/1011", status=200, payload=data) + mock_dcl_version(aioresponse, 4447, 8194, 1011, "-invalid") result = await check_for_update(MagicMock(), 4447, 8194, 1000) assert result is None @@ -67,8 +75,7 @@ async def test_check_updates_not_applicable_not_valid(aioresponse): async def test_check_updates_specific_version(aioresponse): """Test the case to get a specific version.""" # Call the function with a current software version of 1000 and request 1011 as update - data = _load_fixture("4447-8194-1011-valid.json") - aioresponse.get(url="/dcl/model/versions/4447/8194/1011", payload=data) + data = mock_dcl_version(aioresponse, 4447, 8194, 1011, "-valid") result = await check_for_update(MagicMock(), 4447, 8194, 1000, 1011) assert result == data["modelVersion"] @@ -77,14 +84,10 @@ async def test_check_updates_specific_version(aioresponse): async def test_check_no_update_if_url_empty(aioresponse): """Test the case checks if latest version gets picked version.""" # Call the function with a current software version of 1000 and request 1011 as update - data = _load_fixture("4442-67.json") - aioresponse.get(url="/dcl/model/versions/4442/67", payload=data) - data = _load_fixture("4442-67-197888.json") - aioresponse.get(url="/dcl/model/versions/4442/67/197888", payload=data) - data = _load_fixture("4442-67-197910.json") - aioresponse.get(url="/dcl/model/versions/4442/67/197910", payload=data) - data = _load_fixture("4442-67-198340.json") - aioresponse.get(url="/dcl/model/versions/4442/67/198340", payload=data) + mock_dcl_version(aioresponse, 4442, 67) + mock_dcl_version(aioresponse, 4442, 67, 197888) + mock_dcl_version(aioresponse, 4442, 67, 197910) + mock_dcl_version(aioresponse, 4442, 67, 198340) result = await check_for_update(MagicMock(), 4442, 67, 197120) assert result is None