def test_success_scenario2(database): tas1 = TASFactory() tas2 = TASFactory() database.session.add_all([tas1, tas2]) database.session.flush() ap = AppropriationFactory(tas_id=tas1.tas_id, deobligations_recoveries_r_cpe=8) # Contributes 4 op_1 = ObjectClassProgramActivityFactory(tas_id=tas1.tas_id, ussgl487100_downward_adjus_cpe=1, ussgl497100_downward_adjus_cpe=1, ussgl487200_downward_adjus_cpe=1, ussgl497200_downward_adjus_cpe=1) # Contributes another 4 op_2 = ObjectClassProgramActivityFactory(tas_id=tas1.tas_id, ussgl487100_downward_adjus_cpe=1, ussgl497100_downward_adjus_cpe=1, ussgl487200_downward_adjus_cpe=1, ussgl497200_downward_adjus_cpe=1) # Doesn't contribute, different TAS op_3 = ObjectClassProgramActivityFactory(tas_id=tas2.tas_id, ussgl487100_downward_adjus_cpe=1, ussgl497100_downward_adjus_cpe=1, ussgl487200_downward_adjus_cpe=1, ussgl497200_downward_adjus_cpe=1) assert number_of_errors(_FILE, database, models=[ap, op_1, op_2, op_3]) == 0
def test_update_tas_ids_fiscal_year(database): """Fiscal year math should be accurate when checking TAS entries""" sess = database.session tas = TASFactory(internal_start_date=date(2010, 1, 1), internal_end_date=date(2010, 8, 31)) copied_fields = { # translate to a slightly different set of fields 'allocation_transfer_agency': tas.allocation_transfer_agency, 'agency_identifier': tas.agency_identifier, 'beginning_period_of_availa': tas.beginning_period_of_availability, 'ending_period_of_availabil': tas.ending_period_of_availability, 'availability_type_code': tas.availability_type_code, 'main_account_code': tas.main_account_code, 'sub_account_code': tas.sub_account_code } sf_133 = SF133Factory(fiscal_year=2011, period=1, **copied_fields) sess.add_all([tas, sf_133]) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id is None tas.internal_end_date = date(2010, 9, 30) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id is None tas.internal_end_date = date(2010, 10, 31) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id is tas.tas_id
def test_success(database): """ Test that TAS values can be found, and null matches work correctly""" tas = TASFactory() tas_null = TASFactory(allocation_transfer_agency=None, availability_type_code=None, sub_account_code=None) approp = AppropriationFactory( allocation_transfer_agency=tas.allocation_transfer_agency, agency_identifier=tas.agency_identifier, beginning_period_of_availa=tas.beginning_period_of_availability, ending_period_of_availabil=tas.ending_period_of_availability, availability_type_code=tas.availability_type_code, main_account_code=tas.main_account_code, sub_account_code=tas.sub_account_code) approp_null = AppropriationFactory( allocation_transfer_agency=tas_null.allocation_transfer_agency, agency_identifier=tas_null.agency_identifier, beginning_period_of_availa=tas_null.beginning_period_of_availability, ending_period_of_availabil=tas_null.ending_period_of_availability, availability_type_code=tas_null.availability_type_code, main_account_code=tas_null.main_account_code, sub_account_code=tas_null.sub_account_code) errors = number_of_errors(_FILE, database, models=[tas, tas_null, approp, approp_null]) assert errors == 0
def test_updateTASLookups(database, monkeypatch): sess = database.session monkeypatch.setattr( loadTas, 'cleanTas', Mock(return_value=pd.DataFrame({ 'availability_type_code': ['0', '1', '2'], 'tas_id': [111, 222, 333], 'agency_identifier': ['0', '1', '2'], 'allocation_transfer_agency': ['0', '1', '2'], 'beginning_period_of_availability': ['0', '1', '2'], 'ending_period_of_availability': ['0', '1', '2'], 'main_account_code': ['0', '1', '2'], 'sub_account_code': ['0', '1', '2'], })) ) sess.add(TASFactory(tas_id=222)) sess.add(TASFactory(tas_id=444, agency_identifier='other')) sess.commit() results = sess.query(TASLookup).order_by(TASLookup.tas_id).all() assert len(results) == 2 sess.invalidate() loadTas.updateTASLookups('file-name-ignored-due-to-mock') results = sess.query(TASLookup).order_by(TASLookup.tas_id).all() assert len(results) == 3 # there is no 444 assert results[0].tas_id == 111 assert results[0].agency_identifier == '0' assert results[1].tas_id == 222 assert results[1].agency_identifier == '1' # replaces previous value assert results[2].tas_id == 333 assert results[2].agency_identifier == '2'
def test_failure(database): """ Tests that all combinations of TAS, program activity code, and object class in File C do not exist in File B """ tas1 = TASFactory() tas2 = TASFactory() database.session.add_all([tas1, tas2]) database.session.flush() op = ObjectClassProgramActivityFactory(tas_id=tas1.tas_id, program_activity_code='1', object_class='1') af1 = AwardFinancialFactory(tas_id=tas1.tas_id, program_activity_code='1', object_class='1') af2 = AwardFinancialFactory(tas_id=tas2.tas_id, program_activity_code='1', object_class='1') af3 = AwardFinancialFactory(tas_id=tas1.tas_id, program_activity_code='2', object_class='1') af4 = AwardFinancialFactory(tas_id=tas1.tas_id, program_activity_code='1', object_class='2') assert number_of_errors(_FILE, database, models=[op, af1, af2, af3, af4]) == 3
def test_failure(database): """ Test that tas that does not match is an error""" tas = TASFactory(agency_identifier=100) tas_null = TASFactory(agency_identifier=101, allocation_transfer_agency=None, availability_type_code=None, sub_account_code=None) approp = AppropriationFactory( allocation_transfer_agency=tas.allocation_transfer_agency, agency_identifier=102, beginning_period_of_availa=tas.beginning_period_of_availability, ending_period_of_availabil=tas.ending_period_of_availability, availability_type_code=tas.availability_type_code, main_account_code=tas.main_account_code, sub_account_code=tas.sub_account_code) approp_null = AppropriationFactory( allocation_transfer_agency=tas_null.allocation_transfer_agency, agency_identifier=103, beginning_period_of_availa=tas_null.beginning_period_of_availability, ending_period_of_availabil=tas_null.ending_period_of_availability, availability_type_code=tas_null.availability_type_code, main_account_code=tas_null.main_account_code, sub_account_code=tas_null.sub_account_code) # Non-overlapping ranges of agency IDs should generate two errors errors = number_of_errors(_FILE, database, models=[tas, tas_null, approp, approp_null]) assert errors == 2
def test_only_fill_missing(database, monkeypatch): """ Verify that TAS with the same account_num can be modified, that we "close" any non-present TASes, and that we add new entries """ sess = database.session blank_tas_fields = [ 'account_title', 'budget_bureau_code', 'budget_bureau_name', 'budget_function_code', 'budget_function_title', 'budget_subfunction_code', 'budget_subfunction_title', 'reporting_agency_aid', 'reporting_agency_name' ] existing_tas_entries = [ # TAS to be filled in TASFactory(account_num=222, agency_identifier='to-close-2', **{field: None for field in blank_tas_fields}), # TAS to be untouched TASFactory(account_num=333, agency_identifier='to-close-3', **{field: 'populated-333' for field in blank_tas_fields}), ] sess.add_all(existing_tas_entries) sess.commit() incoming_tas_data = pd.DataFrame( columns=('account_num', ) + tuple(blank_tas_fields) + ('agency_identifier', ), data=[ [111] + ['populated-111'] * len(blank_tas_fields) + ['to-close-4'], [222] + ['populated-222'] * len(blank_tas_fields) + ['to-close-5'], [333] + ['populated-333'] * len(blank_tas_fields) + ['to-close-6'], ]) monkeypatch.setattr(load_tas, 'clean_tas', Mock(return_value=incoming_tas_data)) # Initial state assert sess.query(TASLookup).count() == 2 load_tas.update_tas_lookups(sess, 'file-name-ignored-due-to-mock', update_missing=[222]) # Post-"import" state results = sess.query(TASLookup).order_by(TASLookup.account_num).all() assert len(results) == 2 t222, t333 = results assert t222.account_num == 222 assert t222.agency_identifier == 'to-close-2' for tas_field in blank_tas_fields: assert getattr(t222, tas_field) == 'populated-222' assert t333.account_num == 333 assert t333.agency_identifier == 'to-close-3' for tas_field in blank_tas_fields: assert getattr(t333, tas_field) == 'populated-333'
def test_failure(database): """ Tests that TAS values in File A do not exist in File B for the same reporting period """ tas1 = TASFactory() tas2 = TASFactory() database.session.add_all([tas1, tas2]) database.session.flush() ap = AppropriationFactory(account_num=tas1.account_num) op = ObjectClassProgramActivityFactory(account_num=tas2.account_num) assert number_of_errors(_FILE, database, models=[ap, op]) == 1
def test_success(database): """ Tests that TAS values in File A are not unique """ tas1 = TASFactory() tas2 = TASFactory() database.session.add_all([tas1, tas2]) database.session.flush() ap1 = AppropriationFactory(row_number=1, tas_id=tas1.tas_id) ap2 = AppropriationFactory(row_number=2, tas_id=tas2.tas_id) assert number_of_errors(_FILE, database, models=[ap1, ap2]) == 0
def test_financing_tas(database): """ GTAS entries associated with a CARS with a "financing" financial indicator should be ignored""" cars_1 = TASFactory(financial_indicator2='other indicator') cars_2 = TASFactory(financial_indicator2=None) gtas_1 = SF133Factory(account_num=cars_1.account_num, allocation_transfer_agency=None, disaster_emergency_fund_code='N', line=3020, amount=4) gtas_2 = SF133Factory(account_num=cars_2.account_num, period=gtas_1.period, fiscal_year=gtas_1.fiscal_year, agency_identifier=gtas_1.agency_identifier, allocation_transfer_agency=None, disaster_emergency_fund_code='N', line=3020, amount=4) submission = SubmissionFactory(reporting_fiscal_period=gtas_1.period, reporting_fiscal_year=gtas_1.fiscal_year, cgac_code=gtas_1.agency_identifier, is_quarter_format=False) errors = number_of_errors(_FILE, database, models=[gtas_1, gtas_2, cars_1, cars_2], submission=submission) assert errors == 2 cars_3 = TASFactory(financial_indicator2='f') cars_4 = TASFactory(financial_indicator2='F') gtas_3 = SF133Factory(account_num=cars_3.account_num, allocation_transfer_agency=None, disaster_emergency_fund_code='N') gtas_4 = SF133Factory(account_num=cars_4.account_num, period=gtas_3.period, fiscal_year=gtas_3.fiscal_year, agency_identifier=gtas_3.agency_identifier, allocation_transfer_agency=None, disaster_emergency_fund_code='N') submission = SubmissionFactory(reporting_fiscal_period=gtas_3.period, reporting_fiscal_year=gtas_3.fiscal_year, cgac_code=gtas_3.agency_identifier, is_quarter_format=False) errors = number_of_errors(_FILE, database, models=[gtas_3, gtas_4, cars_3, cars_4], submission=submission) assert errors == 0
def test_failure_populated_011_fr_entity_cgac(database): """ Tests that TAS for SF-133 are present in File A for CGAC submissions """ submission_id = randint(1000, 10000) tas, account_num, period, year, cgac_code, frec_code = 'some-tas', 1, 2, 2002, 'some-cgac-code', 'some-frec-code' cgac = CGACFactory(cgac_code=cgac_code, cgac_id=1) frec = FRECFactory(cgac_id=cgac.cgac_id, frec_code=frec_code, frec_id=1) sf1 = SF133Factory(tas=tas, period=period, fiscal_year=year, allocation_transfer_agency=None, agency_identifier='011', account_num=account_num) ts1 = TASFactory(account_num=account_num, fr_entity_type=frec_code) submission = SubmissionFactory(submission_id=submission_id, reporting_fiscal_period=period, reporting_fiscal_year=year, cgac_code=cgac_code, frec_code=None) ap = AppropriationFactory(tas='a-different-tas', submission_id=submission_id) errors = number_of_errors(_FILE, database, models=[cgac, frec, sf1, ts1, ap], submission=submission) assert errors == 1
def test_success(database): """ Tests that all combinations of TAS, program activity code, and object class in File C exist in File B """ tas = TASFactory() database.session.add(tas) database.session.flush() op = ObjectClassProgramActivityFactory(tas_id=tas.tas_id, program_activity_code='1', object_class='1') af = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code='1', object_class='1') # Allow program activity code to be null, empty, or zero af2 = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code='', object_class='1') af3 = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code='0000', object_class='1') af4 = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code=None, object_class='1') assert number_of_errors(_FILE, database, models=[op, af, af2, af3, af4]) == 0
def test_failure(database): """ Tests that, for entries with the matching TAS, Appropriations deobligations_recoveries_r_cpe does not equals the sum of all corresponding entries for Object Class Program Acitivity fields ussgl487100_downward_adjus_cpe, ussgl497100_downward_adjus_cpe, ussgl487200_downward_adjus_cpe, ussgl497200_downward_adjus_cpe""" tas = TASFactory() database.session.add(tas) database.session.flush() ap = AppropriationFactory(tas_id=tas.tas_id, deobligations_recoveries_r_cpe=7) # Contributes 4 op_1 = ObjectClassProgramActivityFactory(tas_id=tas.tas_id, ussgl487100_downward_adjus_cpe=1, ussgl497100_downward_adjus_cpe=1, ussgl487200_downward_adjus_cpe=1, ussgl497200_downward_adjus_cpe=1) # Contributes another 4 op_2 = ObjectClassProgramActivityFactory(tas_id=tas.tas_id, ussgl487100_downward_adjus_cpe=1, ussgl497100_downward_adjus_cpe=1, ussgl487200_downward_adjus_cpe=1, ussgl497200_downward_adjus_cpe=1) assert number_of_errors(_FILE, database, models=[ap, op_1, op_2]) == 1
def test_success_ignore_optional_before_2021(database): """ Ignore AwardFinancial entries that are prior to year 2021 and are indicated by the proper PAC and PAN. """ tas = TASFactory() database.session.add(tas) database.session.flush() op = ObjectClassProgramActivityFactory(account_num=tas.account_num, program_activity_code='1', program_activity_name='PA1', object_class='1', disaster_emergency_fund_code='s') af = AwardFinancialFactory(account_num=tas.account_num, program_activity_code='1', program_activity_name='PA1', object_class='1', disaster_emergency_fund_code='s') af2 = AwardFinancialFactory( account_num=tas.account_num, program_activity_code='OPTN', program_activity_name='FIELD IS optional PRIOR TO FY21', object_class='1', disaster_emergency_fund_code='s') sub = SubmissionFactory(reporting_fiscal_year=2020) assert number_of_errors(_FILE, database, models=[op, af, af2], submission=sub) == 0
def test_financing_tas(database): """GTAS entries associated with a CARS with a "financing" financial indicator should be ignored""" cars = TASFactory() database.session.add(cars) database.session.commit() gtas = SF133Factory(tas_id=cars.tas_id) submission = SubmissionFactory( reporting_fiscal_period=gtas.period, reporting_fiscal_year=gtas.fiscal_year, cgac_code=gtas.allocation_transfer_agency ) errors = number_of_errors(_FILE, database, models=[gtas, cars], submission=submission) assert errors == 1 cars.financial_indicator2 = 'F' assert error_rows(_FILE, database, models=[gtas, cars], submission=submission) == []
def test_update_tas_ids_has_match_closed(database, factory): """If there are models which match the TAS (with an defined end date), they should be modified""" sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 10), reporting_end_date=date(2010, 10, 31)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2010, 9, 1), internal_end_date=date(2010, 10, 15)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.tas_id is None sess.add_all([tas, model]) sess.commit() validationManager.update_tas_ids(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.tas_id == tas.account_num
def test_update_tas_ids_bad_dates(database, factory): """If the relevant TAS does not overlap the date of the submission, it should not be used""" sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 1), reporting_end_date=date(2010, 10, 1)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2011, 1, 1)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.tas_id is None sess.add_all([tas, model]) sess.commit() validationManager.update_tas_ids(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.tas_id is None
def test_success(database, sql_file, factory): """If a TAS value is set, we should succeed""" tas = TASFactory() database.session.add(tas) database.session.flush() model = factory(account_num=tas.account_num) assert number_of_errors(sql_file, database, models=[tas, model]) == 0
def test_failure(database): """ Tests that all combinations of TAS, program activity code, and object class in File C do not exist in File B """ tas1 = TASFactory() tas2 = TASFactory() tas3 = TASFactory() database.session.add_all([tas1, tas2, tas3]) database.session.flush() op = ObjectClassProgramActivityFactory(tas_id=tas1.tas_id, program_activity_code='1', object_class='1') op2 = ObjectClassProgramActivityFactory(tas_id=tas2.tas_id, program_activity_code='1', object_class='2') af1 = AwardFinancialFactory(tas_id=tas3.tas_id, program_activity_code='1', object_class='1') af2 = AwardFinancialFactory(tas_id=tas1.tas_id, program_activity_code='2', object_class='1') af3 = AwardFinancialFactory(tas_id=tas1.tas_id, program_activity_code='1', object_class='2') # Should error even if object class is 0 because it doesn't match the object class of the op af4 = AwardFinancialFactory(tas_id=tas2.tas_id, program_activity_code='1', object_class='0') assert number_of_errors(_FILE, database, models=[op, op2, af1, af2, af3, af4]) == 4
def test_financial_tas_approp(database): """ Tests that TAS for File A are not present in SF-133 except when a financial account (financial indicator type F)""" tas_1 = TASFactory(financial_indicator2='other indicator') tas_2 = TASFactory(financial_indicator2=None) ap_1 = AppropriationFactory(tas_id=tas_1.account_num) ap_2 = AppropriationFactory(tas_id=tas_2.account_num) assert number_of_errors(_FILE, database, models=[tas_1, tas_2, ap_1, ap_2]) == 2 tas_3 = TASFactory(financial_indicator2='F') tas_4 = TASFactory(financial_indicator2='f') ap_3 = AppropriationFactory(tas_id=tas_3.account_num) ap_4 = AppropriationFactory(tas_id=tas_4.account_num) assert number_of_errors(_FILE, database, models=[tas_3, tas_4, ap_3, ap_4]) == 0
def test_failure(database): """ Tests that TAS values in File A are unique """ tas = TASFactory() database.session.add(tas) database.session.flush() ap1 = AppropriationFactory(row_number=1, tas_id=tas.tas_id) ap2 = AppropriationFactory(row_number=2, tas_id=tas.tas_id) assert number_of_errors(_FILE, database, models=[ap1, ap2]) == 2
def test_update_account_nums_has_match_open_ended(database, factory): """ If there are models which match the TAS (with an undefined end date), they should be modified """ sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 1), reporting_end_date=date(2010, 10, 1)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2010, 9, 1)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.account_num is None sess.add_all([tas, model]) sess.commit() validationManager.update_account_nums(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.account_num == tas.account_num
def test_sum_matches(database): tas = TASFactory() database.session.add(tas) database.session.flush() op1 = ObjectClassProgramActivityFactory(tas_id=tas.tas_id) op2 = ObjectClassProgramActivityFactory(tas_id=tas.tas_id) approp_val = -sum(op.obligations_incurred_by_pr_cpe for op in (op1, op2)) approp = AppropriationFactory(tas_id=tas.tas_id, obligations_incurred_total_cpe=approp_val) assert number_of_errors(_FILE, database, models=[approp, op1, op2]) == 0
def test_update_tas_ids_bad_dates(database, factory): """If the relevant TAS does not overlap the date of the submission, it should not be used""" sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 1), reporting_end_date=date(2010, 10, 1)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2011, 1, 1)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.tas_id is None sess.add_all([tas, model]) sess.commit() validationManager.update_tas_ids(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.tas_id is None
def test_add_start_date_fiscal_year(database, today_date, fiscal_date): """We should be calculating the correct beginning of a fiscal year""" database.session.add(TASFactory()) database.session.commit() data = pd.DataFrame({'dummy': ['data']}) with freeze_time(today_date): loadTas.add_start_date(data) assert data['internal_start_date'][0] == fiscal_date
def test_success(database): """ Tests that TAS values in File B should exist in File A for the same reporting period """ tas = TASFactory() database.session.add(tas) database.session.flush() op = ObjectClassProgramActivityFactory(account_num=tas.account_num) ap = AppropriationFactory(account_num=tas.account_num) assert number_of_errors(_FILE, database, models=[op, ap]) == 0
def test_success(database): """ Tests that all combinations of TAS, program activity code, and object class in File C exist in File B """ tas = TASFactory() tas2 = TASFactory() database.session.add_all([tas, tas2]) database.session.flush() op = ObjectClassProgramActivityFactory(tas_id=tas.tas_id, program_activity_code='1', object_class='1') op2 = ObjectClassProgramActivityFactory(tas_id=tas2.tas_id, program_activity_code='2', object_class='0') af = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code='1', object_class='1') # Allow program activity code to be null, empty, or zero af2 = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code='', object_class='1') af3 = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code='0000', object_class='1') af4 = AwardFinancialFactory(tas_id=tas.tas_id, program_activity_code=None, object_class='1') # Allow different object classes if pacs are the same and tas IDs are the same and object classes are just # different numbers of zeroes af5 = AwardFinancialFactory(tas_id=tas2.tas_id, program_activity_code='2', object_class='00') assert number_of_errors(_FILE, database, models=[op, op2, af, af2, af3, af4, af5]) == 0
def test_sum_matches(database): tas = TASFactory() database.session.add(tas) database.session.flush() op1 = ObjectClassProgramActivityFactory(tas_id=tas.tas_id) op2 = ObjectClassProgramActivityFactory(tas_id=tas.tas_id) approp_val = sum(op.gross_outlay_amount_by_pro_cpe for op in (op1, op2)) approp = AppropriationFactory(tas_id=tas.tas_id, gross_outlay_amount_by_tas_cpe=approp_val) assert number_of_errors(_FILE, database, models=[approp, op1, op2]) == 0
def test_sum_does_not_match(database): tas = TASFactory() database.session.add(tas) database.session.flush() op1 = ObjectClassProgramActivityFactory(account_num=tas.account_num) op2 = ObjectClassProgramActivityFactory(account_num=tas.account_num) approp_val = -sum(op.obligations_incurred_by_pr_cpe for op in (op1, op2)) approp_val += randint(1, 9999) # different value now approp = AppropriationFactory(account_num=tas.account_num, obligations_incurred_total_cpe=approp_val) assert number_of_errors(_FILE, database, models=[approp, op1, op2]) == 1
def test_financing_tas(database): """GTAS entries associated with a CARS with a "financing" financial indicator should be ignored""" cars = TASFactory() database.session.add(cars) database.session.commit() gtas = SF133Factory(tas_id=cars.tas_id) submission = SubmissionFactory(reporting_fiscal_period=gtas.period, reporting_fiscal_year=gtas.fiscal_year, cgac_code=gtas.allocation_transfer_agency) errors = number_of_errors(_FILE, database, models=[gtas, cars], submission=submission) assert errors == 1 cars.financial_indicator2 = 'F' assert error_rows(_FILE, database, models=[gtas, cars], submission=submission) == []
def test_update_account_nums_fiscal_year(database): """ Fiscal year math should be accurate when checking TAS entries """ sess = database.session tas = TASFactory(internal_start_date=date(2010, 1, 1), internal_end_date=date(2010, 8, 31)) sf_133 = SF133Factory(fiscal_year=2011, period=1, **tas.component_dict()) sess.add_all([tas, sf_133]) sess.commit() load_sf133.update_account_num(2011, 1) sess.refresh(sf_133) assert sf_133.account_num is None tas.internal_end_date = date(2010, 9, 30) sess.commit() load_sf133.update_account_num(2011, 1) sess.refresh(sf_133) assert sf_133.account_num is None tas.internal_end_date = date(2010, 10, 31) sess.commit() load_sf133.update_account_num(2011, 1) sess.refresh(sf_133) assert sf_133.account_num == tas.account_num
def test_update_tas_ids_fiscal_year(database): """Fiscal year math should be accurate when checking TAS entries""" sess = database.session tas = TASFactory(internal_start_date=date(2010, 1, 1), internal_end_date=date(2010, 8, 31)) sf_133 = SF133Factory(fiscal_year=2011, period=1, **tas.component_dict()) sess.add_all([tas, sf_133]) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id is None tas.internal_end_date = date(2010, 9, 30) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id is None tas.internal_end_date = date(2010, 10, 31) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id == tas.account_num
def test_sum_matches(database): """ Test the GrossOutlayAmountByTAS_CPE amount in the appropriation file (A) does not equal the sum of the corresponding GrossOutlayAmountByProgramObjectClass_CPE values in the award financial file (B). {This value is the sum of all Gross Outlay Amounts reported in file B, to indicate year-to-date activity by TAS/Subaccount.} """ tas = TASFactory() database.session.add(tas) database.session.flush() op1 = ObjectClassProgramActivityFactory(account_num=tas.account_num) op2 = ObjectClassProgramActivityFactory(account_num=tas.account_num) approp_val = sum(op.gross_outlay_amount_by_pro_cpe for op in (op1, op2)) approp = AppropriationFactory(account_num=tas.account_num, gross_outlay_amount_by_tas_cpe=approp_val) assert number_of_errors(_FILE, database, models=[approp, op1, op2]) == 0
def test_update_tas_ids_no_match(database, factory): """If a TAS doesn't share fields, we don't expect a match""" sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 10), reporting_end_date=date(2010, 10, 31)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2010, 9, 1)) # note these will have different fields model = factory(submission_id=submission.submission_id) assert model.tas_id is None sess.add_all([tas, model]) sess.commit() validationManager.update_tas_ids(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.tas_id is None