def connect_to_network(network_info): #First, looking in the known networks configured_networks = wpa_cli.list_configured_networks() for network in configured_networks: if network_info['ssid'] == network['ssid']: Printer([network_info['ssid'], "known,connecting"], i, o, 1) wpa_cli.enable_network(network['network id']) wpa_cli.save_config() raise MenuExitException #Then, if it's an open network, just connecting if wpa_cli.is_open_network(network_info): network_id = wpa_cli.add_network() Printer(["Network is open", "adding to known"], i, o, 1) ssid = network_info['ssid'] wpa_cli.set_network(network_id, 'ssid', '"{}"'.format(ssid)) wpa_cli.set_network(network_id, 'key_mgmt', 'NONE') Printer(["Connecting to", network_info['ssid']], i, o, 1) wpa_cli.enable_network(network_id) wpa_cli.save_config() raise MenuExitException #Offering to enter a password else: input = NumpadCharInput(i, o, message="Password:"******"WiFi password enter UI element") password = input.activate() if password is None: return False network_id = wpa_cli.add_network() Printer(["Password entered", "adding to known"], i, o, 1) ssid = network_info['ssid'] wpa_cli.set_network(network_id, 'ssid', '"{}"'.format(ssid)) wpa_cli.set_network(network_id, 'psk', '"{}"'.format(password)) Printer(["Connecting to", network_info['ssid']], i, o, 1) wpa_cli.enable_network(network_id) wpa_cli.save_config() raise MenuExitException
def set_password(id): input = NumpadCharInput(i, o, message="Password:"******"WiFi password enter UI element") password = input.activate() if password is None: return False wpa_cli.set_network(id, 'psk', '"{}"'.format(password)) wpa_cli.save_config() Printer(["Password entered"], i, o, 1)
def call_command(): command = NumpadCharInput(i, o, message="Command:", name="Script command input").activate() if command is None: return call_external(command, shell=True)
def call_by_path(): path = PathPicker("/", i, o).activate() if path is None: return args = NumpadCharInput(i, o, message="Arguments:", name="Script argument input").activate() if args is not None: path = path+" "+args call_external(path, shell=True)
def test_entering_value(self): ni = NumpadCharInput(get_mock_input(), get_mock_output(), name=ni_name) ni.refresh = lambda *args, **kwargs: None #Defining a key sequence to be tested key_sequence = [ 4, 4, 3, 3, 5, 5, 5, "RIGHT", 5, 5, 5, 6, 6, 6, "ENTER" ] expected_output = "hello" def scenario(): for key in key_sequence: ni.process_streaming_keycode("KEY_{}".format(key)) assert not ni.in_foreground # Should not be active with patch.object(ni, 'idle_loop', side_effect=scenario) as p: return_value = ni.activate() assert return_value == expected_output
def test_shows_data_on_screen(self): """Tests whether the NumpadCharInput outputs data on screen when it's ran""" i = get_mock_input() o = get_mock_output() ni = NumpadCharInput(i, o, message="Test:", name=ni_name) def scenario(): ni.deactivate() with patch.object(ni, 'idle_loop', side_effect=scenario) as p: ni.activate() #The scenario should only be called once assert ni.idle_loop.called assert ni.idle_loop.call_count == 1 assert o.display_data.called assert o.display_data.call_count == 1 #One in to_foreground assert o.display_data.call_args[0] == ('Test:', '', '', '', '', '', '', ' Cancel OK Erase ')
def test_action_keys_leakage(self): """tests whether the action key settings of one NumpadCharInput leaks into another""" i = get_mock_input() o = get_mock_output() i1 = NumpadCharInput(i, o, name=ni_name + "1") i1.action_keys["F1"] = "accept_value" i2 = NumpadCharInput(i, o, name=ni_name + "2") i1.action_keys["F1"] = "accept_value" i2.action_keys["ENTER"] = "deactivate" i3 = NumpadCharInput(i, o, name=ni_name + "3") assert (i1.action_keys != i2.action_keys) assert (i2.action_keys != i3.action_keys) assert (i1.action_keys != i3.action_keys)
def test_f1_left_returns_none(self): ni = NumpadCharInput(get_mock_input(), get_mock_output(), name=ni_name) ni.refresh = lambda *args, **kwargs: None #not needed # Checking at the start of the list def scenario(): ni.process_streaming_keycode("KEY_LEFT") assert not ni.in_foreground with patch.object(ni, 'idle_loop', side_effect=scenario) as p: return_value = ni.activate() assert return_value is None # Checking at the end of the list def scenario(): for i in range(3): ni.process_streaming_keycode("KEY_1") ni.process_streaming_keycode("KEY_F1") assert not ni.in_foreground with patch.object(ni, 'idle_loop', side_effect=scenario) as p: return_value = ni.activate() assert return_value is None
def test_constructor(self): """tests constructor""" ni = NumpadCharInput(get_mock_input(), get_mock_output(), name=ni_name) self.assertIsNotNone(ni)
def callback(): char_input = CharInput(i, o, message="Input characters") print(repr(char_input.activate())) number_input = NumberInput(i, o, message="Input numbers") print(repr(number_input.activate()))