def test_db_session_always_fresh(self):
     s = db.get_session()
     try:
         r = ReportStore()
         s.add(r)
         s.commit()
         r.id = None
         s.commit()
     except:
         pass
     
     # if the session is not cleaned up properly, this will throw an exception
     s = db.get_session()
     s.execute('select 1').fetchall()
     
     s = db.get_mw_session(mediawiki_project)
     try:
         u = MediawikiUser()
         s.add(u)
         s.commit()
         u.user_id = None
         s.commit()
     except:
         pass
     
     # if the session is not cleaned up properly, this will throw an exception
     s = db.get_mw_session(mediawiki_project)
     s.execute('select 1').fetchall()
def unset_public_report(report_id):
    """
    Deletes the specified report from disk, and sets the public flag to False.
    """
    # call would throw an exception if  report cannot be made private
    ReportStore.make_report_private(report_id, current_user.id, g.file_manager)
    return json_response(message='Update successful')
示例#3
0
def unset_public_report(report_id):
    """
    Deletes the specified report from disk, and sets the public flag to False.
    """
    # call would throw an exception if  report cannot be made private
    ReportStore.make_report_private(report_id, current_user.id, g.file_manager)
    return json_response(message='Update successful')
示例#4
0
    def test_db_session_always_fresh(self):
        s = db.get_session()
        try:
            r = ReportStore()
            s.add(r)
            s.commit()
            r.id = None
            s.commit()
        except:
            pass

        # if the session is not cleaned up properly, this will throw an exception
        s = db.get_session()
        s.execute('select 1').fetchall()

        s = db.get_mw_session(mediawiki_project)
        try:
            u = MediawikiUser()
            s.add(u)
            s.commit()
            u.user_id = None
            s.commit()
        except:
            pass

        # if the session is not cleaned up properly, this will throw an exception
        s = db.get_mw_session(mediawiki_project)
        s.execute('select 1').fetchall()
示例#5
0
 def test_make_private_report(self):
     """
     Making a report private should try to delete it
     """
     file_manager = Mock(spec=PublicReportFileManager)
     report_path = file_manager.get_public_report_path(self.reports[0].id)
     ReportStore.make_report_private(self.reports[0].id,
                                     self.reports[0].user_id, file_manager)
     file_manager.remove_file.assert_called_with(report_path)
示例#6
0
 def setUp(self):
     DatabaseTest.setUp(self)
     self.reports = [
         ReportStore(public=False, recurrent=False, user_id=1),
         ReportStore(public=True, recurrent=False, user_id=1),
         ReportStore(public=False, recurrent=True, user_id=1),
         ReportStore(public=True, recurrent=True, user_id=1),
     ]
     self.session.add_all(self.reports)
     self.session.commit()
 def test_make_private_report(self):
     """
     Making a report private should try to delete it
     """
     file_manager = Mock(spec=PublicReportFileManager)
     report_path = file_manager.get_public_report_path(self.reports[0].id)
     ReportStore.make_report_private(
         self.reports[0].id, self.reports[0].user_id, file_manager
     )
     file_manager.remove_file.assert_called_with(report_path)
 def test_public_report_state_change_error(self):
     """
     Persistent Report should propagate IO errors from
     PublicReportFileManager
     """
     self.app = Mock()
     
     self.logger = Mock(spec=RootLogger)
     
     file_manager = PublicReportFileManager(self.logger, '/some/fake/absolute/path')
     file_manager.write_data = Mock(side_effect=PublicReportIOError('Boom!'))
     # do not write anything to disk
     file_manager.get_public_report_path = Mock()
     ReportStore.make_report_public(
         self.reports[0].id, self.reports[0].user_id, file_manager, 'testing data'
     )
 def test_update_another_users_reports(self):
     # updating with the wrong user_id does not work
     r = ReportStore.update_reports(
         [self.reports[1].id], 0, recurrent=True
     )
     assert_equals(r, False)
     self.session.commit()
     self.session.expire_all()
示例#10
0
    def test_public_report_state_change_error(self):
        """
        Persistent Report should propagate IO errors from
        PublicReportFileManager
        """
        self.app = Mock()

        self.logger = Mock(spec=RootLogger)

        file_manager = PublicReportFileManager(self.logger,
                                               '/some/fake/absolute/path')
        file_manager.write_data = Mock(
            side_effect=PublicReportIOError('Boom!'))
        # do not write anything to disk
        file_manager.get_public_report_path = Mock()
        ReportStore.make_report_public(self.reports[0].id,
                                       self.reports[0].user_id, file_manager,
                                       'testing data')
