Exemplo n.º 1
0
    def test_f1_left_returns_none(self):
        ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), name=ci_name)
        ci.refresh = lambda *args, **kwargs: None #not needed

        # Checking at the start of the list
        def scenario():
            ci.keymap["KEY_LEFT"]()
            assert not ci.in_foreground

        with patch.object(ci, 'idle_loop', side_effect=scenario) as p:
            return_value = ci.activate()
        assert return_value is None

        # Checking after entering some keys
        letters_entered = 5
        test_keys = "ur"*letters_entered
        def scenario():
            for key in test_keys:
                execute_shorthand(ci, key)
            for i in range(letters_entered):
                execute_shorthand(ci, 'l')
                assert ci.in_foreground #Not yet at the beginning of the value
            execute_shorthand(ci, 'l')
            assert not ci.in_foreground #At the beginning of the value

        with patch.object(ci, 'idle_loop', side_effect=scenario) as p:
            return_value = ci.activate()
        assert return_value is None
Exemplo n.º 2
0
    def test_shows_data_on_screen(self):
        """Tests whether the CharArrowKeysInput outputs data on screen when it's ran"""
        i = get_mock_input()
        o = get_mock_output()
        ci = CharArrowKeysInput(i, o, message="Test:", name=ci_name)

        expected_output = "hello"
        test_key_offsets = (8, 5, 12, 12, 15)
        test_keys = "r".join(["u"*offset for offset in test_key_offsets])
        test_keys += "e" #Press ENTER

        def scenario():
            assert o.display_data.called
            assert o.display_data.call_args[0] == ('Test:', '')
            for key in test_keys:
                execute_shorthand(ci, key)
            assert not ci.in_foreground  # Should exit on last "e"

        with patch.object(ci, 'idle_loop', side_effect=scenario) as p:
            ci.activate()
            #The scenario should only be called once
            assert ci.idle_loop.called
            assert ci.idle_loop.call_count == 1

        assert o.display_data.called
        assert o.display_data.call_count == len(test_keys) #Magically, it's the same
        #There's one refresh right after the activate() that isn't because of a keypress,
        #And ENTER keypress at the end doesn't trigger a refresh, so it evens out
        assert o.display_data.call_args[0] == ('Test:', 'hello')
Exemplo n.º 3
0
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 = CharArrowKeysInput(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
Exemplo n.º 4
0
def set_password(id):    
    input = CharArrowKeysInput(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)
Exemplo n.º 5
0
 def test_value_leakage(self):
     """tests whether the action key settings of one CharArrowKeysInput leaks into another"""
     i = get_mock_input()
     o = get_mock_output()
     c1 = CharArrowKeysInput(i, o, value="1", name=ci_name + "1")
     c2 = CharArrowKeysInput(i, o, value="2", name=ci_name + "2")
     c3 = CharArrowKeysInput(i, o, name=ci_name + "3")
     assert (c1.value != c2.value)
     assert (c2.value != c3.value)
     assert (c1.value != c3.value)
Exemplo n.º 6
0
def set_password(id):
    input = CharArrowKeysInput(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)
Exemplo n.º 7
0
    def test_entering_value(self):
        ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), name=ci_name)
        ci.refresh = lambda *args, **kwargs: None

        expected_output = "hello"
        test_key_offsets = (8, 5, 12, 12, 15)
        test_keys = "r".join(["u"*offset for offset in test_key_offsets])
        test_keys += "e" #Press ENTER

        def scenario():
            for key in test_keys:
                execute_shorthand(ci, key)
            assert not ci.in_foreground  # Should exit on last "e"

        with patch.object(ci, 'idle_loop', side_effect=scenario) as p:
            return_value = ci.activate()
        assert return_value == expected_output
Exemplo n.º 8
0
def call_command():
    command = CharArrowKeysInput(i,
                                 o,
                                 message="Command:",
                                 name="Script command input").activate()
    if command is None:
        return
    call_external(command, shell=True)
Exemplo n.º 9
0
    def test_entering_value_with_backspaces(self):
        ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), name=ci_name)
        ci.refresh = lambda *args, **kwargs: None

        expected_output = "hello"
        test_key_offsets = (8, 5, 12, 12, 15)
        test_keys = "r".join(["u"*offset for offset in test_key_offsets])
        test_keys += "d"*(test_key_offsets[-1]+1) #Going back to the backspace character
        test_keys += "lr" #should erase the latest character and go to the position it took
        test_keys += "u"*test_key_offsets[-1] #adding the latest character again
        test_keys += "e" #Press ENTER

        def scenario():
            for key in test_keys:
                execute_shorthand(ci, key)
            assert not ci.in_foreground  # Should exit on last "e"

        with patch.object(ci, 'idle_loop', side_effect=scenario) as p:
            return_value = ci.activate()
        assert return_value == expected_output
Exemplo n.º 10
0
def call_by_path():
    path = PathPicker("/", i, o).activate()
    if path is None:
        return
    args = CharArrowKeysInput(i,
                              o,
                              message="Arguments:",
                              name="Script argument input").activate()
    if args is not None:
        path = path + " " + args
    call_external(path, shell=True)
Exemplo n.º 11
0
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 = CharArrowKeysInput(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
Exemplo n.º 12
0
 def test_initial_value_support(self):
     """tests support for the obsolete attribute"""
     value = "ololo"
     ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), initial_value = value, name=ci_name)
     assert ci.value == list(value)
Exemplo n.º 13
0
 def test_constructor(self):
     """tests constructor"""
     ci = CharArrowKeysInput(get_mock_input(), get_mock_output(), name=ci_name)
     self.assertIsNotNone(ci)
Exemplo n.º 14
0
def callback():
    char_input = Input(i, o, initial_value="password")
    print(repr(char_input.activate()))
Exemplo n.º 15
0
def callback():
    char_input = Input(i, o, initial_value = "password")
    print(repr(char_input.activate()))
Exemplo n.º 16
0
def callback():
    char_input = Input(i, o, initial_value="password")
    logger.info(repr(char_input.activate()))