Ejemplo n.º 1
0
def runTestCases(test_cases, options, cmd_line_options):
    log.debug("Running %s" % test_cases)
    log.debug("Options %s" % options)
    log.debug("cmd_line_options %s" % dict(cmd_line_options))

    test_inputs = options['inputs']

    oonib_reporter = OONIBReporter(cmd_line_options)
    yaml_reporter = YAMLReporter(cmd_line_options)

    if cmd_line_options['collector']:
        log.msg("Using remote collector, please be patient while we create the report.")
        try:
            yield oonib_reporter.createReport(options)
        except OONIBReportError:
            log.err("Error in creating new report")
            log.msg("We will only create reports to a file")
            oonib_reporter = None
    else:
        oonib_reporter = None

    yield yaml_reporter.createReport(options)
    log.msg("Reporting to file %s" % yaml_reporter._stream.name)

    try:
        input_unit_factory = InputUnitFactory(test_inputs)
        input_unit_factory.inputUnitSize = int(cmd_line_options['parallelism'])
    except Exception, e:
        log.exception(e)
Ejemplo n.º 2
0
 def test_write_yaml_report_after_close(self):
     r = YAMLReporter(self.testDetails)
     r.createReport()
     r.finish()
     def f(r):
         r.writeReportEntry("foo")
     r.created.addCallback(f)
     self.assertFailure(r.created, ReportAlreadyClosed)
Ejemplo n.º 3
0
 def test_write_report(self):
     y_reporter = YAMLReporter(test_details, 'dummy-report.yaml')
     y_reporter.createReport()
     with open(y_reporter.report_path) as f:
         self.filename = y_reporter.report_path
         report_entries = yaml.safe_load_all(f)
         # Check for keys in header
         entry = report_entries.next()
         assert all(x in entry for x in ['test_name', 'test_version'])
Ejemplo n.º 4
0
 def test_write_report(self):
     y_reporter = YAMLReporter(test_details, 'dummy-report.yaml')
     y_reporter.createReport()
     with open(y_reporter.report_path) as f:
         self.filename = y_reporter.report_path
         report_entries = yaml.safe_load_all(f)
         # Check for keys in header
         entry = report_entries.next()
         assert all(x in entry for x in ['test_name', 'test_version'])
Ejemplo n.º 5
0
 def test_open_yaml_report_and_succeed(self):
     r = YAMLReporter(self.testDetails)
     r.createReport()
     # verify that testDetails was written to report properly
     def f(r):
         r._stream.seek(0)
         details, = yaml.safe_load_all(r._stream)
         self.assertEqual(details, self.testDetails)
     r.created.addCallback(f)
     return r.created
Ejemplo n.º 6
0
 def _write_dummy_report(self, filename):
     from ooni.reporter import YAMLReporter
     from .test_reporter import test_details
     reporter = YAMLReporter(test_details, filename)
     reporter.createReport()
     reporter.writeReportEntry({"spam": "ham"})
     reporter.finish()
Ejemplo n.º 7
0
    def test_write_yaml_report_entry(self):
        r = YAMLReporter(self.testDetails)
        r.createReport()

        report_entry = {'foo':'bar', 'bin':'baz'}
        r.writeReportEntry(report_entry)

        # verify that details and entry were written to report
        def f(r):
            r._stream.seek(0)
            report = yaml.safe_load_all(r._stream)
            details, entry  = report
            self.assertEqual(details, self.testDetails)
            self.assertEqual(entry, report_entry)
        r.created.addCallback(f)
        return r.created
Ejemplo n.º 8
0
 def test_write_multiple_yaml_report_entry(self):
     r = YAMLReporter(self.testDetails)
     r.createReport()
     def reportEntry():
         for x in xrange(10):
             yield {'foo':'bar', 'bin':'baz', 'item':x}
     for entry in reportEntry():
         r.writeReportEntry(entry)
     # verify that details and multiple entries were written to report
     def f(r):
         r._stream.seek(0)
         report = yaml.safe_load_all(r._stream)
         details = report.next()
         self.assertEqual(details, self.testDetails)
         self.assertEqual([r for r in report], [r for r in reportEntry()])
     r.created.addCallback(f)
     return r.created