示例#11
0
def set_public_report(report_id):
    """
    Client facing method with pretty url to set/uset one report as public
    """

    # in order to move code to the PersistenReport class need to fetch report
    # data here
    db_session = db.get_session()
    result_key = db_session.query(ReportStore.result_key)\
        .filter(ReportStore.id == report_id)\
        .one()[0]

    data = report_result_json(result_key).data

    # call would throw an exception if report cannot be made public
    ReportStore.make_report_public(
        report_id, current_user.id, g.file_manager, data
    )

    return json_response(message='Update successful')
 def test_task_error_repr(self):
     pr = ReportStore(status=celery.states.PENDING)
     self.session.add(pr)
     self.session.commit()
     te = TaskErrorStore(task_type='report',
                         task_id=pr.id,
                         message='m',
                         traceback='t',
                         count=1)
     self.session.add(te)
     self.session.commit()
     row = self.session.query(TaskErrorStore).first()
     assert_true(str(row).find('TaskErrorStore') >= 0)
示例#13
0
    def test_update_reports_recurrent_false(self):
        r = ReportStore.update_reports(
            [self.reports[0].id, self.reports[2].id], 1, recurrent=False)
        assert_equals(r, True)
        self.session.commit()
        self.session.expire_all()

        assert_equals(self.reports[0].public, False)
        assert_equals(self.reports[1].public, True)
        assert_equals(self.reports[2].public, False)
        assert_equals(self.reports[3].public, True)
        assert_equals(self.reports[0].recurrent, False)
        assert_equals(self.reports[1].recurrent, False)
        assert_equals(self.reports[2].recurrent, False)
        assert_equals(self.reports[3].recurrent, True)
 def test_update_reports_recurrent_false(self):
     r = ReportStore.update_reports(
         [self.reports[0].id, self.reports[2].id], 1, recurrent=False
     )
     assert_equals(r, True)
     self.session.commit()
     self.session.expire_all()
     
     assert_equals(self.reports[0].public, False)
     assert_equals(self.reports[1].public, True)
     assert_equals(self.reports[2].public, False)
     assert_equals(self.reports[3].public, True)
     assert_equals(self.reports[0].recurrent, False)
     assert_equals(self.reports[1].recurrent, False)
     assert_equals(self.reports[2].recurrent, False)
     assert_equals(self.reports[3].recurrent, True)
 def test_task_error(self):
     pr = ReportStore(status=celery.states.PENDING)
     self.session.add(pr)
     self.session.commit()
     te = TaskErrorStore(task_type='report',
                         task_id=pr.id,
                         message='m',
                         traceback='t',
                         count=1)
     self.session.add(te)
     self.session.commit()
     row = self.session.query(TaskErrorStore).first()
     assert_equal(row.task_type, 'report')
     assert_equal(row.task_id, pr.id)
     assert_equal(row.message, 'm')
     assert_equal(row.traceback, 't')
     assert_equal(row.count, 1)
    def add_runs_to_report(self, index):
        p = self.p
        self.report_runs = []
        for d in range(0, self.no_more_than + 10):
            day = self.today - timedelta(days=d)
            p['metric']['start_date'] = day - timedelta(days=1)
            p['metric']['end_date'] = day
            p['recurrent'] = False
            ps = stringify(p)
            if d not in (self.missed_by_index[index]
                         ) and d < self.ago_by_index[index]:
                self.report_runs.append(
                    ReportStore(
                        recurrent_parent_id=self.reports[index].id,
                        created=day,
                        status='SUCCESS',
                        parameters=ps,
                        user_id=self.uid,
                    ))

        self.session.add_all(self.report_runs)
        self.session.commit()
