2017-10-31 23:03:00 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
import iwd
|
|
|
|
from iwd import IWD
|
|
|
|
from iwd import PSKAgent
|
|
|
|
from iwd import NetworkType
|
|
|
|
|
2019-10-24 19:53:23 +02:00
|
|
|
class TestConnectAutoConnect(unittest.TestCase):
|
2017-10-31 23:03:00 +01:00
|
|
|
|
|
|
|
def check_connect(self, wd, device, ssid, throws):
|
2020-05-06 23:32:15 +02:00
|
|
|
ordered_network = device.get_ordered_network(ssid, scan_if_needed=True)
|
2017-10-31 23:03:00 +01:00
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
|
|
|
if not throws is None:
|
|
|
|
with self.assertRaises(throws):
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
return
|
|
|
|
else:
|
2018-07-03 01:17:35 +02:00
|
|
|
ordered_network.network_object.connect()
|
2017-10-31 23:03:00 +01:00
|
|
|
|
2020-09-14 23:02:33 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2017-10-31 23:03:00 +01:00
|
|
|
|
|
|
|
def check_autoconnect(self, wd, device, ssid, throws):
|
2021-08-12 22:38:12 +02:00
|
|
|
device.autoconnect = True
|
|
|
|
|
2017-10-31 23:03:00 +01:00
|
|
|
if throws is None:
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
condition = 'obj.connected_network is not None'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
2019-01-08 23:43:57 +01:00
|
|
|
ordered_network = device.get_ordered_network(ssid)
|
2017-10-31 23:03:00 +01:00
|
|
|
|
|
|
|
self.assertTrue(ordered_network.network_object.connected)
|
|
|
|
|
|
|
|
device.disconnect()
|
|
|
|
|
|
|
|
condition = 'obj.state == DeviceState.disconnected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
2018-07-03 01:17:35 +02:00
|
|
|
def validate_connection(self, wd, ssid, autoconnect, throws = None,
|
|
|
|
use_agent = False):
|
2017-10-31 23:03:00 +01:00
|
|
|
if use_agent:
|
|
|
|
psk_agent = PSKAgent("secret123")
|
|
|
|
wd.register_psk_agent(psk_agent)
|
|
|
|
|
2018-12-14 20:15:26 +01:00
|
|
|
devices = wd.list_devices(1)
|
2017-10-31 23:03:00 +01:00
|
|
|
self.assertIsNotNone(devices)
|
|
|
|
device = devices[0]
|
|
|
|
|
|
|
|
if autoconnect:
|
|
|
|
self.check_autoconnect(wd, device, ssid, throws)
|
|
|
|
else:
|
|
|
|
self.check_connect(wd, device, ssid, throws)
|
|
|
|
|
|
|
|
if use_agent:
|
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
|
2018-07-03 01:17:35 +02:00
|
|
|
def validate(self, ssid, autoconnect, throws = None, use_agent = False):
|
|
|
|
wd = IWD(True)
|
|
|
|
|
2019-04-20 22:29:05 +02:00
|
|
|
self.validate_connection(wd, ssid, autoconnect, throws, use_agent)
|