class TestPinger(TestCase): def setUp(self): aws_client = AwsClient() aws_client.upload_result = Mock() _ttl = 74 self.Destination = "1.3.5.6" self.Pinger = Pinger(self.Destination, _ttl, aws_client) def tearDown(self): self.Pinger = None def _buildResult(self, successful=True, round_trip_time=100.01, ttl=34): return PingResult(successful=successful, round_trip_time=round_trip_time, ttl=ttl) def _build_queue(self): _queue = list() # Middle _queue.append(self._buildResult(True, 100.001, 34)) # Bad ping _queue.append(self._buildResult(False, 100.01, 78)) # Max _queue.append(self._buildResult(True, 301.951, 1)) # Min _queue.append(self._buildResult(True, 50.245, 42)) # Middle _queue.append(self._buildResult(True, 100.397, 5)) # Successful Total = 552.594 # Successful Average = 138.1485 return _queue def test_summarize_cleared(self): self.Pinger.QueuedPingResults = self._build_queue() self.Pinger._summarize() self.assertEqual(self.Pinger.QueuedPingResults.__len__(), 0) def test_summarize_tallied(self): self.Pinger.QueuedPingResults = self._build_queue() self.Pinger._summarize() self.Pinger.AwsClient.upload_result.assert_called_with(552.594, 138.149, 4, 50.245, 301.951, 1, self.Destination) def test_format_results_failed(self): _result = self.Pinger._format_results(None, None) self.assertFalse(_result.Successful)
def main(): """ Main Runner Starter :return: """ from networkMonitor import AwsClient, Pinger _aws_client = AwsClient() _pinger = Pinger("8.8.8.8", 50, _aws_client, timeout=2, size=56) _pinger.start_pinger() input('Press any key to stop... ') _pinger.stop_pinger()
def setUp(self): aws_client = AwsClient() aws_client.upload_result = Mock() _ttl = 74 self.Destination = "1.3.5.6" self.Pinger = Pinger(self.Destination, _ttl, aws_client)