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)
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
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)
def setUp(self): self.client.force_login(self.test_user) self.out = StringIO() self.group_name = "Test Group" self.group_code = "TestGG" self.directorate_name = "Test Directorate" self.directorate_code = "TestDD" self.cost_centre_code = 109076 group = DepartmentalGroupFactory( group_code=self.group_code, group_name=self.group_name, ) directorate = DirectorateFactory( directorate_code=self.directorate_code, directorate_name=self.directorate_name, group=group, ) CostCentreFactory( directorate=directorate, cost_centre_code=self.cost_centre_code, ) current_year = get_current_financial_year() self.archive_year = current_year - 1
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
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, )
def test_hierarchy_data_returned_in_response(self): self.current_code = CostCentreFactory.create().cost_centre_code self.archived_code = ArchivedCostCentreFactory.create( financial_year_id=2019).cost_centre_code self.url_name = "data_lake_hierachy" self.row_lenght = 11 self.code_position = 4 self.check_data()
def setUp(self): test_cost_centre = 888812 self.test_user, _ = get_user_model().objects.get_or_create( email="*****@*****.**" ) self.cost_centre = CostCentreFactory.create( cost_centre_code=test_cost_centre )
def test_user_cannot_download_wrong_forecast(self): """ User can't access download URL if they do not have editing permission for certain Cost Centre """ # Assigns user to one cost centre assign_perm("change_costcentre", self.test_user, self.cost_centre) # Changes cost_centre_code to one that user can view but NOT edit test_cost_centre_code = 888332 CostCentreFactory.create(cost_centre_code=test_cost_centre_code) download_forecast_url = self.client.get( reverse( "export_edit_forecast_data_cost_centre", kwargs={"cost_centre": test_cost_centre_code}, )) self.assertEqual(download_forecast_url.status_code, 302)
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
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
def setUp(self): self.out = StringIO() self.cost_centre_code = 888812 self.test_user_email = "*****@*****.**" self.test_password = "******" self.cost_centre = CostCentreFactory.create( cost_centre_code=self.cost_centre_code) self.test_user, _ = get_user_model().objects.get_or_create( email=self.test_user_email) self.test_user.set_password(self.test_password) self.test_user.save()
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.financial_year = FinancialYearFactory(financial_year=2019) self.name = "Test" self.surname = "FBP" self.bsce_email = "*****@*****.**" 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.business_partner = FinanceBusinessPartnerFactory( name=self.name, surname=self.surname, ) self.bsce = BSCEFactory(bsce_email=self.bsce_email) self.cost_centre = CostCentreFactory( directorate=self.directorate, cost_centre_code=self.cost_centre_code, business_partner=self.business_partner, bsce_email=self.bsce, ) self.archive_cost_centre = ArchivedCostCentreFactory( financial_year=self.financial_year, cost_centre_code=self.cost_centre_code, ) current_year = get_current_financial_year() self.archive_year = current_year - 1
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
def test_upload_trial_balance_report(self): # Check that BadZipFile is raised on # supply of incorrect file format bad_file_type_upload = FileUpload( s3_document_file=os.path.join( os.path.dirname(__file__), 'test_assets/bad_file_type.csv', ), uploading_user=self.test_user, document_type=FileUpload.ACTUALS, ) bad_file_type_upload.save() with self.assertRaises(BadZipFile): upload_trial_balance_report( bad_file_type_upload, self.test_period, self.test_year, ) bad_title_file_upload = FileUpload( s3_document_file=os.path.join( os.path.dirname(__file__), 'test_assets/bad_title_upload_test.xlsx', ), uploading_user=self.test_user, document_type=FileUpload.ACTUALS, ) bad_title_file_upload.save() with self.assertRaises(UploadFileFormatError): upload_trial_balance_report( bad_title_file_upload, self.test_period, self.test_year, ) self.assertEqual( FinancialCode.objects.filter( cost_centre=self.cost_centre_code).count(), 0, ) cost_centre_code_1 = 888888 CostCentreFactory.create(cost_centre_code=cost_centre_code_1, directorate=self.directorate_obj) # Prepare to upload data. Create some data that will be deleted save_trial_balance_row( '3000-30000-{}-{}-{}-00000-00000-0000-0000-0000'.format( cost_centre_code_1, self.valid_natural_account_code, self.programme_code), self.test_amount, self.period_obj, self.year_obj, self.check_financial_code, 2) self.assertEqual( ForecastMonthlyFigure.objects.filter( financial_code__cost_centre=cost_centre_code_1, ).count(), 0, ) self.assertEqual( ActualUploadMonthlyFigure.objects.filter( financial_code__cost_centre=cost_centre_code_1, ).count(), 1, ) copy_current_year_actuals_to_monthly_figure(self.period_obj, self.test_year) self.assertEqual( ForecastMonthlyFigure.objects.filter( financial_code__cost_centre=cost_centre_code_1, ).count(), 1, ) self.assertEqual( ActualUploadMonthlyFigure.objects.filter( financial_code__cost_centre=cost_centre_code_1, ).count(), 0, ) self.assertFalse( FinancialPeriod.objects.get( period_calendar_code=self.test_period).actual_loaded) bad_file_upload = FileUpload( s3_document_file=os.path.join( os.path.dirname(__file__), 'test_assets/upload_bad_data.xlsx', ), uploading_user=self.test_user, document_type=FileUpload.ACTUALS, ) bad_file_upload.save() upload_trial_balance_report( bad_file_upload, self.test_period, self.test_year, ) self.assertFalse( FinancialPeriod.objects.get( period_calendar_code=self.test_period, ).actual_loaded) self.assertEqual( ForecastMonthlyFigure.objects.filter( financial_code__cost_centre=cost_centre_code_1).count(), 1, ) good_file_upload = FileUpload( s3_document_file=os.path.join( os.path.dirname(__file__), 'test_assets/upload_test.xlsx', ), uploading_user=self.test_user, document_type=FileUpload.ACTUALS, ) good_file_upload.save() upload_trial_balance_report( good_file_upload, self.test_period, self.test_year, ) # Check that existing figures for the same period have been deleted self.assertEqual( ForecastMonthlyFigure.objects.filter( financial_code__cost_centre=cost_centre_code_1).count(), 0, ) # Check for existence of monthly figures self.assertEqual( ForecastMonthlyFigure.objects.filter( financial_code__cost_centre=self.cost_centre_code).count(), 4, ) result = ForecastMonthlyFigure.objects.filter( financial_code__cost_centre=self.cost_centre_code).aggregate( total=Sum('amount')) # Check that figures have correct values self.assertEqual( result['total'], 1000000, ) self.assertTrue( FinancialPeriod.objects.get( period_calendar_code=self.test_period).actual_loaded)
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()
def setUp(self): self.cost_centre_code = 888332 self.cost_centre = CostCentreFactory.create( cost_centre_code=self.cost_centre_code) self.forecast_edit_state = ForecastEditState.objects.get()
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