def time_elapsed(self): """Verifies the time elapsed is presented correctly""" self.assertEqual( executor.Response(None, 1).time_elapsed_ms, 1000, 'Bad ms representation for 1 second') self.assertEqual( executor.Response(None, 0.001).time_elapsed_ms, 1, 'Bad ms representation for 1 ms') self.assertEqual( executor.Response(None, 0.01).time_elapsed_ms, 10, 'Bad ms representation for 10 ms')
def responses_from_times(times): """Generates a list of empty responses from a list of time elapsed :param times: List of time elapsed for each response :type times: list :return: List of responses :rtype: executor.ResponseList""" return executor.ResponseList([executor.Response(None, _) for _ in times])
def craft_response_of_type(response_type): """Generates an executor.Response from an icmp.Types :param response_type: Type of response :type response_type: Union[icmp.Type, tuple] :return: The crafted response :rtype: executor.Response""" return executor.Response(executor.Message('', icmp.ICMP(response_type), '127.0.0.1'), 0.1)
def test_success(self): """Verifies the if the Response can indicate a success to a request correctly""" self.assertTrue(self.craft_response_of_type(icmp.Types.EchoReply).success, 'Unable to validate a successful response') self.assertFalse(self.craft_response_of_type(icmp.Types.DestinationUnreachable).success, 'Unable to validate Destination Unreachable') self.assertFalse(self.craft_response_of_type(icmp.Types.BadIPHeader).success, 'Unable to validate Bad IP Header') self.assertFalse(executor.Response(None, 0.1).success, 'Unable to validate timeout (no payload)')
def test_error_message(self): """Verifies error messages are presented correctly""" self.assertEqual(self.craft_response_of_type(icmp.Types.EchoReply).error_message, None, 'Generated error message when response was correct') self.assertEqual(self.craft_response_of_type(icmp.Types.DestinationUnreachable).error_message, 'Network Unreachable', 'Unable to classify a Network Unreachable error correctly') self.assertEqual(executor.Response(None, 0.1).error_message, 'No response', 'Unable to generate correct message when response is not received') pass