Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump aioresponses from 0.7.7 to 0.7.8 #1040

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 25 additions & 22 deletions tests/server/ota/test_dcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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"]
Expand All @@ -48,17 +58,15 @@ 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


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
Expand All @@ -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"]
Expand All @@ -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
Loading