def test__get_data__network_error(mocker): """ Test "_get_data" method must exit with network error. """ out = StringIO() mocker.patch("sys.argv", ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634"]) mocker.patch("telnetlib.Telnet.read_all", side_effect=socket.error) mocker.patch("telnetlib.Telnet.read_all", side_effect=EOFError) checker = CheckHDDTemp() with pytest.raises(SystemExit): with contextlib2.redirect_stdout(out): checker._get_data() assert ( # nosec: B101 "ERROR: Server communication problem" in out.getvalue().strip())
def test__get_data(mocker): """ Test "_get_data" method must return data from server. """ expected = "|/dev/sda|HARD DRIVE|27|C|" mocker.patch("sys.argv", ["check_hddtemp.py", "-s", "127.0.0.1", "-p", "7634"]) mocker.patch("telnetlib.Telnet.open") mocker.patch( "telnetlib.Telnet.read_all", lambda data: b"|/dev/sda|HARD DRIVE|27|C|", ) checker = CheckHDDTemp() result = checker._get_data() assert result == expected # nosec: B101