Пример #1
0
    def setUp(self):
        self.client.force_login(self.test_user)
        self.test_year = 2019
        self.test_period = 9

        self.file_mock = MagicMock(spec=File)
        self.file_mock.name = 'test.txt'

        self.cost_centre_code = TEST_COST_CENTRE
        self.cost_centre_code_1 = 888888
        self.valid_natural_account_code = TEST_VALID_NATURAL_ACCOUNT_CODE
        self.not_valid_natural_account_code = TEST_NOT_VALID_NATURAL_ACCOUNT_CODE
        self.programme_code = TEST_PROGRAMME_CODE
        self.test_amount = 100
        self.directorate_obj = DirectorateFactory.create(
            directorate_code="T123")
        CostCentreFactory.create(cost_centre_code=self.cost_centre_code,
                                 directorate=self.directorate_obj)
        CostCentreFactory.create(cost_centre_code=self.cost_centre_code_1,
                                 directorate=self.directorate_obj)

        NaturalCodeFactory.create(
            natural_account_code=self.valid_natural_account_code,
            used_for_budget=True)
        NaturalCodeFactory.create(
            natural_account_code=self.not_valid_natural_account_code)
        ProgrammeCodeFactory.create(programme_code=self.programme_code)

        ProgrammeCodeFactory.create(programme_code="333333")

        self.year_obj = FinancialYear.objects.get(financial_year=2019)
Пример #2
0
 def setUp(self):
     self.client.force_login(self.test_user)
     self.test_year = 2019
     self.test_period = 9
     self.cost_centre_code = "109189"
     self.natural_account_code = 52191003
     self.programme_code = "310940"
     self.project_code = "0123"
     self.analisys1 = "00798"
     self.analisys2 = "00321"
     self.test_amount = 100
     self.directorate_obj = DirectorateFactory.create(
         directorate_code="T123")
     CostCentreFactory.create(cost_centre_code=self.cost_centre_code,
                              directorate=self.directorate_obj)
     NaturalCodeFactory.create(
         natural_account_code=self.natural_account_code,
         economic_budget_code="CAPITAL",
     )
     ProgrammeCodeFactory.create(programme_code=self.programme_code)
     ProjectCodeFactory.create(project_code=self.project_code)
     Analysis1Factory.create(analysis1_code=self.analisys1)
     Analysis2Factory.create(analysis2_code=self.analisys2)
     self.year_obj = FinancialYear.objects.get(financial_year=2019)
     self.year_obj.current = True
     self.year_obj.save
Пример #3
0
    def test_data_returned_in_response(self):
        self.current_code = "123456"
        ProgrammeCodeFactory.create(programme_code=self.current_code)
        self.archived_code = HistoricalProgrammeCodeFactory.create(
            financial_year_id=2019).programme_code

        self.url_name = "data_lake_programme_code"

        self.row_lenght = 4
        self.code_position = 0
        self.check_data()
Пример #4
0
    def __init__(self):
        group_name = "Test Group"
        self.group_code = "TestGG"
        directorate_name = "Test Directorate"
        self.directorate_code = "TestDD"
        self.cost_centre_code = 109076

        group_obj = DepartmentalGroupFactory(
            group_code=self.group_code, group_name=group_name,
        )
        directorate_obj = DirectorateFactory(
            directorate_code=self.directorate_code,
            directorate_name=directorate_name,
            group=group_obj,
        )
        cost_centre_obj = CostCentreFactory(
            directorate=directorate_obj, cost_centre_code=self.cost_centre_code,
        )
        current_year = get_current_financial_year()
        programme_obj = ProgrammeCodeFactory()
        self.programme_code = programme_obj.programme_code
        nac_obj = NaturalCodeFactory(economic_budget_code="RESOURCE")
        self.nac = nac_obj.natural_account_code
        project_obj = ProjectCodeFactory()
        self.project_code = project_obj.project_code
        self.year_obj = FinancialYear.objects.get(financial_year=current_year)

        self.financial_code_obj = FinancialCode.objects.create(
            programme=programme_obj,
            cost_centre=cost_centre_obj,
            natural_account_code=nac_obj,
            project_code=project_obj,
        )
        self.financial_code_obj.save
