def test_threeTrials_multipleResultsBadCov(self, mock_print, mock_run_dig, mock_gen_stats, mock_calculate_cov): mock_run_dig.side_effect = [ dig.DigResults(answer=0, authority=4, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=4, msg_size=0, recursion_not_available=False), dig.DigResults(answer=0, authority=1, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=2, msg_size=0, recursion_not_available=False), dig.DigResults(answer=0, authority=53, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=4, msg_size=0, recursion_not_available=False) ] mock_gen_stats.side_effect = ["generated_stats_go_here"] mock_calculate_cov.side_effect = [1000] trials = 3 authoritative_reliability.test_reliability("b", "a", trials, 999) self.assertEqual(trials, mock_run_dig.call_count) mock_run_dig.assert_has_calls([call(domain="a", target_server="b")] * trials) self.assertEqual(1, mock_calculate_cov.call_count) self.assertEqual(0, mock_gen_stats.call_count) self.assertEqual(0, mock_print.call_count)
def test_threeTrials_oneResult(self, mock_print, mock_run_dig, mock_gen_stats): mock_run_dig.side_effect = [ dig.DigResults(answer=0, authority=12, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=240, msg_size=0, recursion_not_available=False), None, dig.DigResults(answer=0, authority=31, additional=0, status="NXDOMAIN", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=120, msg_size=0, recursion_not_available=False), dig.DigResults(answer=0, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=120, msg_size=0, recursion_not_available=True) ] trials = 3 authoritative_reliability.test_reliability("b", "a", trials, 999) self.assertEqual(trials, mock_run_dig.call_count) mock_run_dig.assert_has_calls([call(domain="a", target_server="b")] * trials) self.assertEqual(0, mock_gen_stats.call_count) self.assertEqual(0, mock_print.call_count)
def build_result(rtt, msg_size=0): return dig.DigResults(answer=0, authority=12, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=rtt, msg_size=msg_size, recursion_not_available=False)
def test_oneTrial(self, mock_print, mock_run_dig, mock_gen_stats): mock_run_dig.side_effect = [ dig.DigResults(answer=5, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=120, msg_size=0, recursion_not_available=False), dig.DigResults(answer=5, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=240, msg_size=0, recursion_not_available=False) ] recursive_reliability.test_reliability("b", "a", 1, 999) # Primer still runs dig_count = 2 self.assertEqual(dig_count, mock_run_dig.call_count) mock_run_dig.assert_has_calls([call(domain="a", target_server="b")] * dig_count) self.assertEqual(0, mock_gen_stats.call_count) self.assertEqual(0, mock_print.call_count)
def test_noAnswersOrAuthority(self, mock_print, mock_run_dig): mock_run_dig.side_effect = [ dig.DigResults(answer=0, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=0, msg_size=0, recursion_not_available=False) ] confirm_recursive.confirm_recursive("1.1.1.1", "cnn.com") self.assertEqual(mock_run_dig.call_count, 1) mock_run_dig.assert_has_calls( [call(domain="cnn.com", target_server="1.1.1.1")]) self.assertEqual(mock_print.call_count, 0)
def test_noTrials(self, mock_print, mock_run_dig, mock_gen_stats): mock_run_dig.side_effect = [ dig.DigResults(answer=5, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=120, msg_size=0, recursion_not_available=False) ] trials = 0 authoritative_reliability.test_reliability("a", "b", trials, 999) self.assertEqual(0, mock_run_dig.call_count) self.assertEqual(0, mock_gen_stats.call_count) self.assertEqual(0, mock_print.call_count)
def test_threeTrials_multipleResults(self, mock_print, mock_run_dig, mock_gen_stats): mock_run_dig.side_effect = [ dig.DigResults(answer=5, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=4, msg_size=0, recursion_not_available=False), dig.DigResults(answer=5, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=2, msg_size=0, recursion_not_available=False), dig.DigResults(answer=5, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=4, msg_size=0, recursion_not_available=False), dig.DigResults(answer=5, authority=0, additional=0, status="NOERROR", responding_server="", answer_section=[], authority_section=[], additional_section=[], query_time=2, msg_size=0, recursion_not_available=False) ] mock_gen_stats.side_effect = ["generated_stats_go_here"] recursive_reliability.test_reliability("b", "a", 3, 999) # Primer still runs dig_count = 4 self.assertEqual(dig_count, mock_run_dig.call_count) mock_run_dig.assert_has_calls([call(domain="a", target_server="b")] * dig_count) self.assertEqual(1, mock_gen_stats.call_count) mock_gen_stats.assert_has_calls([call([2, 4, 2])]) self.assertEqual(1, mock_print.call_count) mock_print.assert_has_calls([call("b,generated_stats_go_here")])