Skip to content
Open
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 archinstall/lib/network/wifi_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async def _setup_wifi(self, wifi_iface: str) -> bool:

network_id = self._find_network_id(network.ssid, wifi_iface)

if not network_id:
if network_id is None:
debug('Failed to find network id')
await self._notify_failure()
return False
Expand Down
43 changes: 43 additions & 0 deletions tests/test_wifi_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import asyncio
from pathlib import Path
from unittest.mock import AsyncMock, patch

import pytest

from archinstall.lib.models.network import WifiNetwork
from archinstall.lib.network.wifi_handler import WifiHandler, WpaCliResult
from archinstall.tui.components import LoadingScreen, TableSelectionScreen
from archinstall.tui.result import Result


@pytest.mark.parametrize('network_id, expected', [(0, True), (1, True), (None, False)])
def test_setup_wifi_handles_network_id(tmp_path: Path, network_id: int | None, expected: bool) -> None:
network = WifiNetwork('aa:bb:cc:dd:ee:ff', '2412', '-40', '[WPA2-PSK-CCMP][ESS]', 'TestNetwork')
handler = WifiHandler()
handler._wpa_config.config_file = tmp_path / 'wpa_supplicant.conf'
listed_networks = 'network id / ssid / bssid / flags\n'
if network_id is not None:
listed_networks += f'{network_id}\tTestNetwork\tany\t\n'

with (
patch.object(handler, '_enable_supplicant', new=AsyncMock(return_value=True)),
patch.object(handler, '_scan_wifi', new=AsyncMock(return_value=[network])),
patch.object(TableSelectionScreen, 'run', new=AsyncMock(return_value=Result.selection(network))),
patch.object(handler, '_prompt_psk', new=AsyncMock(return_value='test-password')),
patch.object(LoadingScreen, 'run', new=AsyncMock()),
patch.object(handler, '_notify_failure', new=AsyncMock()) as notify_failure,
patch.object(
handler,
'_wpa_cli',
side_effect=[WpaCliResult(True), WpaCliResult(True, listed_networks), WpaCliResult(True)],
) as wpa_cli,
patch('archinstall.lib.log.logger._path', tmp_path),
):
assert asyncio.run(handler._setup_wifi('wlan0')) is expected

if expected:
wpa_cli.assert_called_with(f'enable {network_id}', 'wlan0')
notify_failure.assert_not_awaited()
else:
assert wpa_cli.call_count == 2
notify_failure.assert_awaited_once()