Пример #5
0
    def setUp(self):
        self.client.force_login(self.test_user)

        self.cost_centre_code = 109076
        cost_centre = CostCentreFactory(
            cost_centre_code=self.cost_centre_code, )
        current_year = get_current_financial_year()
        self.amount_apr = -9876543
        programme_obj = ProgrammeCodeFactory()
        self.programme_code = programme_obj.programme_code
        treasury_l5 = L5AccountFactory()
        nac_obj = NaturalCodeFactory(account_L5_code=treasury_l5)
        self.nac = nac_obj.natural_account_code
        project_obj = ProjectCodeFactory()
        self.project_code = project_obj.project_code
        year_obj = FinancialYear.objects.get(financial_year=current_year)

        apr_period = FinancialPeriod.objects.get(financial_period_code=1)
        apr_period.actual_loaded = True
        apr_period.save()

        # If you use the MonthlyFigureFactory the test fails.
        # I cannot work out why, it may be due to using a random year....
        financial_code_obj = FinancialCode.objects.create(
            programme=programme_obj,
            cost_centre=cost_centre,
            natural_account_code=nac_obj,
            project_code=project_obj,
        )
        financial_code_obj.save
        apr_figure = ForecastMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(
                financial_period_code=1),
            financial_code=financial_code_obj,
            financial_year=year_obj,
            amount=self.amount_apr,
        )
        apr_figure.save
        self.amount_may = 1234567
        may_figure = ForecastMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(
                financial_period_code=2, ),
            amount=self.amount_may,
            financial_code=financial_code_obj,
            financial_year=year_obj,
        )
        may_figure.save
        # Assign download  permission
        can_view_forecasts = Permission.objects.get(
            codename="can_download_mi_reports")
        self.test_user.user_permissions.add(can_view_forecasts)
        self.test_user.save()

        self.year_total = self.amount_apr + self.amount_may
Пример #6
0
    def setUp(self):
        self.client.force_login(self.test_user)
        self.cost_centre_code = 109076
        cost_centre = CostCentreFactory(cost_centre_code=self.cost_centre_code,)
        current_year = get_current_financial_year()
        self.amount_apr = -234567
        self.amount_may = 345216
        self.programme_obj = ProgrammeCodeFactory()
        nac_obj = NaturalCodeFactory()
        project_obj = ProjectCodeFactory()
        self.programme_code = project_obj.project_code
        year_obj = FinancialYear.objects.get(financial_year=current_year)

        # If you use the MonthlyFigureFactory the test fails.
        # I cannot work out why, it may be due to using a random year....
        financial_code_obj = FinancialCode.objects.create(
            programme=self.programme_obj,
            cost_centre=cost_centre,
            natural_account_code=nac_obj,
            project_code=project_obj,
        )
        financial_code_obj.save
        apr_figure = BudgetMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(financial_period_code=1),
            financial_code=financial_code_obj,
            financial_year=year_obj,
            amount=self.amount_apr,
        )
        apr_figure.save

        may_figure = BudgetMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(financial_period_code=2,),
            amount=self.amount_may,
            financial_code=financial_code_obj,
            financial_year=year_obj,
        )
        may_figure.save

        financial_code_obj1 = FinancialCode.objects.create(
            programme=self.programme_obj,
            cost_centre=cost_centre,
            natural_account_code=nac_obj,
        )

        may_figure1 = BudgetMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(financial_period_code=2,),
            amount=self.amount_may,
            financial_code=financial_code_obj1,
            financial_year=year_obj,
        )
        may_figure1.save

        self.year_total = self.amount_apr + self.amount_may
Пример #7
0
    def setUp(self):
        self.client.force_login(self.test_user)
        self.out = StringIO()

        obj = ProgrammeCodeFactory()
        self.programme_code = obj.programme_code
        self.programme_description = obj.programme_description
        self.budget_type = obj.budget_type.budget_type
        current_year = get_current_financial_year()
        self.archive_year = current_year - 1
        current_year = get_current_financial_year()
        self.archive_year = current_year - 1
Пример #8
0
    def setUp(self):
        self.nac_code = 999999
        self.cost_centre_code = 888812
        self.analysis_1_code = "1111111"
        self.analysis_2_code = "2222222"
        self.project_code = "3000"

        self.programme = ProgrammeCodeFactory.create()
        self.cost_centre = NaturalCodeFactory.create(
            natural_account_code=self.nac_code, )
        self.project = ProjectCodeFactory.create(
            project_code=self.project_code, )
        CostCentreFactory.create(cost_centre_code=self.cost_centre_code)
        self.analysis_1 = Analysis1Factory.create(
            analysis1_code=self.analysis_1_code, )
        self.analysis_2 = Analysis2Factory.create(
            analysis2_code=self.analysis_2_code, )
