예제 #1
0
 def test_end_of_month_mar(self):
     self.test_end_of_month_feb()
     end_of_month_archive(12)
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 129)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 12)
예제 #2
0
 def test_end_of_month_nov(self):
     self.test_end_of_month_oct()
     end_of_month_archive(8)
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 107)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 8)
예제 #3
0
 def test_end_of_month_jul(self):
     self.test_end_of_month_jun()
     end_of_month_archive(4)
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 69)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 4)
예제 #4
0
 def test_end_of_month_sep(self):
     self.test_end_of_month_aug()
     end_of_month_archive(6)
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 90)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 6)
예제 #5
0
 def test_end_of_month_may(self):
     self.test_end_of_month_apr()
     end_of_month_archive(2)
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 44)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 2)
예제 #6
0
 def test_end_of_month_jan(self):
     self.test_end_of_month_dec()
     end_of_month_archive(10)
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 120)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 10)
예제 #7
0
 def handle(self, *args, **options):
     try:
         period_code = options["period"]
         try:
             validate_period_code(period_code)
         except InvalidPeriodError:
             self.stdout.write(self.style.ERROR("Valid Period is between 1 and 15."))
             return
         except PeriodAlreadyArchivedError:
             self.stdout.write(
                 self.style.ERROR("The selected period has already been archived.")
             )
             return
         except LaterPeriodAlreadyArchivedError:
             self.stdout.write(
                 self.style.ERROR("A later period has already been archived.")
             )
             return
         end_of_month_archive(period_code)
         self.stdout.write(
             self.style.SUCCESS(f'Period {period_code} archived.')
         )
     except Exception as ex:
         self.stdout.write(
             self.style.ERROR(f"An error occured: {ex}")
         )
예제 #8
0
 def test_delete_latest_period(self):
     initial_forecast_count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(initial_forecast_count, 15)
     end_of_month_archive(1)
     forecast_count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(forecast_count, 30)
     delete_last_end_of_month_archive()
     forecast_count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(forecast_count, initial_forecast_count)
예제 #9
0
 def test_end_of_month_apr(self):
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 15)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 0)
     end_of_month_archive(1)
     count = BudgetMonthlyFigure.objects.all().count()
     self.assertEqual(count, 30)
     budget_total_count = MonthlyTotalBudget.objects.all().count()
     self.assertEqual(budget_total_count, 1)
예제 #10
0
파일: test_utils.py 프로젝트: uktrade/fido
 def set_archive_period(self, last_archived_period=13):
     if last_archived_period > 13:
         last_archived_period = 13
     for tested_period in range(1, last_archived_period):
         end_of_month_archive(tested_period)
         # save the full total
         self.set_period_total(tested_period)
         change_amount = tested_period * 10000
         self.monthly_figure_update(tested_period + 1, change_amount, "Forecast")
         change_amount = tested_period * 1000
         self.monthly_figure_update(tested_period + 1, change_amount, "Budget")
     self.set_period_total(0)
예제 #11
0
 def test_delete_selected_period(self):
     end_of_month_archive(1)
     initial_forecast_count = ForecastMonthlyFigure.objects.all().count()
     end_of_month_archive(2)
     end_of_month_obj = EndOfMonthStatus.objects.get(archived_period=2)
     self.assertEqual(end_of_month_obj.archived, True)
     forecast_count = ForecastMonthlyFigure.objects.all().count()
     self.assertNotEqual(forecast_count, initial_forecast_count)
     delete_end_of_month_archive(2)
     forecast_count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(forecast_count, initial_forecast_count)
     end_of_month_obj = EndOfMonthStatus.objects.get(archived_period=2)
     self.assertEqual(end_of_month_obj.archived, False)
예제 #12
0
 def check_archive_period(self, tested_period):
     total_before = self.get_current_total()
     end_of_month_archive(tested_period)
     # run a query giving the full total
     archived_total = self.get_period_total(tested_period)
     self.assertEqual(total_before, archived_total)
     change_amount = tested_period * 10000
     self.init_data.monthly_figure_update(tested_period + 1, change_amount)
     current_total = self.get_current_total()
     self.archived_figure[tested_period] = archived_total
     self.assertNotEqual(current_total, archived_total)
     self.assertEqual(current_total, (archived_total + change_amount))
     for period in range(1, tested_period + 1):
         self.assertEqual(self.archived_figure[period],
                          self.get_period_total(period))
