8
8
from aioresponses import aioresponses
9
9
import pytest
10
10
11
+ from matter_server .server .helpers import DCL_PRODUCTION_URL
11
12
from matter_server .server .ota .dcl import check_for_update
12
13
13
14
@@ -24,22 +25,31 @@ def mock_aioresponse():
24
25
yield m
25
26
26
27
28
+ def mock_dcl_version (
29
+ aioresponse , vid : int , pid : int , version : int | None = None , suffix : str = ""
30
+ ) -> dict :
31
+ """Test."""
32
+ if version :
33
+ data = _load_fixture (f"{ vid } -{ pid } -{ version } { suffix } .json" )
34
+ url = DCL_PRODUCTION_URL + f"/dcl/model/versions/{ vid } /{ pid } /{ version } "
35
+ else :
36
+ data = _load_fixture (f"{ vid } -{ pid } { suffix } .json" )
37
+ url = DCL_PRODUCTION_URL + f"/dcl/model/versions/{ vid } /{ pid } "
38
+ aioresponse .get (url = url , status = 200 , payload = data )
39
+ return data
40
+
41
+
27
42
@pytest .fixture (name = "get_software_versions" , autouse = True )
28
43
def _mock_get_software_versions (aioresponse ) -> None :
29
44
"""Mock the _get_software_versions function."""
30
- data = _load_fixture ("4447-8194.json" )
31
- aioresponse .get (url = "/dcl/model/versions/4447/8194" , status = 200 , payload = data )
32
- aioresponse .get (
33
- url = "/dcl/model/versions/4447/8194/1000" ,
34
- payload = _load_fixture ("4447-8194-1000.json" ),
35
- )
45
+ mock_dcl_version (aioresponse , 4447 , 8194 )
46
+ mock_dcl_version (aioresponse , 4447 , 8194 , 1000 )
36
47
37
48
38
49
async def test_check_updates (aioresponse ):
39
50
"""Test the case where the latest software version is applicable."""
40
51
# Call the function with a current software version of 1000
41
- data = _load_fixture ("4447-8194-1011-valid.json" )
42
- aioresponse .get (url = "/dcl/model/versions/4447/8194/1011" , status = 200 , payload = data )
52
+ data = mock_dcl_version (aioresponse , 4447 , 8194 , 1011 , "-valid" )
43
53
result = await check_for_update (MagicMock (), 4447 , 8194 , 1000 )
44
54
45
55
assert result == data ["modelVersion" ]
@@ -48,17 +58,15 @@ async def test_check_updates(aioresponse):
48
58
async def test_check_updates_not_applicable (aioresponse ):
49
59
"""Test the case where the latest software version is not applicable."""
50
60
# Call the function with a current software version of 2000
51
- data = _load_fixture ("4447-8194-1011-valid.json" )
52
- aioresponse .get (url = "/dcl/model/versions/4447/8194/1011" , status = 200 , payload = data )
61
+ mock_dcl_version (aioresponse , 4447 , 8194 , 1011 , "-valid" )
53
62
result = await check_for_update (MagicMock (), 4447 , 8194 , 2000 )
54
63
55
64
assert result is None
56
65
57
66
58
67
async def test_check_updates_not_applicable_not_valid (aioresponse ):
59
68
"""Test the case where the latest software version is not valid."""
60
- data = _load_fixture ("4447-8194-1011-invalid.json" )
61
- aioresponse .get (url = "/dcl/model/versions/4447/8194/1011" , status = 200 , payload = data )
69
+ mock_dcl_version (aioresponse , 4447 , 8194 , 1011 , "-invalid" )
62
70
result = await check_for_update (MagicMock (), 4447 , 8194 , 1000 )
63
71
64
72
assert result is None
@@ -67,8 +75,7 @@ async def test_check_updates_not_applicable_not_valid(aioresponse):
67
75
async def test_check_updates_specific_version (aioresponse ):
68
76
"""Test the case to get a specific version."""
69
77
# Call the function with a current software version of 1000 and request 1011 as update
70
- data = _load_fixture ("4447-8194-1011-valid.json" )
71
- aioresponse .get (url = "/dcl/model/versions/4447/8194/1011" , payload = data )
78
+ data = mock_dcl_version (aioresponse , 4447 , 8194 , 1011 , "-valid" )
72
79
result = await check_for_update (MagicMock (), 4447 , 8194 , 1000 , 1011 )
73
80
74
81
assert result == data ["modelVersion" ]
@@ -77,14 +84,10 @@ async def test_check_updates_specific_version(aioresponse):
77
84
async def test_check_no_update_if_url_empty (aioresponse ):
78
85
"""Test the case checks if latest version gets picked version."""
79
86
# Call the function with a current software version of 1000 and request 1011 as update
80
- data = _load_fixture ("4442-67.json" )
81
- aioresponse .get (url = "/dcl/model/versions/4442/67" , payload = data )
82
- data = _load_fixture ("4442-67-197888.json" )
83
- aioresponse .get (url = "/dcl/model/versions/4442/67/197888" , payload = data )
84
- data = _load_fixture ("4442-67-197910.json" )
85
- aioresponse .get (url = "/dcl/model/versions/4442/67/197910" , payload = data )
86
- data = _load_fixture ("4442-67-198340.json" )
87
- aioresponse .get (url = "/dcl/model/versions/4442/67/198340" , payload = data )
87
+ mock_dcl_version (aioresponse , 4442 , 67 )
88
+ mock_dcl_version (aioresponse , 4442 , 67 , 197888 )
89
+ mock_dcl_version (aioresponse , 4442 , 67 , 197910 )
90
+ mock_dcl_version (aioresponse , 4442 , 67 , 198340 )
88
91
result = await check_for_update (MagicMock (), 4442 , 67 , 197120 )
89
92
90
93
assert result is None
0 commit comments