def test_no_activity(self, serve_data_url) -> None:
     check = NetworkBandwidth(
         "name", psutil.net_if_addrs().keys(), sys.float_info.max, sys.float_info.max
     )
     # make some traffic
     requests.get(serve_data_url)
     assert check.check() is None
Ejemplo n.º 2
0
 def test_no_activity(self, stub_server):
     check = NetworkBandwidth(
         'name', psutil.net_if_addrs().keys(),
         sys.float_info.max, sys.float_info.max)
     # make some traffic
     requests.get(stub_server.resource_address(''))
     assert check.check() is None
Ejemplo n.º 3
0
 def test_with_activity(self, send_threshold, receive_threshold, match,
                        stub_server):
     check = NetworkBandwidth(
         'name', psutil.net_if_addrs().keys(),
         send_threshold, receive_threshold)
     # make some traffic
     requests.get(stub_server.resource_address(''))
     res = check.check()
     assert res is not None
     assert match in res
 def test_with_activity(
     self, send_threshold, receive_threshold, match, serve_data_url
 ) -> None:
     check = NetworkBandwidth(
         "name", psutil.net_if_addrs().keys(), send_threshold, receive_threshold
     )
     # make some traffic
     requests.get(serve_data_url)
     res = check.check()
     assert res is not None
     assert match in res
Ejemplo n.º 5
0
    def test_create_default(self, mock_interfaces):
        parser = configparser.ConfigParser()
        parser.read_string('''
[section]
interfaces = foo, baz
''')
        check = NetworkBandwidth.create('name', parser['section'])
        assert set(check._interfaces) == {'foo', 'baz'}
        assert check._threshold_send == 100
        assert check._threshold_receive == 100
    def test_create_default(self, _mock_interfaces) -> None:
        parser = configparser.ConfigParser()
        parser.read_string(
            """
[section]
interfaces = foo, baz
"""
        )
        check = NetworkBandwidth.create("name", parser["section"])
        assert set(check._interfaces) == {"foo", "baz"}
        assert check._threshold_send == 100
        assert check._threshold_receive == 100
    def test_delta_calculation_receive(self, mocker) -> None:
        first = mocker.MagicMock()
        type(first).bytes_sent = mocker.PropertyMock(return_value=1000)
        type(first).bytes_recv = mocker.PropertyMock(return_value=800)
        mocker.patch("psutil.net_io_counters").return_value = {
            "eth0": first,
        }

        with freeze_time("2019-10-01 10:00:00"):
            check = NetworkBandwidth("name", ["eth0"], sys.float_info.max, 0)

        second = mocker.MagicMock()
        type(second).bytes_sent = mocker.PropertyMock(return_value=1222)
        type(second).bytes_recv = mocker.PropertyMock(return_value=900)
        mocker.patch("psutil.net_io_counters").return_value = {
            "eth0": second,
        }

        with freeze_time("2019-10-01 10:00:01"):
            res = check.check()
            assert res is not None
            assert " 100.0 " in res
 def test_internal_state_updated(self, serve_data_url) -> None:
     check = NetworkBandwidth(
         "name", psutil.net_if_addrs().keys(), sys.float_info.max, sys.float_info.max
     )
     check.check()
     old_state = check._previous_values
     requests.get(serve_data_url)
     check.check()
     assert old_state != check._previous_values
Ejemplo n.º 9
0
 def test_internal_state_updated(self, stub_server):
     check = NetworkBandwidth(
         'name', psutil.net_if_addrs().keys(),
         sys.float_info.max, sys.float_info.max)
     check.check()
     old_state = check._previous_values
     requests.get(stub_server.resource_address(''))
     check.check()
     assert old_state != check._previous_values
Ejemplo n.º 10
0
 def test_create_error(self, _mock_interfaces, config, error_match) -> None:
     parser = configparser.ConfigParser()
     parser.read_string(config)
     with pytest.raises(ConfigurationError, match=error_match):
         NetworkBandwidth.create("name", parser["section"])
Ejemplo n.º 11
0
 def test_smoke(self, serve_data_url) -> None:
     check = NetworkBandwidth("name", psutil.net_if_addrs().keys(), 0, 0)
     # make some traffic
     requests.get(serve_data_url)
     assert check.check() is not None
Ejemplo n.º 12
0
 def create_instance(self, name):
     return NetworkBandwidth(name, psutil.net_if_addrs().keys(), 0, 0)
Ejemplo n.º 13
0
 def test_create_error(self, mock_interfaces, config, error_match):
     parser = configparser.ConfigParser()
     parser.read_string(config)
     with pytest.raises(ConfigurationError, match=error_match):
         NetworkBandwidth.create('name', parser['section'])
Ejemplo n.º 14
0
 def test_smoke(self, stub_server):
     check = NetworkBandwidth(
         'name', psutil.net_if_addrs().keys(), 0, 0)
     # make some traffic
     requests.get(stub_server.resource_address(''))
     assert check.check() is not None