@@ -2142,6 +2142,71 @@ def test_calls_state_and_connectivity(self, qapp):
21422142 w ._async_load_saved_networks .assert_awaited_once ()
21432143
21442144
2145+ class TestWiredProfilesAutoconnect :
2146+ """Device.Autoconnect dies on NM restart; only the profile flag persists."""
2147+
2148+ @staticmethod
2149+ def _wire_profiles (w , conn_type = "802-3-ethernet" , autoconnect = True ):
2150+ nm_settings_proxy = AsyncProxyMock (
2151+ list_connections = AsyncMock (return_value = ["/conn/eth" ])
2152+ )
2153+ w ._nm_settings = _ProxyFactory (nm_settings_proxy )
2154+ settings = {
2155+ "connection" : {
2156+ "type" : ("s" , conn_type ),
2157+ "autoconnect" : ("b" , autoconnect ),
2158+ "timestamp" : ("t" , 123 ),
2159+ },
2160+ "ipv4" : {"method" : ("s" , "auto" )},
2161+ }
2162+ w ._gather_settings = AsyncMock (return_value = [("/conn/eth" , settings )])
2163+ conn_proxy = AsyncProxyMock (update = AsyncMock ())
2164+ w ._conn_settings = lambda path : conn_proxy
2165+ return conn_proxy
2166+
2167+ @pytest .mark .asyncio
2168+ async def test_disables_wired_profile (self , qapp ):
2169+ w = _make_worker (qapp )
2170+ conn = self ._wire_profiles (w , autoconnect = True )
2171+ await w ._set_wired_profiles_autoconnect (False )
2172+ props = conn .update .await_args [0 ][0 ]
2173+ assert props ["connection" ]["autoconnect" ] == ("b" , False )
2174+
2175+ @pytest .mark .asyncio
2176+ async def test_strips_timestamp_nm_will_not_accept (self , qapp ):
2177+ w = _make_worker (qapp )
2178+ conn = self ._wire_profiles (w , autoconnect = True )
2179+ await w ._set_wired_profiles_autoconnect (False )
2180+ assert "timestamp" not in conn .update .await_args [0 ][0 ]["connection" ]
2181+
2182+ @pytest .mark .asyncio
2183+ async def test_reenables_wired_profile (self , qapp ):
2184+ w = _make_worker (qapp )
2185+ conn = self ._wire_profiles (w , autoconnect = False )
2186+ await w ._set_wired_profiles_autoconnect (True )
2187+ assert conn .update .await_args [0 ][0 ]["connection" ]["autoconnect" ] == ("b" , True )
2188+
2189+ @pytest .mark .asyncio
2190+ async def test_skips_when_already_correct (self , qapp ):
2191+ w = _make_worker (qapp )
2192+ conn = self ._wire_profiles (w , autoconnect = True )
2193+ await w ._set_wired_profiles_autoconnect (True )
2194+ conn .update .assert_not_awaited ()
2195+
2196+ @pytest .mark .asyncio
2197+ async def test_ignores_non_ethernet_profiles (self , qapp ):
2198+ w = _make_worker (qapp )
2199+ conn = self ._wire_profiles (w , conn_type = "802-11-wireless" , autoconnect = True )
2200+ await w ._set_wired_profiles_autoconnect (False )
2201+ conn .update .assert_not_awaited ()
2202+
2203+ @pytest .mark .asyncio
2204+ async def test_exception_is_non_fatal (self , qapp ):
2205+ w = _make_worker (qapp )
2206+ w ._nm_settings = MagicMock (side_effect = RuntimeError ("boom" ))
2207+ await w ._set_wired_profiles_autoconnect (False ) # must not raise
2208+
2209+
21452210class TestEnsureWiredAutoconnect :
21462211 def test_no_wired_device_returns_early (self , qapp ):
21472212 w = _make (qapp , wired = False )
@@ -2164,6 +2229,13 @@ def test_autoconnect_on_is_left_alone(self, qapp):
21642229 _run (w ._ensure_wired_autoconnect ())
21652230 wired .autoconnect .set_async .assert_not_awaited ()
21662231
2232+ def test_profiles_are_rearmed_too (self , qapp ):
2233+ w = _make (qapp )
2234+ w ._set_wired_profiles_autoconnect = AsyncMock ()
2235+ _wire (w , wired_proxy = AsyncProxyMock (state = 30 , autoconnect = False ))
2236+ _run (w ._ensure_wired_autoconnect ())
2237+ w ._set_wired_profiles_autoconnect .assert_awaited_once_with (True )
2238+
21672239 def test_exception_is_non_fatal (self , qapp ):
21682240 w = _make (qapp )
21692241 w ._generic = MagicMock (side_effect = RuntimeError ("boom" ))
@@ -2276,6 +2348,17 @@ def test_calls_disconnect(self, qapp):
22762348 wired .disconnect .assert_awaited_once ()
22772349 w ._deactivate_all_vlans .assert_awaited_once ()
22782350
2351+ def test_persists_choice_in_the_profile (self , qapp ):
2352+ w = _make (qapp )
2353+ wired = AsyncProxyMock ()
2354+ wired .disconnect = AsyncMock ()
2355+ _wire (w , wired_proxy = wired )
2356+ w ._is_ethernet_connected = AsyncMock (return_value = False )
2357+ w ._deactivate_all_vlans = AsyncMock ()
2358+ w ._set_wired_profiles_autoconnect = AsyncMock ()
2359+ _run (w ._async_disconnect_ethernet ())
2360+ w ._set_wired_profiles_autoconnect .assert_awaited_once_with (False )
2361+
22792362
22802363class TestConnectEthernetAsync :
22812364 def test_no_wired_path_emits_error (self , qapp ):
0 commit comments