def test_create_no_number(self) -> None:
     parser = configparser.ConfigParser()
     parser.read_string(
         """
         [section]
         ports = 10,20xx,30
         """
     )
     with pytest.raises(ConfigurationError):
         ActiveConnection.create("name", parser["section"])
    def test_connected(self, monkeypatch, connection) -> None:
        def addresses():
            return {
                "dummy": [
                    snic(socket.AF_INET, self.MY_ADDRESS, "255.255.255.0", None, None),
                    snic(
                        socket.AF_INET6,
                        self.MY_ADDRESS_IPV6,
                        "ffff:ffff:ffff:ffff::",
                        None,
                        None,
                    ),
                    snic(
                        socket.AF_INET6,
                        self.MY_ADDRESS_IPV6_SCOPED,
                        "ffff:ffff:ffff:ffff::",
                        None,
                        None,
                    ),
                ],
            }

        def connections():
            return [connection]

        monkeypatch.setattr(psutil, "net_if_addrs", addresses)
        monkeypatch.setattr(psutil, "net_connections", connections)

        assert ActiveConnection("foo", [10, self.MY_PORT, 30]).check() is not None
Exemplo n.º 3
0
    def test_connected(self, monkeypatch, connection):

        def addresses():
            return {
                'dummy': [
                    snic(socket.AF_INET,
                         self.MY_ADDRESS,
                         '255.255.255.0',
                         None, None),
                    snic(socket.AF_INET6,
                         self.MY_ADDRESS_IPV6,
                         'ffff:ffff:ffff:ffff::',
                         None, None),
                    snic(socket.AF_INET6,
                         self.MY_ADDRESS_IPV6_SCOPED,
                         'ffff:ffff:ffff:ffff::',
                         None, None),
                ]
            }

        def connections():
            return [connection]

        monkeypatch.setattr(psutil, 'net_if_addrs', addresses)
        monkeypatch.setattr(psutil, 'net_connections', connections)

        assert ActiveConnection(
            'foo', [10, self.MY_PORT, 30]).check() is not None
 def test_create(self) -> None:
     parser = configparser.ConfigParser()
     parser.read_string(
         """
         [section]
         ports = 10,20,30
         """
     )
     assert ActiveConnection.create("name", parser["section"])._ports == {10, 20, 30}
 def test_smoke(self) -> None:
     ActiveConnection("foo", [22]).check()
 def create_instance(self, name):
     return ActiveConnection(name, [10])
Exemplo n.º 7
0
 def test_create_no_number(self):
     parser = configparser.ConfigParser()
     parser.read_string('''[section]
                        ports = 10,20xx,30''')
     with pytest.raises(ConfigurationError):
         ActiveConnection.create('name', parser['section'])
Exemplo n.º 8
0
 def test_create_no_entry(self):
     parser = configparser.ConfigParser()
     parser.read_string('''[section]''')
     with pytest.raises(ConfigurationError):
         ActiveConnection.create('name', parser['section'])
Exemplo n.º 9
0
 def test_create(self):
     parser = configparser.ConfigParser()
     parser.read_string('''[section]
                        ports = 10,20,30''')
     assert ActiveConnection.create(
         'name', parser['section'])._ports == {10, 20, 30}
Exemplo n.º 10
0
 def test_smoke(self):
     ActiveConnection('foo', [22]).check()