Пример #9
0
    def setUp(self):
        self.client.force_login(self.test_user)
        self.test_year = 2019
        make_financial_year_current(self.test_year)
        self.test_period = 9

        self.cost_centre_code = TEST_COST_CENTRE
        self.valid_natural_account_code = TEST_VALID_NATURAL_ACCOUNT_CODE
        self.not_valid_natural_account_code = TEST_NOT_VALID_NATURAL_ACCOUNT_CODE
        self.programme_code = TEST_PROGRAMME_CODE
        self.test_amount = 100
        self.directorate_obj = DirectorateFactory.create(
            directorate_code='T123')
        CostCentreFactory.create(
            cost_centre_code=self.cost_centre_code,
            directorate=self.directorate_obj,
            active=False,
        )
        NaturalCodeFactory.create(
            natural_account_code=self.valid_natural_account_code,
            economic_budget_code=VALID_ECONOMIC_CODE_LIST[0],
            active=False,
        )
        NaturalCodeFactory.create(
            natural_account_code=18162001,
            economic_budget_code=VALID_ECONOMIC_CODE_LIST[0],
            active=False,
        )
        NaturalCodeFactory.create(
            natural_account_code=self.not_valid_natural_account_code,
            active=False,
        )
        ProgrammeCodeFactory.create(
            programme_code=self.programme_code,
            active=False,
        )
        ProgrammeCodeFactory.create(programme_code='310540')
        ProgrammeCodeFactory.create(programme_code='310530')

        self.period_obj = FinancialPeriod.objects.get(
            period_calendar_code=self.test_period)
        self.year_obj = FinancialYear.objects.get(financial_year=2019)
        dummy_upload = FileUpload(
            s3_document_file='dummy.csv',
            uploading_user=self.test_user,
            document_type=FileUpload.ACTUALS,
        )
        dummy_upload.save()
        self.check_financial_code = CheckFinancialCode(dummy_upload)
Пример #10
0
    def setUp(self):
        self.client.force_login(self.test_user)
        self.group_name = "Test Group"
        self.group_code = "TestGG"
        self.directorate_name = "Test Directorate"
        self.directorate_code = "TestDD"
        self.cost_centre_code = 109076

        self.group = DepartmentalGroupFactory(
            group_code=self.group_code,
            group_name=self.group_name,
        )
        self.directorate = DirectorateFactory(
            directorate_code=self.directorate_code,
            directorate_name=self.directorate_name,
            group=self.group,
        )
        self.cost_centre = CostCentreFactory(
            directorate=self.directorate,
            cost_centre_code=self.cost_centre_code,
        )
        current_year = get_current_financial_year()
        self.amount_apr = -9876543
        self.programme_obj = ProgrammeCodeFactory()
        nac_obj = NaturalCodeFactory()
        self.project_obj = ProjectCodeFactory()
        year_obj = FinancialYear.objects.get(financial_year=current_year)

        apr_period = FinancialPeriod.objects.get(financial_period_code=1)
        apr_period.actual_loaded = True
        apr_period.save()

        # If you use the MonthlyFigureFactory the test fails.
        # I cannot work out why, it may be due to using a random year....
        financial_code_obj = FinancialCode.objects.create(
            programme=self.programme_obj,
            cost_centre=self.cost_centre,
            natural_account_code=nac_obj,
            project_code=self.project_obj
        )
        financial_code_obj.save
        apr_figure = ForecastMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(
                financial_period_code=1
            ),
            financial_code=financial_code_obj,
            financial_year=year_obj,
            amount=self.amount_apr
        )
        apr_figure.save
        self.amount_may = 1234567
        may_figure = ForecastMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(
                financial_period_code=2,
            ),
            amount=self.amount_may,
            financial_code=financial_code_obj,
            financial_year=year_obj
        )
        may_figure.save
        # Assign forecast view permission
        can_view_forecasts = Permission.objects.get(
            codename='can_view_forecasts'
        )
        self.test_user.user_permissions.add(can_view_forecasts)
        self.test_user.save()

        self.budget = create_budget(financial_code_obj, year_obj)
        self.year_total = self.amount_apr + self.amount_may
        self.underspend_total = self.budget - self.amount_apr - self.amount_may
        self.spend_to_date_total = self.amount_apr
