class TestOONIBReportLog(ConfigTestCase):

    def setUp(self):
        super(TestOONIBReportLog, self).setUp()
        self.measurement_id = '20160727T182604Z-ZZ-AS0-dummy'
        self.config.measurements_directory = tempfile.mkdtemp()
        self.measurement_dir = os.path.join(
            self.config.measurements_directory,
            self.measurement_id
        )
        self.report_log_path = os.path.join(self.measurement_dir,
                                            'report_log.json')
        os.mkdir(self.measurement_dir)
        self.report_log = OONIBReportLog()

    def tearDown(self):
        shutil.rmtree(self.measurement_dir)
        super(TestOONIBReportLog, self).tearDown()

    @defer.inlineCallbacks
    def test_report_created(self):
        yield self.report_log.created(self.measurement_id, {})
        with open(self.report_log_path) as f:
            report = json.load(f)
            self.assertEqual(report['status'], 'created')

    @defer.inlineCallbacks
    def test_report_closed(self):
        yield self.report_log.created(self.measurement_id, {})
        yield self.report_log.closed(self.measurement_id)

        self.assertFalse(os.path.exists(self.report_log_path))

    @defer.inlineCallbacks
    def test_report_creation_failed(self):
        yield self.report_log.creation_failed(self.measurement_id, {})
        with open(self.report_log_path) as f:
            report = json.load(f)
        self.assertEqual(report["status"], "creation-failed")

    @defer.inlineCallbacks
    def test_list_reports_in_progress(self):
        yield self.report_log.created(self.measurement_id, {})
        in_progress = yield self.report_log.get_in_progress()
        incomplete = yield self.report_log.get_incomplete()
        self.assertEqual(len(incomplete), 0)
        self.assertEqual(len(in_progress), 1)

    @defer.inlineCallbacks
    def test_list_reports_to_upload(self):
        yield self.report_log.creation_failed(self.measurement_id, {})
        incomplete = yield self.report_log.get_incomplete()
        to_upload = yield self.report_log.get_to_upload()
        self.assertEqual(len(incomplete), 0)
        self.assertEqual(len(to_upload), 1)
Example #2
0
class TestOONIBReportLog(ConfigTestCase):
    def setUp(self):
        super(TestOONIBReportLog, self).setUp()
        self.measurement_id = '20160727T182604Z-ZZ-AS0-dummy'
        self.config.measurements_directory = tempfile.mkdtemp()
        self.measurement_dir = os.path.join(self.config.measurements_directory,
                                            self.measurement_id)
        self.report_log_path = os.path.join(self.measurement_dir,
                                            'report_log.json')
        os.mkdir(self.measurement_dir)
        self.report_log = OONIBReportLog()

    def tearDown(self):
        shutil.rmtree(self.measurement_dir)
        super(TestOONIBReportLog, self).tearDown()

    @defer.inlineCallbacks
    def test_report_created(self):
        yield self.report_log.created(self.measurement_id, {})
        with open(self.report_log_path) as f:
            report = json.load(f)
            self.assertEqual(report['status'], 'created')

    @defer.inlineCallbacks
    def test_report_closed(self):
        yield self.report_log.created(self.measurement_id, {})
        yield self.report_log.closed(self.measurement_id)

        self.assertFalse(os.path.exists(self.report_log_path))

    @defer.inlineCallbacks
    def test_report_creation_failed(self):
        yield self.report_log.creation_failed(self.measurement_id, {})
        with open(self.report_log_path) as f:
            report = json.load(f)
        self.assertEqual(report["status"], "creation-failed")

    @defer.inlineCallbacks
    def test_list_reports_in_progress(self):
        yield self.report_log.created(self.measurement_id, {})
        in_progress = yield self.report_log.get_in_progress()
        incomplete = yield self.report_log.get_incomplete()
        self.assertEqual(len(incomplete), 0)
        self.assertEqual(len(in_progress), 1)

    @defer.inlineCallbacks
    def test_list_reports_to_upload(self):
        yield self.report_log.creation_failed(self.measurement_id, {})
        incomplete = yield self.report_log.get_incomplete()
        to_upload = yield self.report_log.get_to_upload()
        self.assertEqual(len(incomplete), 0)
        self.assertEqual(len(to_upload), 1)
Example #3
0
def status():
    oonib_report_log = OONIBReportLog()

    reports_to_upload = yield oonib_report_log.get_to_upload()
    print("Reports to be uploaded")
    print("----------------------")
    for report_file, value in reports_to_upload:
        print_report(report_file, value)

    reports_in_progress = yield oonib_report_log.get_in_progress()
    print("Reports in progress")
    print("-------------------")
    for report_file, value in reports_in_progress:
        print_report(report_file, value)

    reports_incomplete = yield oonib_report_log.get_incomplete()
    print("Incomplete reports")
    print("------------------")
    for report_file, value in reports_incomplete:
        print_report(report_file, value)
Example #4
0
def status():
    oonib_report_log = OONIBReportLog()

    reports_to_upload = yield oonib_report_log.get_to_upload()
    print("Reports to be uploaded")
    print("----------------------")
    for report_file, value in reports_to_upload:
        print_report(report_file, value)

    reports_in_progress = yield oonib_report_log.get_in_progress()
    print("Reports in progress")
    print("-------------------")
    for report_file, value in reports_in_progress:
        print_report(report_file, value)

    reports_incomplete = yield oonib_report_log.get_incomplete()
    print("Incomplete reports")
    print("------------------")
    for report_file, value in reports_incomplete:
        print_report(report_file, value)