def test_get_measures_to_print(self): measures_to_print_expected = """+-------------+""" \ """-------------+------+"""\ """---------+-----------+ | destination | ip | port | time ms | condition | +-------------+-------------+------+---------+-----------+ | hemlo.com | 127.0.0.1 | 123 | 0.05 | Open | | google.com | 192.168.0.2 | 443 | 0.05 | Open | | meow.org | 192.167.2.1 | 123 | - | Closed | +-------------+-------------+------+---------+-----------+""" measures_with_dest = [] single_stat = ping.StatisticsData(0.050, ip='127.0.0.1', port=123), "hemlo.com" measures_with_dest.append(single_stat) single_stat = ping.StatisticsData(0.050, ip='192.168.0.2', port=443), "google.com" measures_with_dest.append(single_stat) single_stat = ping.StatisticsData(-1, ip='192.167.2.1', port=123), "meow.org" measures_with_dest.append(single_stat) measures_to_print = watchdog_ping \ .WatchdogPingData \ .get_measures_to_print(measures_with_dest) self.assertEqual(measures_to_print_expected, measures_to_print.__str__())
def test_statistics_some_failed(self): expected = "Statistic tcping for [127.0.0.1:123]:\n" \ "Pings count: 4, Successful: 2, Failed: 2\n" \ "Fails percentage: 50.0\n" \ "Max time: 50.0ms, Min time: 50.0ms, Average time 50.0ms\n" measures = [] single_stat = ping.StatisticsData(0.050, ip='127.0.0.1', port=123) measures.append(single_stat) single_stat = ping.StatisticsData(0.050, ip='127.0.0.1', port=123) measures.append(single_stat) single_stat = ping.StatisticsData(-1, ip='127.0.0.1', port=123) measures.append(single_stat) single_stat = ping.StatisticsData(-1, ip='127.0.0.1', port=123) measures.append(single_stat) statstics = statistics.Statistics(measures, '127.0.0.1', '123') self.assertEqual(expected, statstics.__str__())
def test_min_max(self): measures_with_dest = [] single_stat = ping.StatisticsData(0.050, ip='127.0.0.1', port=123), "hemlo.com" measures_with_dest.append(single_stat) single_stat = ping.StatisticsData(0.059, ip='192.168.0.2', port=443), "google.com" measures_with_dest.append(single_stat) single_stat = ping.StatisticsData(-1, ip='192.167.2.1', port=123), "meow.org" measures_with_dest.append(single_stat) max, min = watchdog_ping.WatchdogPingData \ .get_max_and_min_time(measures_with_dest) self.assertEqual(max, 0.059) self.assertEqual(min, -1)
def test_prepare_ping_info_if_failed(self): expected = "From: [127.0.0.1:123]; Failed;" single_stat = ping.StatisticsData(-1, ip='127.0.0.1', port=123) ping_info = str(single_stat) self.assertEqual(expected, ping_info)
def test_prepare_ping_info(self): expected = "From: [127.0.0.1:123]; Time: 51.0ms;" single_stat = ping.StatisticsData(0.051, ip='127.0.0.1', port=123) ping_info = str(single_stat) self.assertEqual(expected, ping_info)
def test_statistics_data_if_failed(self): single_stat = ping.StatisticsData(-1, ip='127.0.0.1', port=123) self.assertEqual(single_stat.is_failed, True)
def test_statistics_data_have_meta(self): single_stat = ping.StatisticsData(0.051, ip='127.0.0.1', port=123) self.assertEqual(single_stat, 0.051) self.assertEqual(single_stat.ip, '127.0.0.1') self.assertEqual(single_stat.port, 123) self.assertEqual(single_stat.is_failed, False)
def test_statistics_data_is_float(self): single_stat = ping.StatisticsData(0.051, ip='127.0.0.1', port=123) self.assertEqual(single_stat, 0.051)