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_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_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_success(database): """ Test that a four digit object class with no flag is a success, and a three digit object class with a flag is a success""" # Create a 12 character random piid piid = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for i in range(12)) piid_two = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for i in range(12)) piid_three = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for i in range(12)) first_piid_row_one = AwardFinancialFactory(transaction_obligated_amou = 1100, piid = piid, allocation_transfer_agency = None) first_piid_row_two = AwardFinancialFactory(transaction_obligated_amou = 11, piid = piid, allocation_transfer_agency = None) # And add a row for a different piid second_piid_row_one = AwardFinancialFactory(transaction_obligated_amou = 9999, piid = piid_two, allocation_transfer_agency = None) third_piid_row_one = AwardFinancialFactory(transaction_obligated_amou = 8888, piid = piid_three, allocation_transfer_agency = 123) third_piid_row_two = AwardFinancialFactory(transaction_obligated_amou = 8888, piid = piid_three, allocation_transfer_agency = None) first_ap_row = AwardProcurementFactory(piid = piid, federal_action_obligation = -1100) second_ap_row = AwardProcurementFactory(piid = piid, federal_action_obligation = -10) third_ap_row = AwardProcurementFactory(piid = piid, federal_action_obligation = -1) second_piid_ap_row = AwardProcurementFactory(piid = piid_two, federal_action_obligation = -9999) third_piid_ap_row = AwardProcurementFactory(piid = piid_three, federal_action_obligation = -9999) errors = number_of_errors(_FILE, database, models=[first_piid_row_one, first_piid_row_two, second_piid_row_one, third_piid_row_one, first_ap_row, second_ap_row, third_ap_row, second_piid_ap_row, third_piid_ap_row, third_piid_row_two]) assert errors == 0
def test_failure(database): """ Test fail Prior to FY22, if the DisasterEmergencyFundCode element has a valid COVID-19 related code and the row is a balance row, then GrossOutlayAmountByAward_CPE cannot be blank. Beginning in FY22, if the row is a balance row, then GrossOutlayAmountByAward_CPE cannot be blank. """ op1 = AwardFinancialFactory(disaster_emergency_fund_code='p', transaction_obligated_amou=None, gross_outlay_amount_by_awa_cpe=None) defc1 = DEFCFactory(code='P', group='covid_19') errors = number_of_errors(_FILE, database, models=[op1, defc1]) assert errors == 1 # Testing for a submission after 2022 sub = SubmissionFactory(submission_id=4, reporting_fiscal_period=9, reporting_fiscal_year=2022, cgac_code='TEST', frec_code=None) op1 = AwardFinancialFactory(disaster_emergency_fund_code='t', transaction_obligated_amou=None, gross_outlay_amount_by_awa_cpe=None, submission_id=4) errors = number_of_errors(_FILE, database, models=[op1], submission=sub) assert errors == 1
def test_success(database): """ Unique PIID, ParentAwardId from file C exists in file D1 during the same reporting period. """ af = AwardFinancialFactory(piid='some_piid', parent_award_id='some_parent_award_id') ap = AwardProcurementFactory(piid='some_piid', parent_award_id='some_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 0 af = AwardFinancialFactory(piid='some_piid', parent_award_id='some_parent_award_id') ap_1 = AwardProcurementFactory(piid='some_piid', parent_award_id='some_parent_award_id') ap_2 = AwardProcurementFactory(piid='some_piid', parent_award_id='some_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap_1, ap_2]) == 0 af = AwardFinancialFactory(piid=None, parent_award_id='some_parent_award_id') ap = AwardProcurementFactory(piid='some_piid', parent_award_id='some_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 0 af = AwardFinancialFactory(piid='some_piid', parent_award_id=None) ap = AwardProcurementFactory(piid='some_piid', parent_award_id=None) assert number_of_errors(_FILE, database, models=[af, ap]) == 0
def test_failure(database): """ Test failure for each unique combination of PIID/ParentAwardId in File C, the sum of each TransactionObligatedAmount should match (but with opposite signs) the sum of the FederalActionObligation reported in D1. This rule does not apply if the ATA field is populated and is different from the Agency ID. """ # Create a 12 character random parent_award_id paid_1 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) paid_2 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) piid = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) # Basic sum, row 3 is ignored in this sum because it doesn't have a paid af_1_row_1 = AwardFinancialFactory(transaction_obligated_amou=1100, piid=piid, parent_award_id=paid_1, allocation_transfer_agency=None) af_1_row_2 = AwardFinancialFactory(transaction_obligated_amou=11, piid=piid, parent_award_id=paid_1, allocation_transfer_agency=None) af_1_row_3 = AwardFinancialFactory(transaction_obligated_amou=11, piid=piid, parent_award_id=None, allocation_transfer_agency=None) # Same ATA/AID or no ATA sum af_2_row_1 = AwardFinancialFactory(transaction_obligated_amou=1111, piid=piid, parent_award_id=paid_2, allocation_transfer_agency=None) af_2_row_2 = AwardFinancialFactory(transaction_obligated_amou=1111, piid=piid, parent_award_id=paid_2, allocation_transfer_agency="good", agency_identifier="good") # Sum of these values doesn't add up (ignoring third one because it has a different paid) ap_1_row_1 = AwardProcurementFactory(parent_award_id=paid_1, piid=piid, federal_action_obligation=-1100) ap_1_row_2 = AwardProcurementFactory(parent_award_id=paid_1, piid=piid, federal_action_obligation=-10) ap_1_row_3 = AwardProcurementFactory(parent_award_id="1234", piid=piid, federal_action_obligation=-1) # Sum of the two above should be both of them, not just one ap_2 = AwardProcurementFactory(parent_award_id=paid_2, piid=piid, federal_action_obligation=-1111) errors = number_of_errors(_FILE, database, models=[af_1_row_1, af_1_row_2, af_1_row_3, af_2_row_1, af_2_row_2, ap_1_row_1, ap_1_row_2, ap_1_row_3, ap_2]) assert errors == 2
def test_failure(database): """ Test failure for each unique URI in File C, the sum of each TransactionObligatedAmount should match (but with opposite signs) the sum of the FederalActionObligation or OriginalLoanSubsidyCost amounts reported in D2. This rule does not apply if the ATA field is populated and is different from the Agency ID. """ # Create a 12 character random uri uri_1 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) uri_2 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) uri_3 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) # Simple addition that doesn't add up right af_1_row_1 = AwardFinancialFactory(transaction_obligated_amou=1100, uri=uri_1, allocation_transfer_agency=None) af_1_row_2 = AwardFinancialFactory(transaction_obligated_amou=11, uri=uri_1, allocation_transfer_agency=None) # Incorrect addition based on assistance type in AFA af_2 = AwardFinancialFactory(transaction_obligated_amou=9999, uri=uri_2, allocation_transfer_agency=None) # Don't ignore when ATA and AID match af_3 = AwardFinancialFactory(transaction_obligated_amou=1100, uri=uri_3, allocation_transfer_agency="good", agency_identifier="good") # Sum of this uri doesn't add up to af uri sum afa_1_row_1 = AwardFinancialAssistanceFactory(uri=uri_1, federal_action_obligation=-1100, original_loan_subsidy_cost=None) afa_1_row_2 = AwardFinancialAssistanceFactory(uri=uri_1, federal_action_obligation=-10, original_loan_subsidy_cost=None) # Both of these rows use the column that isn't filled in for summing so neither results in the correct number afa_2_row_1 = AwardFinancialAssistanceFactory(uri=uri_2, federal_action_obligation=-9999, original_loan_subsidy_cost=None) afa_2_row_2 = AwardFinancialAssistanceFactory(uri=uri_2, federal_action_obligation=None, original_loan_subsidy_cost=-1000, assistance_type='07') # This shouldn't be ignored afa_3 = AwardFinancialAssistanceFactory(uri=uri_3, federal_action_obligation=0, original_loan_subsidy_cost=None) errors = number_of_errors(_FILE, database, models=[af_1_row_1, af_1_row_2, af_2, af_3, afa_1_row_1, afa_1_row_2, afa_2_row_1, afa_2_row_2, afa_3]) assert errors == 3
def test_success(database): """ Testing valid program activity name for the corresponding TAS/TAFS as defined in Section 82 of OMB Circular A-11. """ af_1 = AwardFinancialFactory(row_number=1, beginning_period_of_availa=2016, agency_identifier='test', allocation_transfer_agency='test', main_account_code='test', program_activity_name='test', program_activity_code='test') af_2 = AwardFinancialFactory(row_number=2, beginning_period_of_availa=2016, agency_identifier='test', allocation_transfer_agency='test', main_account_code='test', program_activity_name='test', program_activity_code='test') pa = ProgramActivityFactory(budget_year=2016, agency_id='test', allocation_transfer_id='test', account_number='test', program_activity_name='test', program_activity_code='test') assert number_of_errors(_FILE, database, models=[af_1, af_2, pa]) == 0
def test_success(database): """ Unique PIID, ParentAwardId from file D1 exists in file C during the same reporting period, except D1 records with zero FederalActionObligation. """ ap = AwardProcurementFactory(piid='some_pIId', parent_award_id='some_PArent_award_id', federal_action_obligation=1) af = AwardFinancialFactory(piid='some_piid', parent_award_id='some_parent_AWard_id') assert number_of_errors(_FILE, database, models=[ap, af]) == 0 # Rule shouldn't be checked if federal_action_obligation is null ap = AwardProcurementFactory(piid='some_piid', parent_award_id='some_PArent_award_id', federal_action_obligation=None) assert number_of_errors(_FILE, database, models=[ap]) == 0 # Checks null = null ap = AwardProcurementFactory(piid='some_piid', parent_award_id=None, federal_action_obligation=1) af = AwardFinancialFactory(piid='some_pIId', parent_award_id=None) assert number_of_errors(_FILE, database, models=[ap, af]) == 0
def test_failure(database): """ Test failure for each unique PIID in File C, the sum of each TransactionObligatedAmount should match (but with opposite signs) the sum of the FederalActionObligation reported in D1. This rule does not apply if the ATA field is populated and is different from the Agency ID. Ignore rows that contain a PAID. """ # Create a 12 character random piid piid_1 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) piid_2 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) piid_3 = ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) # No ATA, not matching (off by 1) af_1_row_1 = AwardFinancialFactory(transaction_obligated_amou=1100, piid=piid_1, parent_award_id='', allocation_transfer_agency=None) af_1_row_2 = AwardFinancialFactory(transaction_obligated_amou=11, piid=piid_1, parent_award_id=None, allocation_transfer_agency=None) # No ATA, not matching, one record, no paid af_2 = AwardFinancialFactory(transaction_obligated_amou=9999, piid=piid_2, parent_award_id=None, allocation_transfer_agency=None) # Matching ATA, should not be ignored af_3 = AwardFinancialFactory(transaction_obligated_amou=11, piid=piid_3, parent_award_id=None, allocation_transfer_agency="123", agency_identifier="123") # Award Procurement portion of checks # Sum of all these would be sum of piid_1 af if one wasn't ignored ap_1_row_1 = AwardProcurementFactory(piid=piid_1, parent_award_id=None, federal_action_obligation=-1100) ap_1_row_2 = AwardProcurementFactory(piid=piid_1, parent_award_id=None, federal_action_obligation=-10) # second piid that simply doesn't match ap_2 = AwardProcurementFactory(piid=piid_2, parent_award_id=None, federal_action_obligation=-1111) # third piid that should not be ignored because ATA is present but matches ap_3 = AwardProcurementFactory(piid=piid_3, parent_award_id=None, federal_action_obligation=0) errors = number_of_errors(_FILE, database, models=[af_1_row_1, af_1_row_2, af_2, af_3, ap_1_row_1, ap_1_row_2, ap_2, ap_3]) assert errors == 3
def test_success(database): """ Test for USSGL 48XX & 49XX (except 487X & 497X) if any one is provided then by_direct_reimbursable_fun is not empty """ af = AwardFinancialFactory() assert number_of_errors(_FILE, database, models=[af]) == 0 af = AwardFinancialFactory(ussgl480100_undelivered_or_fyb=None, ussgl480100_undelivered_or_cpe=None, ussgl483100_undelivered_or_cpe=None, ussgl488100_upward_adjustm_cpe=None, ussgl490100_delivered_orde_fyb=None, ussgl490100_delivered_orde_cpe=None, ussgl493100_delivered_orde_cpe=None, ussgl498100_upward_adjustm_cpe=None, ussgl480200_undelivered_or_fyb=None, ussgl480200_undelivered_or_cpe=None, ussgl483200_undelivered_or_cpe=None, ussgl488200_upward_adjustm_cpe=None, ussgl490200_delivered_orde_cpe=None, ussgl490800_authority_outl_fyb=None, ussgl490800_authority_outl_cpe=None, ussgl498200_upward_adjustm_cpe=None, by_direct_reimbursable_fun=None) assert number_of_errors(_FILE, database, models=[af]) == 0
def test_failure(database): """ Unique PIID, ParentAwardId from file C doesn't exist in file D1 during the same reporting period. """ # Perform when there's a transaction obligated amount value in the field af = AwardFinancialFactory(piid='some_piid', parent_award_id='some_parent_award_id', allocation_transfer_agency=None, transaction_obligated_amou='12345') ap = AwardProcurementFactory(piid='some_other_piid', parent_award_id='some_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 1 # Perform when there's a transaction obligated amount value in the field af = AwardFinancialFactory(piid='some_piid', parent_award_id='some_parent_award_id', allocation_transfer_agency='bad', transaction_obligated_amou='12345') ap = AwardProcurementFactory(piid='some_piid', parent_award_id='some_other_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 1 af = AwardFinancialFactory(piid='some_piid', parent_award_id=None, allocation_transfer_agency='bad', transaction_obligated_amou='12345') ap = AwardProcurementFactory(piid='some_other_piid', parent_award_id='some_other_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 1
def test_failure(database): """ Test failure for unique PIID, or combination of PIID/ParentAwardId, from file C exists in file D1 during the same reporting period. Do not process if allocation transfer agency is not null and does not match agency ID. """ # Perform when there's a transaction obligated amount value in the field af = AwardFinancialFactory(piid='some_pIId', parent_award_id='some_pARent_award_id', allocation_transfer_agency=None, transaction_obligated_amou='12345') ap = AwardProcurementFactory(piid='some_other_piid', parent_award_id='some_parent_AWard_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 1 # Perform when there's an ata in the field and it matches the aid af = AwardFinancialFactory(piid='some_piid', parent_award_id='some_parent_AWard_id', allocation_transfer_agency='bad', agency_identifier='bad', transaction_obligated_amou='12345') ap = AwardProcurementFactory(piid='some_pIId', parent_award_id='soME_other_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 1 af = AwardFinancialFactory(piid='some_piid', parent_award_id=None, allocation_transfer_agency='bad', agency_identifier='bad', transaction_obligated_amou='12345') ap = AwardProcurementFactory(piid='some_other_piid', parent_award_id='some_oTHer_parent_award_id') assert number_of_errors(_FILE, database, models=[af, ap]) == 1
def test_both_fain_and_url_supplied(database): """ Tests File D2 (award financial assistance) having both uri and fain populated. """ tas = _TAS afa_1 = AwardFinancialAssistanceFactory(tas=tas, fain='aBc', uri='xYz', federal_action_obligation=1, original_loan_subsidy_cost='1', record_type='2') afa_2 = AwardFinancialAssistanceFactory(tas=tas, fain='dEf', uri='gHi', federal_action_obligation=1, original_loan_subsidy_cost='1', record_type='1') af_1 = AwardFinancialFactory(tas=tas, submisson_id=afa_1.submission_id, fain=afa_1.fain.lower(), uri=None, transaction_obligated_amou=1) af_2 = AwardFinancialFactory(tas=tas, submisson_id=afa_2.submission_id, fain=None, uri=afa_2.uri.lower(), transaction_obligated_amou=0) errors = number_of_errors(_FILE, database, models=[afa_1, afa_2, af_1, af_2]) assert errors == 0
def test_success(database): """ Test that a four digit object class with no flag is a success, and a three digit object class with a flag is a success """ # Create a 12 character random fain fain = ''.join( choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) fain_two = ''.join( choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) fain_three = ''.join( choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) first_fain_row_one = AwardFinancialFactory(transaction_obligated_amou=1100, fain=fain, allocation_transfer_agency=None) first_fain_row_two = AwardFinancialFactory(transaction_obligated_amou=11, fain=fain, allocation_transfer_agency=None) # And add a row for a different fain second_fain_row_one = AwardFinancialFactory( transaction_obligated_amou=9999, fain=fain_two, allocation_transfer_agency=None) third_fain_row_one = AwardFinancialFactory(transaction_obligated_amou=8888, fain=fain_three, allocation_transfer_agency=123) first_afa_row = AwardFinancialAssistanceFactory( fain=fain, federal_action_obligation=-1100, original_loan_subsidy_cost=None) second_afa_row = AwardFinancialAssistanceFactory( fain=fain, federal_action_obligation=-10, original_loan_subsidy_cost=None) third_afa_row = AwardFinancialAssistanceFactory( fain=fain, original_loan_subsidy_cost=-1, assistance_type='08', federal_action_obligation=None) wrong_type_afa_row = AwardFinancialAssistanceFactory( fain=fain, original_loan_subsidy_cost=-2222, assistance_type='09', federal_action_obligation=None) other_fain_afa_row = AwardFinancialAssistanceFactory( fain=fain_two, federal_action_obligation=-9999, original_loan_subsidy_cost=None) third_fain_ap_row = AwardFinancialAssistanceFactory( fain=fain_three, federal_action_obligation=-9999) errors = number_of_errors(_FILE, database, models=[ first_fain_row_one, first_fain_row_two, second_fain_row_one, first_afa_row, second_afa_row, third_afa_row, wrong_type_afa_row, other_fain_afa_row, third_fain_row_one, third_fain_ap_row ]) assert errors == 0
def test_success(database): """ Test that calculation passes with equal values and with a null """ value_one = Decimal('101.23') value_two = Decimal('102.34') value_three = Decimal('103.45') value_four = Decimal('104.56') award_fin = AwardFinancialFactory(gross_outlay_amount_by_awa_cpe=value_one - value_three + value_two - value_four, gross_outlays_undelivered_cpe=value_one, gross_outlays_delivered_or_cpe=value_two, gross_outlays_undelivered_fyb=value_three, gross_outlays_delivered_or_fyb=value_four) award_fin_2 = AwardFinancialFactory(gross_outlay_amount_by_awa_cpe=-value_three + value_two - value_four, gross_outlays_undelivered_cpe=None, gross_outlays_delivered_or_cpe=value_two, gross_outlays_undelivered_fyb=value_three, gross_outlays_delivered_or_fyb=value_four) award_fin_3 = AwardFinancialFactory(gross_outlay_amount_by_awa_cpe=value_one - value_three - value_four, gross_outlays_undelivered_cpe=value_one, gross_outlays_delivered_or_cpe=None, gross_outlays_undelivered_fyb=value_three, gross_outlays_delivered_or_fyb=value_four) award_fin_4 = AwardFinancialFactory(gross_outlay_amount_by_awa_cpe=value_one + value_two - value_four, gross_outlays_undelivered_cpe=value_one, gross_outlays_delivered_or_cpe=value_two, gross_outlays_undelivered_fyb=None, gross_outlays_delivered_or_fyb=value_four) award_fin_5 = AwardFinancialFactory(gross_outlay_amount_by_awa_cpe=value_one - value_three + value_two, gross_outlays_undelivered_cpe=value_one, gross_outlays_delivered_or_cpe=value_two, gross_outlays_undelivered_fyb=value_three, gross_outlays_delivered_or_fyb=None) assert number_of_errors(_FILE, database, models=[award_fin, award_fin_2, award_fin_3, award_fin_4, award_fin_5]) == 0
def test_ignored_and_failed_original_loan_subsidy_cost_values(database): """ Tests that a single warning is thrown for both a federal action obligation of 0 and an original loan subsidy cost of 0. """ tas = _TAS afa = AwardFinancialAssistanceFactory(tas=tas, fain='abc', uri=None, federal_action_obligation=1, original_loan_subsidy_cost='0', assistance_type='09', record_type='3') afa_2 = AwardFinancialAssistanceFactory(tas=tas, fain='aBc', uri=None, federal_action_obligation=1, original_loan_subsidy_cost='-2.3', assistance_type='09', record_type='2') afa_3 = AwardFinancialAssistanceFactory(tas=tas, fain='abC', uri=None, federal_action_obligation=1, original_loan_subsidy_cost='2.3', assistance_type='08', record_type='3') af = AwardFinancialFactory(tas=tas, submisson_id=afa.submission_id, fain=None, uri=None, transaction_obligated_amou=1) errors = number_of_errors(_FILE, database, models=[afa, af, afa_2, afa_3]) assert errors == 3 # Test that this is ignored if assistance type is 08 afa = AwardFinancialAssistanceFactory(tas=tas, fain='abc', uri=None, federal_action_obligation=1, original_loan_subsidy_cost='0', assistance_type='08', record_type='2') afa_2 = AwardFinancialAssistanceFactory(tas=tas, fain='aBc', uri=None, federal_action_obligation=1, original_loan_subsidy_cost='-2.3', assistance_type='08', record_type='3') af = AwardFinancialFactory(tas=tas, submisson_id=afa.submission_id, fain=None, uri=None, transaction_obligated_amou=1) errors = number_of_errors(_FILE, database, models=[afa, af, afa_2]) assert errors == 0
def test_success(database): """ Test that availability type code is either x or absent """ award_fin = AwardFinancialFactory(availability_type_code='X') award_fin_lower = AwardFinancialFactory(availability_type_code='x') award_fin_null = AwardFinancialFactory(availability_type_code=None) errors = number_of_errors( _FILE, database, models=[award_fin, award_fin_null, award_fin_lower]) assert errors == 0
def test_failure(database): """ Test invalid 4 digit object class code and corresponding reimbursable funding source """ af = AwardFinancialFactory(object_class='1234', by_direct_reimbursable_fun='x') assert number_of_errors(_FILE, database, models=[af]) == 1 af = AwardFinancialFactory(object_class='2234', by_direct_reimbursable_fun='Y') assert number_of_errors(_FILE, database, models=[af]) == 1
def test_success(database): """ Test that agency codes are matched against cgac correctly """ award_fin = AwardFinancialFactory() award_fin_null = AwardFinancialFactory(agency_identifier=None) cgac = CGACFactory(cgac_code=award_fin.agency_identifier) errors = number_of_errors(_FILE, database, models=[award_fin, award_fin_null, cgac]) assert errors == 0
def test_success(database): """ Test that calculation passes with equal values and with a null """ value_one = Decimal('101.23') award_fin = AwardFinancialFactory(gross_outlays_undelivered_fyb=value_one, ussgl480200_undelivered_or_fyb=value_one) award_fin_null = AwardFinancialFactory(gross_outlays_undelivered_fyb=0, ussgl480200_undelivered_or_fyb=None) assert number_of_errors(_FILE, database, models=[award_fin, award_fin_null]) == 0
def test_failure(database): """ Test that a three digit object class with no flag is an error. Only finds rows with matching piid AND parent_award_id from AwardFinancialFactory and doesn't care about rows with null parent_award_id in AwardFinancialFactory """ # Create a 12 character random parent_award_id parent_award_id = ''.join( choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) parent_award_id_two = ''.join( choice(ascii_uppercase + ascii_lowercase + digits) for _ in range(12)) first_parent_award_id_row_one = AwardFinancialFactory( transaction_obligated_amou=1100, piid="1234", parent_award_id=parent_award_id, allocation_transfer_agency=None) first_parent_award_id_row_two = AwardFinancialFactory( transaction_obligated_amou=11, piid="1234", parent_award_id=parent_award_id, allocation_transfer_agency=None) first_parent_award_id_row_three = AwardFinancialFactory( transaction_obligated_amou=11, piid="1234", parent_award_id=None, allocation_transfer_agency=None) # And add a row that is wrong second_parent_award_id_row_one = AwardFinancialFactory( transaction_obligated_amou=9999, piid="1234", parent_award_id=parent_award_id_two, allocation_transfer_agency=None) first_ap_row = AwardProcurementFactory(parent_award_id=parent_award_id, piid="1234", federal_action_obligation=-1100) second_ap_row = AwardProcurementFactory(parent_award_id=parent_award_id, piid="1234", federal_action_obligation=-10) third_ap_row = AwardProcurementFactory(parent_award_id="1234", piid="1234", federal_action_obligation=-10) other_parent_award_id_ap_row = AwardProcurementFactory( parent_award_id=parent_award_id_two, piid="1234", federal_action_obligation=-1111) errors = number_of_errors(_FILE, database, models=[ first_parent_award_id_row_one, first_parent_award_id_row_two, first_parent_award_id_row_three, second_parent_award_id_row_one, first_ap_row, second_ap_row, third_ap_row, other_parent_award_id_ap_row ]) assert errors == 2
def test_failure(database): """ ObligationsUndeliveredOrdersUnpaidTotal in File C != USSGL 4801 + 4881 in File C for the same date context (FYB) """ af = AwardFinancialFactory(obligations_undelivered_or_fyb=1, ussgl480100_undelivered_or_fyb=None) assert number_of_errors(_FILE, database, models=[af]) == 1 af = AwardFinancialFactory(obligations_undelivered_or_fyb=1, ussgl480100_undelivered_or_fyb=2) assert number_of_errors(_FILE, database, models=[af]) == 1
def test_failure(database): """ Test fail DEFC values must be A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, or T (plus future codes as determined by OMB). DEFC cannot be blank. """ op1 = AwardFinancialFactory(disaster_emergency_fund_code='z') op2 = AwardFinancialFactory(disaster_emergency_fund_code='3') op3 = AwardFinancialFactory(disaster_emergency_fund_code='AA') op4 = AwardFinancialFactory(disaster_emergency_fund_code='') errors = number_of_errors(_FILE, database, models=[op1, op2, op3, op4]) assert errors == 4
def test_failure(database): """ Test with fain, uri, and piid all absent """ # Test with all three award_fin = AwardFinancialFactory() # Test with one missing award_fin_no_fain = AwardFinancialFactory(fain=None) award_fin_no_uri = AwardFinancialFactory(uri=None) assert number_of_errors( _FILE, database, models=[award_fin, award_fin_no_fain, award_fin_no_uri]) == 3
def test_success(database): """ Test cases with different combinations of fain, uri, and piid """ # Test with only one present award_fin_fain = AwardFinancialFactory(uri=None, piid=None) award_fin_uri = AwardFinancialFactory(fain=None, piid=None) award_fin_piid = AwardFinancialFactory(fain=None, uri=None) assert number_of_errors( _FILE, database, models=[award_fin_fain, award_fin_uri, award_fin_piid]) == 0
def test_success(database): """ Tests that Beginning Period of Availability and Ending Period of Availability are blank if Availability Type Code = X """ tas = "".join([_TAS, "_success"]) af1 = AwardFinancialFactory(availability_type_code='x', beginning_period_of_availa=None, ending_period_of_availabil=None) af2 = AwardFinancialFactory(availability_type_code='X', beginning_period_of_availa=None, ending_period_of_availabil=None) assert number_of_errors(_FILE, database, models=[af1, af2]) == 0
def test_relevantFainPiids(database): """We should be retrieving a pair of all FAINs and PIIDs associated with a particular submission""" sess = database.session award1 = AwardFinancialFactory() award2 = AwardFinancialFactory(submission_id=award1.submission_id, piid=None) award3 = AwardFinancialFactory() sess.add_all([award1, award2, award3]) fains, piids = fileF.relevantFainsPiids(sess, award1.submission_id) assert fains == {award1.fain, award2.fain} # ignores award3 assert piids == {award1.piid} # ignores award2's None
def test_success(database): """ ObligationsDeliveredOrdersUnpaidTotal in File C = USSGL 4901 + 4981 in File C for the same date context (FYB) """ af = AwardFinancialFactory(obligations_delivered_orde_fyb=None, ussgl490100_delivered_orde_fyb=None) assert number_of_errors(_FILE, database, models=[af]) == 0 af = AwardFinancialFactory(obligations_delivered_orde_fyb=1, ussgl490100_delivered_orde_fyb=1) assert number_of_errors(_FILE, database, models=[af]) == 0