示例#1
0
 def setUp(self):
     self.out = StringIO()
     init_data = MonthlyFigureSetup()
     init_data.setup_forecast()
     init_data.setup_budget()
     call_command("archive")
     self.current_year = get_current_financial_year()
     call_command("archive_current_year", )
示例#2
0
class ArchiveCurrentYearTest(TestCase):
    def setUp(self):
        self.init_data = MonthlyFigureSetup()
        self.init_data.setup_forecast()
        self.init_data.setup_budget()
        call_command("archive")

    def test_archive_actuals(self):
        self.assertEqual(ArchivedFinancialCode.objects.count(), 0)
        self.assertEqual(ArchivedForecastData.objects.count(), 0)
        call_command("archive_current_year", )
        self.assertEqual(ArchivedFinancialCode.objects.count(), 1)
        self.assertEqual(ArchivedForecastData.objects.count(), 1)
        ArchivedForecastData_obj = ArchivedForecastData.objects.all().first()
        value_dict = self.init_data.value_dict
        self.assertEqual(ArchivedForecastData_obj.apr, value_dict[1])
        self.assertEqual(ArchivedForecastData_obj.may, value_dict[2])
        self.assertEqual(ArchivedForecastData_obj.jun, value_dict[3])
        self.assertEqual(ArchivedForecastData_obj.jul, value_dict[4])
        self.assertEqual(ArchivedForecastData_obj.aug, value_dict[5])
        self.assertEqual(ArchivedForecastData_obj.sep, value_dict[6])
        self.assertEqual(ArchivedForecastData_obj.oct, value_dict[7])
        self.assertEqual(ArchivedForecastData_obj.nov, value_dict[8])
        self.assertEqual(ArchivedForecastData_obj.dec, value_dict[9])
        self.assertEqual(ArchivedForecastData_obj.jan, value_dict[10])
        self.assertEqual(ArchivedForecastData_obj.feb, value_dict[11])
        self.assertEqual(ArchivedForecastData_obj.mar, value_dict[12])
        self.assertEqual(ArchivedForecastData_obj.adj1, value_dict[13])
        self.assertEqual(ArchivedForecastData_obj.adj2, value_dict[14])
        self.assertEqual(ArchivedForecastData_obj.adj3, value_dict[15])

    def test_archive_budget(self):
        self.assertEqual(ArchivedFinancialCode.objects.count(), 0)
        self.assertEqual(ArchivedForecastData.objects.count(), 0)
        call_command("archive_current_year", )
        self.assertEqual(ArchivedFinancialCode.objects.count(), 1)
        self.assertEqual(ArchivedForecastData.objects.count(), 1)
        ArchivedForecastData_obj = ArchivedForecastData.objects.all().first()
        self.assertEqual(ArchivedForecastData_obj.budget,
                         self.init_data.total_budget)
示例#3
0
class ReadArchivedBudgetTest(TestCase):
    archived_figure = []

    def setUp(self):
        self.init_data = MonthlyFigureSetup()
        self.init_data.setup_budget()
        for period in range(0, 16):
            self.archived_figure.append(0)

    def get_period_total(self, period):
        data_model = forecast_budget_view_model[period]
        tot_q = data_model.objects.all()
        return tot_q[0].budget

    def get_current_total(self):
        return self.get_period_total(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))

    # The following tests check that the archived figures are not changed by
    # changing the current figures.
    def test_read_archived_figure_apr(self):
        tested_period = 1
        self.check_archive_period(tested_period)

    def test_read_archived_figure_may(self):
        tested_period = 2
        self.test_read_archived_figure_apr()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_jun(self):
        tested_period = 3
        self.test_read_archived_figure_may()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_jul(self):
        tested_period = 4
        self.test_read_archived_figure_jun()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_aug(self):
        tested_period = 5
        self.test_read_archived_figure_jul()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_sep(self):
        tested_period = 6
        self.test_read_archived_figure_aug()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_oct(self):
        tested_period = 7
        self.test_read_archived_figure_sep()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_nov(self):
        tested_period = 8
        self.test_read_archived_figure_oct()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_dec(self):
        tested_period = 9
        self.test_read_archived_figure_nov()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_jan(self):
        tested_period = 10
        self.test_read_archived_figure_dec()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_feb(self):
        tested_period = 11
        self.test_read_archived_figure_jan()
        self.check_archive_period(tested_period)

    def test_read_archived_figure_mar(self):
        tested_period = 12
        self.test_read_archived_figure_feb()
        self.check_archive_period(tested_period)
示例#4
0
class EndOfMonthBudgetTest(TestCase):
    def setUp(self):
        self.init_data = MonthlyFigureSetup()
        self.init_data.setup_budget()

    # The following tests test_end_of_month_xxx checkes that only forecast is saved,
    # not actuals. This is tested by counting the records saved in the period tested.
    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)

    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)

    def test_end_of_month_jun(self):
        self.test_end_of_month_may()
        end_of_month_archive(3)
        count = BudgetMonthlyFigure.objects.all().count()
        self.assertEqual(count, 57)
        budget_total_count = MonthlyTotalBudget.objects.all().count()
        self.assertEqual(budget_total_count, 3)

    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)

    def test_end_of_month_aug(self):
        self.test_end_of_month_jul()
        end_of_month_archive(5)
        count = BudgetMonthlyFigure.objects.all().count()
        self.assertEqual(count, 80)
        budget_total_count = MonthlyTotalBudget.objects.all().count()
        self.assertEqual(budget_total_count, 5)

    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)

    def test_end_of_month_oct(self):
        self.test_end_of_month_sep()
        end_of_month_archive(7)
        count = BudgetMonthlyFigure.objects.all().count()
        self.assertEqual(count, 99)
        budget_total_count = MonthlyTotalBudget.objects.all().count()
        self.assertEqual(budget_total_count, 7)

    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)

    def test_end_of_month_dec(self):
        self.test_end_of_month_nov()
        end_of_month_archive(9)
        count = BudgetMonthlyFigure.objects.all().count()
        self.assertEqual(count, 114)
        budget_total_count = MonthlyTotalBudget.objects.all().count()
        self.assertEqual(budget_total_count, 9)

    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)

    def test_end_of_month_feb(self):
        self.test_end_of_month_jan()
        end_of_month_archive(11)
        count = BudgetMonthlyFigure.objects.all().count()
        self.assertEqual(count, 125)
        budget_total_count = MonthlyTotalBudget.objects.all().count()
        self.assertEqual(budget_total_count, 11)

    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)
示例#5
0
 def setUp(self):
     self.out = StringIO()
     init_data = MonthlyFigureSetup()
     init_data.setup_forecast()
     init_data.setup_budget()
     self.current_year = get_current_financial_year()