예제 #13
0
def monthly_figures_create():
    monthly_figures_clear()
    current_financial_year = FinancialYear.objects.get(current=True)
    cost_centre_fk = CostCentre.objects.first()
    programme_list = ProgrammeCode.objects.all()
    project_list = ProjectCode.objects.all()
    natural_account_list = NaturalCode.objects.all()
    financial_periods = FinancialPeriod.objects.exclude(
        period_long_name__icontains="adj"
    )
    monthly_amount = 0
    budget_amount = 1
    # Several nested loops, to create a reasonable quantity of data.
    for project_code in project_list:
        for programme_fk in programme_list:
            monthly_amount += 10
            for natural_account_code_fk in natural_account_list:
                financial_code = FinancialCode.objects.create(
                    programme=programme_fk,
                    cost_centre=cost_centre_fk,
                    natural_account_code=natural_account_code_fk,
                    project_code=project_code,
                )
                financial_code.save()

                for period in financial_periods:
                    ForecastMonthlyFigure.objects.create(
                        financial_year=current_financial_year,
                        financial_period=period,
                        financial_code=financial_code,
                        amount=monthly_amount,
                    )
                    monthly_amount += 10
                    BudgetMonthlyFigure.objects.create(
                        financial_year=current_financial_year,
                        financial_period=period,
                        financial_code=financial_code,
                        amount=budget_amount,
                    )
                    budget_amount += 1

    for period_id in range(1, 3):
        end_of_month_archive(period_id)
        actual = FinancialPeriod.objects.get(financial_period_code=period_id)
        actual.actual_loaded = True
        actual.save()
예제 #14
0
    def check_archive_period(self, tested_period):
        total_before = self.get_current_total()
        end_of_month_archive(tested_period)
        # run a query giving the full total
        archived_total = self.get_period_total(tested_period)
        self.assertEqual(total_before, archived_total)
        change_amount = tested_period * 10000
        self.init_data.monthly_figure_update(tested_period + 1, change_amount,
                                             "budget")
        current_total = self.get_current_total()
        self.archived_figure[tested_period] = archived_total
        self.assertNotEqual(current_total, archived_total)
        self.assertNotEqual(current_total, archived_total)
        self.assertEqual(current_total, (archived_total + change_amount))

        for period in range(1, tested_period + 1):
            # Check the full total. It is saved in a different table, for convenience
            monthly_budget = MonthlyTotalBudget.objects.get(
                archived_period=period)
            self.assertEqual(self.archived_figure[period],
                             monthly_budget.amount)
            # Check that nothig has corrupted the archived figures
            self.assertEqual(self.archived_figure[period],
                             self.get_period_total(period))
예제 #15
0
 def form_valid(self, form):
     archivable_period = get_archivable_month()
     end_of_month_archive(archivable_period)
     self.period_code = archivable_period
     return super().form_valid(form)
예제 #16
0
 def test_end_of_month_oct(self):
     self.test_end_of_month_sep()
     end_of_month_archive(7)
     count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(count, 99)
예제 #17
0
 def test_end_of_month_dec(self):
     self.test_end_of_month_nov()
     end_of_month_archive(9)
     count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(count, 114)
예제 #18
0
 def test_end_of_month_jun(self):
     self.test_end_of_month_may()
     end_of_month_archive(3)
     count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(count, 57)
예제 #19
0
 def test_end_of_month_aug(self):
     self.test_end_of_month_jul()
     end_of_month_archive(5)
     count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(count, 80)
예제 #20
0
 def test_end_of_month_apr(self):
     count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(count, 15)
     end_of_month_archive(1)
     count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(count, 30)
예제 #21
0
 def test_error_early_archived_period(self):
     period = 5
     end_of_month_archive(period)
     with self.assertRaises(ArchiveMonthArchivedPastError):
         end_of_month_archive(period - 1)
예제 #22
0
 def test_end_of_month_mar(self):
     self.test_end_of_month_feb()
     end_of_month_archive(12)
     count = ForecastMonthlyFigure.objects.all().count()
     self.assertEqual(count, 129)
예제 #23
0
 def test_error_already_archived_period(self):
     period = 5
     end_of_month_archive(period)
     with self.assertRaises(ArchiveMonthAlreadyArchivedError):
         end_of_month_archive(period)
예제 #24
0
 def test_error_invalid_period(self):
     with self.assertRaises(ArchiveMonthInvalidPeriodError):
         end_of_month_archive(16)
     with self.assertRaises(ArchiveMonthInvalidPeriodError):
         end_of_month_archive(0)