Пример #11
0
    def setUp(self):
        self.client.force_login(self.test_user)
        self.group_name = "Test Group"
        self.group_code = "TestGG"
        self.directorate_name = "Test Directorate"
        self.directorate_code = "TestDD"
        self.cost_centre_code = 109076

        self.group = DepartmentalGroupFactory(
            group_code=self.group_code,
            group_name=self.group_name,
        )
        self.directorate = DirectorateFactory(
            directorate_code=self.directorate_code,
            directorate_name=self.directorate_name,
            group=self.group,
        )
        self.cost_centre = CostCentreFactory(
            directorate=self.directorate,
            cost_centre_code=self.cost_centre_code,
        )
        current_year = get_current_financial_year()
        self.amount_apr = -9876543

        programme_obj = ProgrammeCodeFactory()
        self.budget_type = programme_obj.budget_type.budget_type_display
        expenditure_obj = ExpenditureCategoryFactory()
        self.expenditure_id = expenditure_obj.id
        self.nac_obj = NaturalCodeFactory(natural_account_code=12345678,
                                          expenditure_category=expenditure_obj,
                                          economic_budget_code='RESOURCE')
        year_obj = FinancialYear.objects.get(financial_year=current_year)

        apr_period = FinancialPeriod.objects.get(financial_period_code=1)
        apr_period.actual_loaded = True
        apr_period.save()

        project_obj = ProjectCodeFactory(project_code=1234)
        self.project_code = project_obj.project_code
        # If you use the MonthlyFigureFactory the test fails.
        # I cannot work out why, it may be due to using a random year....
        financial_code1_obj = FinancialCode.objects.create(
            programme=programme_obj,
            cost_centre=self.cost_centre,
            natural_account_code=self.nac_obj,
            project_code=project_obj)
        financial_code1_obj.save
        self.expenditure_type = \
            financial_code1_obj.forecast_expenditure_type.forecast_expenditure_type_name
        apr_figure = ForecastMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(
                financial_period_code=1),
            financial_code=financial_code1_obj,
            financial_year=year_obj,
            amount=self.amount_apr,
        )
        apr_figure.save

        self.amount_may = 1234567
        may_figure = ForecastMonthlyFigure.objects.create(
            financial_period=FinancialPeriod.objects.get(
                financial_period_code=4),
            financial_code=financial_code1_obj,
            financial_year=year_obj,
            amount=self.amount_may)
        may_figure.save

        # Assign forecast view permission
        can_view_forecasts = Permission.objects.get(
            codename='can_view_forecasts')
        self.test_user.user_permissions.add(can_view_forecasts)
        self.test_user.save()

        # Bust permissions cache (refresh_from_db does not work)
        self.test_user, _ = get_user_model().objects.get_or_create(
            email="*****@*****.**")

        self.year_total = self.amount_apr + self.amount_may
        self.underspend_total = -self.amount_apr - self.amount_may
        self.spend_to_date_total = self.amount_apr
Пример #12
0
def set_up_test_objects(context):
    # Clear forecast data cache
    cache.clear()

    nac_codes = [111111, 999999]
    analysis_1_code = "1111111"
    analysis_2_code = "2222222"
    project_code_value = "3000"

    financial_year = FinancialYear.objects.first()

    if not financial_year:
        FinancialYearFactory()

    if BudgetType.objects.count() == 0:
        BudgetType.objects.create(
            budget_type_key="DEL",
            budget_type="Programme DEL",
        )
        BudgetType.objects.create(
            budget_type_key="AME",
            budget_type="Programme AME",
        )
        BudgetType.objects.create(
            budget_type_key="ADMIN",
            budget_type="Admin",
        )

    CostCentreFactory.create(cost_centre_code=TEST_COST_CENTRE_CODE, )

    programme = ProgrammeCodeFactory.create()
    project_code = ProjectCodeFactory.create(project_code=project_code_value)
    analysis_1 = Analysis1Factory.create(analysis1_code=analysis_1_code)
    analysis_2 = Analysis2Factory.create(analysis2_code=analysis_2_code)

    for nac_code in nac_codes:
        nac_code = NaturalCodeFactory.create(natural_account_code=nac_code, )
        for financial_period in range(1, 14):
            financial_month = financial_period + 3

            if financial_month > 12:
                financial_month = financial_month - 12

            month_name = (financial_period,
                          datetime.date(get_current_financial_year(),
                                        financial_month, 1).strftime('%B'))[1]

            financial_period_count = FinancialPeriod.objects.filter(
                financial_period_code=financial_period).count()

            if financial_period_count == 0:
                FinancialPeriodFactory(financial_period_code=financial_period,
                                       period_long_name=month_name,
                                       period_short_name=month_name[0:3],
                                       period_calendar_code=financial_month)

            financial_code = FinancialCode.objects.filter(
                cost_centre_id=TEST_COST_CENTRE_CODE,
                programme=programme,
                natural_account_code=nac_code,
                analysis1_code=analysis_1,
                analysis2_code=analysis_2,
                project_code=project_code,
            ).first()

            if not financial_code:
                financial_code = FinancialCode.objects.create(
                    cost_centre_id=TEST_COST_CENTRE_CODE,
                    programme=programme,
                    natural_account_code=nac_code,
                    analysis1_code=analysis_1,
                    analysis2_code=analysis_2,
                    project_code=project_code,
                )

            ForecastMonthlyFigure.objects.create(
                financial_year_id=get_current_financial_year(),
                financial_period_id=financial_period,
                financial_code=financial_code,
                amount=0,
            )

    if ForecastEditState.objects.count() == 0:
        ForecastEditStateFactory.create()