示例#17
0
    def setUp(self):
        ControllerAsyncTest.setUp(self)
        # add reports just for testing
        report_created = ReportStore(user_id=self.owner_user_id,
                                     status=celery.states.PENDING,
                                     queue_result_key=None,
                                     show_in_ui=True)
        report_started = ReportStore(user_id=self.owner_user_id,
                                     status=celery.states.STARTED,
                                     queue_result_key=None,
                                     show_in_ui=True)
        report_started2 = ReportStore(user_id=self.owner_user_id,
                                      status=celery.states.STARTED,
                                      queue_result_key=None,
                                      show_in_ui=True)
        report_finished = ReportStore(user_id=self.owner_user_id,
                                      status=celery.states.SUCCESS,
                                      queue_result_key=None,
                                      show_in_ui=True)
        report_recurrent = ReportStore(user_id=self.owner_user_id,
                                       status=celery.states.SUCCESS,
                                       queue_result_key=None,
                                       show_in_ui=True,
                                       recurrent=True)
        self.past_date = date.today() - timedelta(days=60)

        report_recurrent_two_months_ago = ReportStore(
            user_id=self.owner_user_id,
            status=celery.states.SUCCESS,
            queue_result_key=None,
            show_in_ui=True,
            created=self.past_date,
            recurrent=True)
        self.session.add_all([
            report_created,
            report_started,
            report_started2,
            report_finished,
            report_recurrent,
            report_recurrent_two_months_ago,
        ])
        self.session.commit()
 def test_report(self):
     pr = ReportStore(status=celery.states.PENDING)
     self.session.add(pr)
     self.session.commit()
     row = self.session.query(ReportStore).get(pr.id)
     assert_equal(row.status, celery.states.PENDING)
 def test_report_repr(self):
     pr = ReportStore(status=celery.states.PENDING)
     self.session.add(pr)
     self.session.commit()
     row = self.session.query(ReportStore).get(pr.id)
     assert_true(str(row).find('ReportStore') >= 0)
    def setUp(self):
        DatabaseTest.setUp(self)

        # turn off the scheduler for this test
        self.save_schedule = queue.conf['CELERYBEAT_SCHEDULE']
        queue.conf['CELERYBEAT_SCHEDULE'] = {}

        self.common_cohort_1()
        self.uid = self.owner_user_id
        self.today = strip_time(datetime.today())
        # NOTE: running with 20 just makes the tests run faster, but any value > 11 works
        self.no_more_than = 20
        self.missed_by_index = {
            0: [1, 2, 11],
            1: [1, 2, 11, self.no_more_than + 1, self.no_more_than + 3],
            2: [1, 2],
            3: range(0, self.no_more_than + 10),
        }
        self.ago_by_index = {
            0: 26,
            1: self.no_more_than + 10,
            2: 6,
            3: self.no_more_than + 10
        }
        age = {
            i: self.today - timedelta(days=v - 1)
            for i, v in self.ago_by_index.items()
        }

        self.p = {
            'metric': {
                'start_date': age[0],
                'end_date': self.today,
                'name': 'NamespaceEdits',
            },
            'recurrent': True,
            'cohort': {
                'id': self.cohort.id,
                'name': self.cohort.name
            },
            'name': 'test-recurrent-reports',
        }
        ps = stringify(self.p)

        self.reports = [
            ReportStore(recurrent=True,
                        created=age[0],
                        parameters=ps,
                        user_id=self.uid),
            ReportStore(recurrent=True,
                        created=age[1],
                        parameters=ps,
                        user_id=self.uid),
            ReportStore(recurrent=True,
                        created=age[2],
                        parameters=ps,
                        user_id=self.uid),
            ReportStore(recurrent=True,
                        created=age[3],
                        parameters=ps,
                        user_id=self.uid),
        ]
        self.session.add_all(self.reports)
        self.session.commit()
示例#21
0
 def test_update_another_users_reports(self):
     # updating with the wrong user_id does not work
     r = ReportStore.update_reports([self.reports[1].id], 0, recurrent=True)
     assert_equals(r, False)
     self.session.commit()
     self.session.expire_all()
 def setUp(self):
     DatabaseTest.setUp(self)
     self.report = ReportStore(status=celery.states.PENDING)
     self.session.add(self.report)
     self.session.commit()
示例#23
0
 def test_get_celery_task_result_when_empty(self):
     mock_report = ReportStore()
     failure = mock_report.get_result_safely('')
     assert_equal(failure['failure'], 'result not available')
 def test_get_celery_task_result_when_empty(self):
     mock_report = ReportStore()
     failure = mock_report.get_result_safely('')
     assert_equal(failure['failure'], 'result not available')