Ejemplo n.º 9
0
    def test_write_report(self):
        test = MockTest()

        y_reporter = YAMLReporter(test_details)
        y_reporter.createReport()
        y_reporter.testDone(test, 'spam')
        with open(y_reporter.report_path) as f:
            report_entries = yaml.safe_load_all(f)
            # Check for keys in header
            entry = report_entries.next()
            assert all(x in entry for x in ['test_name', 'test_version'])

            entry = report_entries.next()
            # Check for first entry of report
            assert all(x in entry \
                       for x in ['report_content', 'input', \
                                 'test_name', 'test_started', \
                                 'test_runtime'])
Ejemplo n.º 10
0
def runTestCases(test_cases, options, cmd_line_options):
    log.debug("Running %s" % test_cases)
    log.debug("Options %s" % options)
    log.debug("cmd_line_options %s" % dict(cmd_line_options))

    test_inputs = options['inputs']

    # Set a default reporter
    if not cmd_line_options['collector'] and not \
        cmd_line_options['no-default-reporter']:
        with open('collector') as f:
            reporter_url = random.choice(f.readlines())
            reporter_url = reporter_url.split('#')[0].strip()
            cmd_line_options['collector'] = reporter_url

    oonib_reporter = OONIBReporter(cmd_line_options)
    yaml_reporter = YAMLReporter(cmd_line_options)

    if cmd_line_options['collector']:
        log.msg("Using remote collector, please be patient while we create the report.")
        try:
            yield oonib_reporter.createReport(options)
        except OONIBReportError:
            log.err("Error in creating new report")
            log.msg("We will only create reports to a file")
            oonib_reporter = None
    else:
        oonib_reporter = None

    yield yaml_reporter.createReport(options)
    log.msg("Reporting to file %s" % yaml_reporter._stream.name)

    try:
        input_unit_factory = InputUnitFactory(test_inputs)
        input_unit_factory.inputUnitSize = int(cmd_line_options['parallelism'])
    except Exception, e:
        log.exception(e)
Ejemplo n.º 11
0
    def post_director_start(_):
        for net_test_loader in test_list:
            collector = global_options['collector']
            test_details = net_test_loader.testDetails

            yaml_reporter = YAMLReporter(test_details)
            reporters = [yaml_reporter]

            if collector and collector.startswith('httpo') \
                    and (not (config.tor_state or config.tor.socks_port)):
                raise errors.TorNotRunning
            elif collector:
                log.msg("Reporting using collector: %s" % collector)
                try:
                    oonib_reporter = OONIBReporter(test_details, collector)
                    reporters.append(oonib_reporter)
                except errors.InvalidOONIBCollectorAddress, e:
                    raise e

            log.debug("adding callback for startNetTest")
            d.addCallback(director.startNetTest, net_test_loader, reporters)
Ejemplo n.º 12
0
def get_reporters(net_test_loader):
    """
    Determines which reports are able to run and returns an instance of them.

    We always report to flat file via the :class:`ooni.reporters.YAMLReporter`
    and the :class:`ooni.reporters.OONIBReporter`.

    The later will be used only if we determine that Tor is running.

    Returns:
        a list of reporter instances
    """
    test_details = net_test_loader.testDetails
    reporters = []
    yaml_reporter = YAMLReporter(test_details, config.reports_directory)
    reporters.append(yaml_reporter)

    if config.reports.collector and collector_supported(config.reports.collector):
        oonib_reporter = OONIBReporter(test_details, config.reports.collector)
        reporters.append(oonib_reporter)
    return reporters
Ejemplo n.º 13
0
 def test_close_yaml_report(self):
     r = YAMLReporter(self.testDetails)
     r.createReport()
     r.finish()
     self.assertTrue(r._stream.closed)