@@ -186,3 +186,50 @@ def test_capability_properties_work_with_mapped_profile(self, eu_api):
186186 assert v .air_purifier_supported is False
187187 assert v .is_left_hand_drive is True
188188 assert v .ev_alarm_supported is False
189+
190+
191+ class TestGetVehiclesProfileFetch :
192+ """get_vehicles fetches profiles only when supports_vehicle_profile is set."""
193+
194+ def _make_api (self , supported : bool ):
195+ from hyundai_kia_connect_api .ApiImplType1 import ApiImplType1
196+
197+ api = object .__new__ (ApiImplType1 )
198+ api .supports_vehicle_profile = supported
199+ api .SPA_API_URL = "https://example.test/api/v1/spa/"
200+ return api
201+
202+ def test_get_vehicles_fetches_profiles_when_supported (self ):
203+ import hyundai_kia_connect_api .ApiImplType1 as type1_mod
204+ from hyundai_kia_connect_api .ApiImplType1 import ApiImplType1
205+ from unittest .mock import patch , MagicMock
206+
207+ api = self ._make_api (supported = True )
208+ resp = MagicMock ()
209+ resp .json .return_value = {"resMsg" : {"vehicles" : []}}
210+ with (
211+ patch .object (ApiImplType1 , "_get_authenticated_headers" , return_value = {}),
212+ patch .object (type1_mod , "_check_response_for_errors" , return_value = None ),
213+ patch .object (type1_mod .requests , "get" , return_value = resp ),
214+ patch .object (ApiImplType1 , "_fetch_vehicle_profiles" ) as fetch ,
215+ ):
216+ result = ApiImplType1 .get_vehicles (api , token = MagicMock ())
217+ assert result == []
218+ fetch .assert_called_once ()
219+
220+ def test_get_vehicles_skips_profiles_when_not_supported (self ):
221+ import hyundai_kia_connect_api .ApiImplType1 as type1_mod
222+ from hyundai_kia_connect_api .ApiImplType1 import ApiImplType1
223+ from unittest .mock import patch , MagicMock
224+
225+ api = self ._make_api (supported = False )
226+ resp = MagicMock ()
227+ resp .json .return_value = {"resMsg" : {"vehicles" : []}}
228+ with (
229+ patch .object (ApiImplType1 , "_get_authenticated_headers" , return_value = {}),
230+ patch .object (type1_mod , "_check_response_for_errors" , return_value = None ),
231+ patch .object (type1_mod .requests , "get" , return_value = resp ),
232+ patch .object (ApiImplType1 , "_fetch_vehicle_profiles" ) as fetch ,
233+ ):
234+ ApiImplType1 .get_vehicles (api , token = MagicMock ())
235+ fetch .assert_not_called ()
0 commit comments