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-07-03 01:17:36 +02:00
|
|
|
devices = wd.list_devices(1);
|
2016-10-05 01:26:43 +02:00
|
|
|
self.assertIsNotNone(devices)
|
|
|
|
device = devices[0]
|
|
|
|
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
ordered_networks = device.get_ordered_networks()
|
|
|
|
ordered_network = ordered_networks[0]
|
|
|
|
|
|
|
|
self.assertEqual(ordered_network.name, "ssidNew")
|
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
|
|
|
|
condition = 'obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
|
|
|
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()
|
|
|
|
self.assertEqual(len(known_networks), 3)
|
|
|
|
|
2018-07-31 16:37:08 +02:00
|
|
|
known_networks[0].forget()
|
2016-10-05 01:26:43 +02:00
|
|
|
|
|
|
|
known_networks = wd.list_known_networks()
|
|
|
|
self.assertEqual(len(known_networks), 2)
|
|
|
|
|
|
|
|
self.connect_to_new_network(wd)
|
|
|
|
|
|
|
|
known_networks = wd.list_known_networks()
|
|
|
|
self.assertEqual(len(known_networks), 3)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.list_removal_and_addition(wd)
|
|
|
|
except:
|
|
|
|
del wd
|
|
|
|
raise
|
|
|
|
|
|
|
|
del wd
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|