def test_setup_local_options_in_test_cases(self): options = {'subargs':dummyArgs, 'test':StringIO(net_test_string)} ntl = NetTestLoader(options) ntl.checkOptions() for test_class, test_method in ntl.testCases: self.assertEqual(test_class.localOptions, dummyOptions)
def test_singular_input_processor(self): """ Verify that all measurements use the same object as their input processor. """ ntl = NetTestLoader(dummyArgs) ntl.loadNetTestString(generator_id_net_test) ntl.checkOptions() director = Director() self.filename = 'dummy_report.yamloo' d = director.startNetTest(ntl, self.filename) @d.addCallback def complete(result): with open(self.filename) as report_file: all_report_entries = yaml.safe_load_all(report_file) header = all_report_entries.next() results_case_a = all_report_entries.next() aa_test, ab_test, ac_test = results_case_a.get('results', []) results_case_b = all_report_entries.next() ba_test = results_case_b.get('results', [])[0] # Within a NetTestCase an inputs object will be consistent self.assertEqual(aa_test, ab_test, ac_test) # An inputs object will be different between different NetTestCases self.assertNotEqual(aa_test, ba_test) return d
def test_load_net_test_multiple(self): ntl = NetTestLoader(dummyArgs) ntl.loadNetTestString(double_net_test_string) self.verifyMethods(ntl.testCases) self.verifyClasses(ntl.testCases, set(('DummyTestCaseA', 'DummyTestCaseB'))) ntl.checkOptions()
def test_setup_local_options_in_test_cases(self): ntl = NetTestLoader(dummyArgs) ntl.loadNetTestString(net_test_string) ntl.checkOptions() for test_class, test_method in ntl.testCases: self.assertEqual(test_class.localOptions, dummyOptions)
def test_load_with_invalid_option(self): try: ntl = NetTestLoader(dummyInvalidArgs) ntl.loadNetTestString(net_test_string) ntl.checkOptions() raise Exception except UsageError: pass
def test_load_with_invalid_option(self): options = {'subargs':dummyInvalidArgs, 'test':StringIO(net_test_string)} try: ntl = NetTestLoader(options) ntl.checkOptions() raise Exception except UsageError: pass
def test_net_test_inputs(self): ntl = NetTestLoader(dummyArgsWithFile) ntl.loadNetTestString(net_test_string_with_file) ntl.checkOptions() nt = NetTest(ntl.getTestCases(), ntl.getTestDetails(), None) yield nt.initialize() for test_class, test_methods in nt.testCases: self.assertEqual(len(list(test_class.inputs)), 10)
def test_generate_measurements_size(self): ntl = NetTestLoader(dummyArgsWithFile) ntl.loadNetTestString(net_test_string_with_file) ntl.checkOptions() net_test = NetTest(ntl, None) measurements = list(net_test.generateMeasurements()) self.assertEqual(len(measurements), 20)
def test_generate_measurements_size(self): ntl = NetTestLoader(dummyArgsWithFile) ntl.loadNetTestString(net_test_string_with_file) ntl.checkOptions() net_test = NetTest(ntl.getTestCases(), ntl.getTestDetails(), None) net_test.initializeInputProcessor() measurements = list(net_test.generateMeasurements()) self.assertEqual(len(measurements), 20)
def test_generate_measurements_size(self): options = {'subargs':dummyArgsWithFile, 'test':StringIO(net_test_string_with_file)} ntl = NetTestLoader(options) ntl.checkOptions() net_test = NetTest(ntl, None) measurements = list(net_test.generateMeasurements()) self.assertEqual(len(measurements), 20)
def test_start_net_test(self): options = {'test':net_test_string, 'subargs':dummyArgs} net_test_loader = NetTestLoader(options) net_test_loader.checkOptions() d = self.director.startNetTest('', net_test_loader, self.reporters) @d.addCallback def done(result): self.assertEqual(self.director.successfulMeasurements, 20) return d
def test_net_test_inputs(self): ntl = NetTestLoader(dummyArgsWithFile) ntl.loadNetTestString(net_test_string_with_file) ntl.checkOptions() nt = NetTest(ntl.getTestCases(), ntl.getTestDetails(), None) nt.initializeInputProcessor() # XXX: if you use the same test_class twice you will have consumed all # of its inputs! tested = set([]) for test_instance, test_method, inputs in nt.testInstances: self.assertEqual(len(list(inputs)), 10)
def test_net_test_inputs(self): ntl = NetTestLoader(dummyArgsWithFile) ntl.loadNetTestString(net_test_string_with_file) ntl.checkOptions() # XXX: if you use the same test_class twice you will have consumed all # of its inputs! tested = set([]) for test_class, test_method in ntl.testCases: if test_class not in tested: tested.update([test_class]) self.assertEqual(len(list(test_class.inputs)), 10)
def _load_ooni(self, task_data): required_keys = ["test_name"] for required_key in required_keys: if required_key not in task_data: raise MissingTaskDataKey(required_key) self.ooni['test_name'] = task_data.pop('test_name') # This raises e.NetTestNotFound, we let it go onto the caller nettest_path = nettest_to_path(self.ooni['test_name'], self._arbitrary_paths) annotations = self._pop_option('annotations', task_data, {}) collector_address = self._pop_option('collector', task_data, None) try: self.output_path = self.global_options['reportfile'] except KeyError: self.output_path = task_data.pop('reportfile', None) if task_data.get('no-collector', False): collector_address = None elif config.reports.upload is False: collector_address = None net_test_loader = NetTestLoader( options_to_args(task_data), annotations=annotations, test_file=nettest_path ) if isinstance(collector_address, dict): net_test_loader.collector = CollectorClient( settings=collector_address ) elif collector_address is not None: net_test_loader.collector = CollectorClient( collector_address ) if (net_test_loader.collector is not None and net_test_loader.collector.backend_type == "onion"): self.requires_tor = True try: net_test_loader.checkOptions() if net_test_loader.requiresTor: self.requires_tor = True except e.MissingTestHelper: self.requires_bouncer = True self.ooni['net_test_loader'] = net_test_loader
def test_nettest_timeout(self): ntl = NetTestLoader(('-u', 'http://localhost:8007/')) ntl.loadNetTestString(http_net_test) ntl.checkOptions() director = Director() d = director.startNetTest(ntl, [MockReporter()]) @d.addCallback def complete(result): assert director.failedMeasurements == 1 return d
def test_net_test_completed_callback(self): ntl = NetTestLoader(dummyArgsWithFile) ntl.loadNetTestString(net_test_string_with_file) ntl.checkOptions() director = Director() d = director.startNetTest(ntl, [MockReporter()]) @d.addCallback def complete(result): self.assertEqual(result, None) self.assertEqual(director.successfulMeasurements, 20) return d
def test_nettest_timeout(self): ntl = NetTestLoader(('-u', 'http://localhost:8007/')) ntl.loadNetTestString(http_net_test) ntl.checkOptions() director = Director() self.filename = 'dummy_report.yamloo' d = director.start_net_test_loader(ntl, self.filename) @d.addCallback def complete(result): assert director.failedMeasurements == 1 return d
def test_net_test_completed_callback(self): options = {'subargs':dummyArgsWithFile, 'test':StringIO(net_test_string_with_file)} ntl = NetTestLoader(options) ntl.checkOptions() director = Director() d = director.startNetTest('', ntl, [MockReporter()]) @d.addCallback def complete(result): #XXX: why is the return type (True, None) ? self.assertEqual(result, [(True,None)]) self.assertEqual(director.successfulMeasurements, 20) return d
def loadDeck(self, deckFile): with open(deckFile) as f: self.deckHash = sha256(f.read()) f.seek(0) test_deck = yaml.safe_load(f) for test in test_deck: try: nettest_path = nettest_to_path(test['options']['test_file']) except e.NetTestNotFound: log.err("Could not find %s" % test['options']['test_file']) log.msg("Skipping...") continue net_test_loader = NetTestLoader(test['options']['subargs'], test_file=nettest_path) #XXX: If the deck specifies the collector, we use the specified collector # And it should also specify the test helper address to use # net_test_loader.collector = test['options']['collector'] net_test_loader.checkOptions() self.netTestLoaders.append(net_test_loader)
def test_send_to_inputs_generator(self): """ Verify that a net test can send information back into an inputs generator. """ ntl = NetTestLoader(dummyArgs) ntl.loadNetTestString(generator_net_test) ntl.checkOptions() director = Director() self.filename = 'dummy_report.njson' d = director.start_net_test_loader(ntl, self.filename) @d.addCallback def complete(result): with open(self.filename) as report_file: all_report_entries = map(json.loads, report_file) results = [x['input'] for x in all_report_entries] self.assertEqual(results, [9, 8, 7, 6, 5, 5, 3, 2, 1, 0]) return d
def test_setup_local_options_in_test_cases(self): ntl = NetTestLoader(dummyArgs) ntl.loadNetTestString(net_test_string) ntl.checkOptions() self.assertEqual(dict(ntl.localOptions), dummyOptions)
def test_load_net_test_multiple(self): ntl = NetTestLoader(dummyArgs) ntl.loadNetTestString(double_net_test_string) test_cases = ntl.getTestCases() self.verifyMethods(test_cases) ntl.checkOptions()