コード例 #1
0
 def get_or_create_report(self):
     try:
         report = Report.get(Report.submission == self)
     except NoResultFound:
         return Report(submission=self)
     else:
         return report
コード例 #2
0
    def test_leachete_report_creation(self):
        self.setup_test_data()
        count = Report.count()
        leachete_register = LeacheteMonthlyRegister.all()[0]
        leachete_register.status = Submission.APPROVED

        self.assertEqual(Report.count(), count + 1)
コード例 #3
0
    def test_create_or_update_report(self):
        self.setup_test_data()
        report_count = Report.count()
        windrow_monitor = WindrowMonitoring.all()[0]

        windrow_monitor.status = Submission.APPROVED

        self.assertEqual(Report.count(), report_count + 1)
コード例 #4
0
    def test_consumption_report_not_created_for_first_report(self):
        count = Report.count()
        electricity_register = DBSession\
            .query(ElectricityRegister)\
            .filter(ElectricityRegister.date == '2014-04-01')\
            .one()

        electricity_register.status = Submission.APPROVED

        self.assertEqual(Report.count(), count)
コード例 #5
0
    def populate_daily_waste_reports(self):
        # approve some daily wastes to have data to aggregate on
        num_reports = Report.count()
        daily_wastes = self.get_pending_submissions_by_class(DailyWaste).all()

        for daily_waste in daily_wastes:
            daily_waste.status = Submission.APPROVED

        # check that we've incremented num reports buy number of approved
        # submissions
        self.assertEqual(Report.count(), num_reports + len(daily_wastes))

        return daily_wastes
コード例 #6
0
    def test_delete_report(self):
        submission = Submission.newest()
        submission_id = submission.id
        report = Report(submission=submission, report_json={'key': 'value'})
        with transaction.manager:
            DBSession.add(report)
        num_reports = Report.count(Report.submission_id == submission_id)
        self.assertEqual(num_reports, 1)

        submission = Submission.get(Submission.id == submission_id)
        submission.delete_report()
        self.assertEqual(Report.count(Report.submission_id == submission_id),
                         num_reports - 1)
コード例 #7
0
 def test_get_or_create_report_returns_existing_report_if_one_exist(self):
     submission = Submission.newest()
     submission_id = submission.id
     report = Report(submission=submission, report_json={'key': 'value'})
     with transaction.manager:
         DBSession.add(report)
     submission = Submission.get(Submission.id == submission_id)
     report = submission.get_or_create_report()
     self.assertTrue(instance_state(report).persistent)
コード例 #8
0
    def test_consumption_report_creation(self):
        count = Report.count()
        electricity_register = ElectricityRegister.newest()
        electricity_register.status = Submission.APPROVED

        self.assertEqual(Report.count(), count + 1)
コード例 #9
0
 def delete_report(self):
     return Report.delete(Report.submission_id == self.id)