2016-10-05 01:26:43 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
import iwd
|
|
|
|
from iwd import IWD
|
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
|
|
|
|
def connect_to_new_network(self, wd):
|
2018-12-14 20:15:26 +01:00
|
|
|
devices = wd.list_devices(1)
|
2016-10-05 01:26:43 +02:00
|
|
|
self.assertIsNotNone(devices)
|
|
|
|
device = devices[0]
|
|
|
|
|
2018-10-02 21:02:17 +02:00
|
|
|
device.scan()
|
|
|
|
|
|
|
|
condition = 'obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
2016-10-05 01:26:43 +02:00
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
2018-12-14 20:15:28 +01:00
|
|
|
ordered_network = device.get_ordered_network('ssidNew')
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
|
2020-09-14 23:02:33 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
device.disconnect()
|
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
2018-07-03 01:17:36 +02:00
|
|
|
def list_removal_and_addition(self, wd):
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
known_networks = wd.list_known_networks()
|
2019-08-21 21:06:17 +02:00
|
|
|
self.assertEqual(len(known_networks), 4)
|
2016-10-05 01:26:43 +02:00
|
|
|
|
2018-08-09 16:33:46 +02:00
|
|
|
for network in known_networks:
|
|
|
|
if network.name == 'ssidTKIP':
|
|
|
|
network.forget()
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
known_networks = wd.list_known_networks()
|
2019-08-21 21:06:17 +02:00
|
|
|
self.assertEqual(len(known_networks), 3)
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
self.connect_to_new_network(wd)
|
|
|
|
|
|
|
|
known_networks = wd.list_known_networks()
|
2019-08-21 21:06:17 +02:00
|
|
|
self.assertEqual(len(known_networks), 4)
|
2016-10-05 01:26:43 +02:00
|
|
|
|
2018-08-09 16:33:46 +02:00
|
|
|
IWD.copy_to_storage('known_networks/ssidPSK.psk')
|
2019-08-21 21:06:17 +02:00
|
|
|
condition = 'len(obj.list_known_networks()) == 5'
|
2020-09-11 01:12:37 +02:00
|
|
|
wd.wait_for_object_condition(wd, condition)
|
2018-08-09 16:33:46 +02:00
|
|
|
|
2019-08-21 21:06:17 +02:00
|
|
|
expected = ['ssidNew', 'ssidOpen', 'ssidPSK', 'ssidEAP-TLS',
|
|
|
|
'Hotspot Network']
|
2018-08-09 16:33:46 +02:00
|
|
|
self.assertEqual({n.name for n in wd.list_known_networks()},
|
|
|
|
set(expected))
|
|
|
|
|
|
|
|
IWD.remove_from_storage('ssidPSK.psk')
|
2019-08-21 21:06:17 +02:00
|
|
|
condition = 'len(obj.list_known_networks()) == 4'
|
2020-09-11 01:12:37 +02:00
|
|
|
wd.wait_for_object_condition(wd, condition)
|
2018-08-09 16:33:46 +02:00
|
|
|
|
2016-10-05 01:26:43 +02:00
|
|
|
for net in known_networks:
|
2018-07-31 16:37:08 +02:00
|
|
|
net.forget()
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
known_networks = wd.list_known_networks()
|
|
|
|
self.assertEqual(len(known_networks), 0)
|
|
|
|
|
2018-07-03 01:17:36 +02:00
|
|
|
def test_known_networks(self):
|
|
|
|
wd = IWD(True)
|
|
|
|
|
2019-04-20 22:29:05 +02:00
|
|
|
self.list_removal_and_addition(wd)
|
2018-07-03 01:17:36 +02:00
|
|
|
|
2016-10-05 01:26:43 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
IWD.copy_to_storage('known_networks/ssidOpen.open')
|
|
|
|
IWD.copy_to_storage('known_networks/ssidTKIP.psk')
|
|
|
|
IWD.copy_to_storage('known_networks/ssidEAP-TLS.8021x')
|
2019-08-21 21:06:17 +02:00
|
|
|
IWD.copy_to_hotspot('known_networks/hotspot.conf')
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|