Example #1
0
def test_wpa_check_p2p_interface_negative(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('interface', )
        return ["Selected interface 'wlan0'", "Available interfaces:", "wlan0"]

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    assert wpacli.check_p2p_interface() == False
Example #2
0
def test_wpacli_p2p_connect(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('-i', 'w1p0', 'p2p_connect', 'peer01', '12345678')
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.p2p_connect("w1p0", '12345678', 'peer01')
Example #3
0
def test_wpacli_wps_pin(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('-i', 'w1p0', 'wps_pin', 'any', '12345678', '300')
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.set_wps_pin("w1p0", '12345678', 300)
Example #4
0
def test_wpacli_p2p_group_add(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ("p2p_group_add", 'persistent=42')
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.p2p_group_add("42")
Example #5
0
def test_wpacli_wfd_subelem_set(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ("wfd_subelem_set", "0", '00000000')
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.wfd_subelem_set(0, "00000000")
Example #6
0
def test_wpacli_stop_p2p_find(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('p2p_stop_find', )
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.stop_p2p_find()
Example #7
0
def test_wpacli_wps_pbc(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('-i', 'w1p0', 'wps_pbc')
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.start_wps_pbc("w1p0")
Example #8
0
def test_wpacli_stop_p2p_find_negative(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('p2p_stop_find', )
        return "FAILED"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    with pytest.raises(WpaException):
        wpacli.stop_p2p_find()
Example #9
0
def test_wpacli_wfd_subelem_set_negative(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ("wfd_subelem_set", "0", '00000000')
        return "FAILED"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    with pytest.raises(WpaException):
        wpacli.wfd_subelem_set(0, "00000000")
Example #10
0
def test_wpacli_start_p2p_find(monkeypatch):
    def mockreturn(self, *args):
        assert args == (
            'p2p_find',
            'type=progressive',
        )
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.start_p2p_find()
Example #11
0
def test_wpa_p2p_interface(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('interface', )
        return [
            "Selected interface 'p2p-wlp4s0'", "Available interfaces:",
            "p2p-wlp4s0", "wlp4s0"
        ]

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    result = wpacli.get_p2p_interface()
    assert result == "p2p-wlp4s0"
Example #12
0
def test_wpacli_get_persistent_group_network_id(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ("list_networks", )
        return [
            "Selected interface 'p2p-dev-wlan0",
            "network id / ssid / bssid / flags", "0       Some_wifi any",
            "1       DIRECT-3E_picast       aa:22:cc:33:dd:44       [DISABLED][P2P-PERSISTENT]"
        ]

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    assert wpacli.get_persistent_group_network_id("picast") == "1"
Example #13
0
def test_wpacli_set_p2p_go_ht40(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == (
            "set",
            "p2p_go_ht40",
            "1",
        )
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.set_p2p_go_ht40()
Example #14
0
def test_wpacli_set_device_name(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == (
            "set",
            "device_name",
            "foo",
        )
        return "OK"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    wpacli.set_device_name("foo")
Example #15
0
def test_wpa_get_interface(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == ('interface', )
        return [
            "Selected interface 'p2p-wlp4s0'", "Available interfaces:",
            "p2p-wlp4s0", "wlp4s0"
        ]

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    selected, interfaces = wpacli.get_interfaces()
    assert selected == 'p2p-wlp4s0'
    assert interfaces == ['p2p-wlp4s0', 'wlp4s0']
Example #16
0
def test_wpacli_set_p2p_go_ht40_negative(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == (
            "set",
            "p2p_go_ht40",
            "1",
        )
        return "FAILED"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    with pytest.raises(WpaException):
        wpacli.set_p2p_go_ht40()
Example #17
0
def test_wpacli_set_device_name_negative(monkeypatch):
    def mockreturn(self, *arg):
        assert arg == (
            "set",
            "device_name",
            "foo",
        )
        return "FAILED"

    monkeypatch.setattr(WpaCli, "cmd", mockreturn)
    wpacli = WpaCli()
    with pytest.raises(WpaException):
        wpacli.set_device_name("foo")
Example #18
0
 def set_p2p_interface(self, R2):
     wpacli = WpaCli()
     if wpacli.check_p2p_interface():
         self.logger.info("Already set a p2p interface.")
         p2p_interface = wpacli.get_p2p_interface()
     else:
         self.create_p2p_interface(R2)
         sleep(3)
         p2p_interface = wpacli.get_p2p_interface()
         if p2p_interface is None:
             raise WpaException("Can not create P2P Wifi interface.")
         self.logger.info("Start p2p interface: {} address {}".format(
             p2p_interface, self.config.myaddress))
         os.system("sudo ifconfig {} {}".format(p2p_interface,
                                                self.config.myaddress))
     self.wlandev = p2p_interface
Example #19
0
 def start_wps(self):
     wpacli = WpaCli()
     if self.config.wps_mode == "pbc":
         wpacli.start_wps_pbc(self.wlandev)
     else:
         wpacli.set_wps_pin(self.wlandev, self.config.pin,
                            self.config.timeout)
Example #20
0
 def create_p2p_interface(self, R2):
     wpacli = WpaCli()
     wpacli.start_p2p_find()
     wpacli.set_device_name(self.config.device_name)
     wpacli.set_device_type(self.config.device_type)
     wpacli.set_p2p_go_ht40()
     wpacli.wfd_subelem_set(0, self.wfd_devinfo())
     wpacli.wfd_subelem_set(1, self.wfd_bssid(0))
     wpacli.wfd_subelem_set(6, self.wfd_sink_info(0, 0))
     wpacli.wfd_subelem_set(7, self.wfd_ext_cap(uibc=False, i2c=False))
     if R2:
         wpacli.wfd_subelem_set(11, self.wfd_devinfo2())
     wpacli.p2p_group_add(self.config.group_name)