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
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
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
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
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
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"])
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
def create_instance(self, name): return NetworkBandwidth(name, psutil.net_if_addrs().keys(), 0, 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'])
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