示例#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 ArchiveCurrentYearErrorTest(TestCase):
    def setUp(self):
        self.init_data = MonthlyFigureSetup()
        self.init_data.setup_forecast()

    def test_command_error(self):
        with self.assertRaises(CommandError):
            call_command("archive_current_year", )

    def test_error_no_archived_chart_of_account(self):
        with self.assertRaises(ArchiveYearError):
            archive_current_year()
示例#3
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)
示例#4
0
class DeleteEndOfMonthArchiveTest(TestCase):
    def setUp(self):
        self.init_data = MonthlyFigureSetup()
        self.init_data.setup_forecast()

    def test_error_invalid_period(self):
        with self.assertRaises(DeleteNonExistingArchiveError):
            delete_last_end_of_month_archive()
        with self.assertRaises(ArchiveMonthInvalidPeriodError):
            delete_end_of_month_archive(0)
        with self.assertRaises(DeleteNonExistingArchiveError):
            delete_end_of_month_archive(1)

    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)

    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)
示例#5
0
class EndOfMonthForecastTest(TestCase):
    def setUp(self):
        self.init_data = MonthlyFigureSetup()
        self.init_data.setup_forecast()

    def test_error_invalid_period(self):
        with self.assertRaises(ArchiveMonthInvalidPeriodError):
            end_of_month_archive(16)
        with self.assertRaises(ArchiveMonthInvalidPeriodError):
            end_of_month_archive(0)

    def test_error_already_archived_period(self):
        period = 5
        end_of_month_archive(period)
        with self.assertRaises(ArchiveMonthAlreadyArchivedError):
            end_of_month_archive(period)

    def test_error_early_archived_period(self):
        period = 5
        end_of_month_archive(period)
        with self.assertRaises(ArchiveMonthArchivedPastError):
            end_of_month_archive(period - 1)

    # 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 = ForecastMonthlyFigure.objects.all().count()
        self.assertEqual(count, 15)
        end_of_month_archive(1)
        count = ForecastMonthlyFigure.objects.all().count()
        self.assertEqual(count, 30)

    def test_end_of_month_may(self):
        self.test_end_of_month_apr()
        end_of_month_archive(2)
        count = ForecastMonthlyFigure.objects.all().count()
        self.assertEqual(count, 44)

    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)

    def test_end_of_month_jul(self):
        self.test_end_of_month_jun()
        end_of_month_archive(4)
        count = ForecastMonthlyFigure.objects.all().count()
        self.assertEqual(count, 69)

    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)

    def test_end_of_month_sep(self):
        self.test_end_of_month_aug()
        end_of_month_archive(6)
        count = ForecastMonthlyFigure.objects.all().count()
        self.assertEqual(count, 90)

    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)

    def test_end_of_month_nov(self):
        self.test_end_of_month_oct()
        end_of_month_archive(8)
        count = ForecastMonthlyFigure.objects.all().count()
        self.assertEqual(count, 107)

    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)

    def test_end_of_month_jan(self):
        self.test_end_of_month_dec()
        end_of_month_archive(10)
        count = ForecastMonthlyFigure.objects.all().count()
        self.assertEqual(count, 120)

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

    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)
示例#6
0
class ReadArchivedForecastTest(TestCase):
    archived_figure = []

    def setUp(self):
        self.init_data = MonthlyFigureSetup()
        self.init_data.setup_forecast()
        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.annotate(
            total=F("apr") + F("may") + F("jun") + F("jul") + F("aug") +
            F("sep") + F("oct") + F("nov") + F("dec") + F("jan") + F("feb") +
            F("mar") + F("adj1") + F("adj2") + F("adj3"))
        return tot_q[0].total

    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)
        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))

    # 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)
示例#7
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()