def test_success(database): """ Test If LegalEntityCongressionalDistrict is provided, it must be valid in the 5-digit zip code indicated by LegalEntityZIP5. Districts that were created under the 2000 census or later are considered valid. This rule is ignored when CorrectionDeleteIndicator is D """ zip1 = ZipsFactory(zip5="12345", congressional_district_no="01", state_abbreviation="AB") zip2 = ZipsFactory(zip5="23456", congressional_district_no="01", state_abbreviation="CD") sc1 = StateCongressionalFactory(state_code="AB", congressional_district_no="01", census_year=None) sc2 = StateCongressionalFactory(state_code="CD", congressional_district_no="02", census_year=2000) det_award_1 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="12345", legal_entity_congressional="", correction_delete_indicatr='') det_award_2 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="", legal_entity_congressional="01", correction_delete_indicatr='C') det_award_3 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="", legal_entity_congressional="", correction_delete_indicatr='c') det_award_4 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="", legal_entity_congressional="", correction_delete_indicatr='d') det_award_5 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="12345", legal_entity_congressional=None, correction_delete_indicatr=None) det_award_6 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="12345", legal_entity_congressional="01", correction_delete_indicatr='c') det_award_7 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="23456", legal_entity_congressional="02", correction_delete_indicatr='') # Test ignore cdi of D det_award_8 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="12345", legal_entity_congressional="03", correction_delete_indicatr='d') errors = number_of_errors(_FILE, database, models=[det_award_1, det_award_2, det_award_3, det_award_4, det_award_5, det_award_6, det_award_7, det_award_8, zip1, zip2, sc1, sc2]) assert errors == 0
def initialize_db_values(db): """ Initialize the values in the DB that can be used throughout the tests """ zip_code_1 = ZipsFactory(zip5='12345', zip_last4='6789', state_abbreviation='NY', county_number='001', congressional_district_no='01') zip_code_2 = ZipsFactory(zip5='12345', zip_last4='4321', state_abbreviation='NY', county_number='001', congressional_district_no='02') zip_code_3 = ZipsFactory(zip5='54321', zip_last4='4321', state_abbreviation='NY', county_number='001', congressional_district_no='05') zip_code_4 = ZipsFactory(zip5='98765', zip_last4='4321', state_abbreviation='NY', county_number='001', congressional_district_no=None) zip_city = ZipCityFactory(zip_code=zip_code_1.zip5, city_name='Test City') zip_city_2 = ZipCityFactory(zip_code=zip_code_3.zip5, city_name='Test City 2') zip_city_3 = ZipCityFactory(zip_code=zip_code_4.zip5, city_name='Test City 3') city_code = CityCodeFactory(feature_name='Test City', city_code='00001', state_code='NY', county_number=zip_code_1.county_number, county_name='Test City County') duns_1 = DunsFactory(awardee_or_recipient_uniqu='123456789', ultimate_parent_unique_ide='234567890', ultimate_parent_legal_enti='Parent 1') duns_2a = DunsFactory(awardee_or_recipient_uniqu='234567890', ultimate_parent_unique_ide='234567890', ultimate_parent_legal_enti='Parent 2') duns_2b = DunsFactory(awardee_or_recipient_uniqu='234567890', ultimate_parent_unique_ide=None, ultimate_parent_legal_enti=None) duns_3 = DunsFactory(awardee_or_recipient_uniqu='345678901', ultimate_parent_unique_ide=None, ultimate_parent_legal_enti=None) db.session.add_all([ zip_code_1, zip_code_2, zip_code_3, zip_code_4, zip_city, zip_city_2, zip_city_3, city_code, duns_1, duns_2a, duns_2b, duns_3 ]) db.session.commit()
def test_failure(database): """ LegalEntityZIP5 is not a valid zip code. """ zip_1 = ZipsFactory(zip5='12345', zip_last4='6789') fabs_1 = FABSFactory(legal_entity_zip5='12345', legal_entity_zip_last4='9876', correction_delete_indicatr='') errors = number_of_errors(_FILE, database, models=[zip_1, fabs_1]) assert errors == 1
def test_success(database): """ LegalEntityZIP5 + LegalEntityZIPLast4 is not a valid 9 digit zip. Null/blank zip codes ignored. """ zip_1 = ZipsFactory(zip5="12345", zip_last4="6789") det_award_1 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="12345", legal_entity_zip_last4="6789") det_award_2 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="12345", legal_entity_zip_last4=None) det_award_3 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5=None, legal_entity_zip_last4="6789") det_award_4 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="12345", legal_entity_zip_last4="") det_award_5 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="", legal_entity_zip_last4="6789") # half bad code but other half blank ignored det_award_6 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="", legal_entity_zip_last4="9876") det_award_7 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="54321", legal_entity_zip_last4="") errors = number_of_errors(_FILE, database, models=[ zip_1, det_award_1, det_award_2, det_award_3, det_award_4, det_award_5, det_award_6, det_award_7 ]) assert errors == 0
def test_failure(database): """ LegalEntityZIP5 is not a valid zip code. """ zip_1 = ZipsFactory(zip5="12345", zip_last4="6789") det_award_1 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="12345", legal_entity_zip_last4="9876") errors = number_of_errors(_FILE, database, models=[zip_1, det_award_1]) assert errors == 1
def test_failure(database): """ LegalEntityZIP5 is not a valid zip code. """ zip_1 = ZipsFactory(zip5='12345', zip_last4='6789') det_award_1 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='12345', legal_entity_zip_last4='9876', correction_delete_indicatr='') errors = number_of_errors(_FILE, database, models=[zip_1, det_award_1]) assert errors == 1
def test_failure(database): """ LegalEntityZIP5 is not a valid zip code. """ zip_1 = ZipsFactory(zip5='12345') fabs_1 = FABSFactory(legal_entity_zip5='54321', correction_delete_indicatr='') # add a valid one to make sure NOT EXISTS is doing what we expect fabs_2 = FABSFactory(legal_entity_zip5='12345', correction_delete_indicatr='c') errors = number_of_errors(_FILE, database, models=[zip_1, fabs_1, fabs_2]) assert errors == 1
def test_success(database): """ LegalEntityZIP5 is not a valid zip code. Null/blank zip codes ignored. """ zip_1 = ZipsFactory(zip5="12345") det_award_1 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="12345") det_award_2 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5=None) det_award_3 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="") errors = number_of_errors( _FILE, database, models=[zip_1, det_award_1, det_award_2, det_award_3]) assert errors == 0
def test_failure(database): """ LegalEntityZIP5 is not a valid zip code. """ zip_1 = ZipsFactory(zip5="12345") det_award_1 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="54321") # add a valid one to make sure NOT EXISTS is doing what we expect det_award_2 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5="12345") errors = number_of_errors(_FILE, database, models=[zip_1, det_award_1, det_award_2]) assert errors == 1
def test_failure(database): """ Test failure If LegalEntityCongressionalDistrict is provided, it must be valid in the 5-digit zip code indicated by LegalEntityZIP5. Districts that were created under the 2000 census or later are considered valid """ zip1 = ZipsFactory(zip5='12345', congressional_district_no='01', state_abbreviation='AB') sc1 = StateCongressionalFactory(state_code='AB', congressional_district_no='01', census_year=None) sc2 = StateCongressionalFactory(state_code='AB', congressional_district_no='02', census_year=1999) fabs_1 = FABSFactory(legal_entity_zip5='12345', legal_entity_congressional='02', correction_delete_indicatr='') fabs_2 = FABSFactory(legal_entity_zip5='12346', legal_entity_congressional='01', correction_delete_indicatr=None) fabs_3 = FABSFactory(legal_entity_zip5='12345', legal_entity_congressional='03', correction_delete_indicatr='C') errors = number_of_errors(_FILE, database, models=[fabs_1, fabs_2, fabs_3, zip1, sc1, sc2]) assert errors == 3
def test_success(database): """ Test If LegalEntityCongressionalDistrict is provided, it must be valid in the 5-digit zip code indicated by LegalEntityZIP5. Districts that were created under the 2000 census or later are considered valid. This rule is ignored when CorrectionDeleteIndicator is D """ zip1 = ZipsFactory(zip5='12345', congressional_district_no='01', state_abbreviation='AB') zip2 = ZipsFactory(zip5='23456', congressional_district_no='01', state_abbreviation='CD') sc1 = StateCongressionalFactory(state_code='AB', congressional_district_no='01', census_year=None) sc2 = StateCongressionalFactory(state_code='CD', congressional_district_no='02', census_year=2000) fabs_1 = FABSFactory(legal_entity_zip5='12345', legal_entity_congressional='', correction_delete_indicatr='') fabs_2 = FABSFactory(legal_entity_zip5='', legal_entity_congressional='01', correction_delete_indicatr='C') fabs_3 = FABSFactory(legal_entity_zip5='', legal_entity_congressional='', correction_delete_indicatr='c') fabs_4 = FABSFactory(legal_entity_zip5='', legal_entity_congressional='', correction_delete_indicatr='d') fabs_5 = FABSFactory(legal_entity_zip5='12345', legal_entity_congressional=None, correction_delete_indicatr=None) fabs_6 = FABSFactory(legal_entity_zip5='12345', legal_entity_congressional='01', correction_delete_indicatr='c') fabs_7 = FABSFactory(legal_entity_zip5='23456', legal_entity_congressional='02', correction_delete_indicatr='') # Test ignore cdi of D fabs_8 = FABSFactory(legal_entity_zip5='12345', legal_entity_congressional='03', correction_delete_indicatr='d') errors = number_of_errors(_FILE, database, models=[fabs_1, fabs_2, fabs_3, fabs_4, fabs_5, fabs_6, fabs_7, fabs_8, zip1, zip2, sc1, sc2]) assert errors == 0
def test_success(database): """ LegalEntityZIP5 + LegalEntityZIPLast4 is not a valid 9 digit zip. Null/blank zip codes ignored. """ zip_1 = ZipsFactory(zip5='12345', zip_last4='6789') det_award_1 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='12345', legal_entity_zip_last4='6789', correction_delete_indicatr='') det_award_2 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='12345', legal_entity_zip_last4=None, correction_delete_indicatr=None) det_award_3 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5=None, legal_entity_zip_last4='6789', correction_delete_indicatr='c') det_award_4 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='12345', legal_entity_zip_last4='', correction_delete_indicatr='C') det_award_5 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='', legal_entity_zip_last4='6789', correction_delete_indicatr='') # half bad code but other half blank ignored det_award_6 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='', legal_entity_zip_last4='9876', correction_delete_indicatr='') det_award_7 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='54321', legal_entity_zip_last4='', correction_delete_indicatr='') # Ignore correction delete indicator of D det_award_8 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='12345', legal_entity_zip_last4='9876', correction_delete_indicatr='d') errors = number_of_errors(_FILE, database, models=[ zip_1, det_award_1, det_award_2, det_award_3, det_award_4, det_award_5, det_award_6, det_award_7, det_award_8 ]) assert errors == 0
def test_success(database): """ LegalEntityZIP5 is not a valid zip code. Null/blank zip codes ignored. """ zip_1 = ZipsFactory(zip5='12345') fabs_1 = FABSFactory(legal_entity_zip5='12345', correction_delete_indicatr='') fabs_2 = FABSFactory(legal_entity_zip5=None, correction_delete_indicatr=None) fabs_3 = FABSFactory(legal_entity_zip5='', correction_delete_indicatr='c') # Ignore correction delete indicator of D fabs_4 = FABSFactory(legal_entity_zip5='54321', correction_delete_indicatr='d') errors = number_of_errors(_FILE, database, models=[zip_1, fabs_1, fabs_2, fabs_3, fabs_4]) assert errors == 0
def test_failure(database): """ Test failure If LegalEntityCongressionalDistrict is provided, it must be valid in the 5-digit zip code indicated by LegalEntityZIP5. Districts that were created under the 2000 census or later are considered valid""" zip1 = ZipsFactory(zip5="12345", congressional_district_no="01", state_abbreviation="AB") sc1 = StateCongressionalFactory(state_code="AB", congressional_district_no="01", census_year=None) sc2 = StateCongressionalFactory(state_code="AB", congressional_district_no="02", census_year=1999) det_award_1 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="12345", legal_entity_congressional="02", correction_delete_indicatr='') det_award_2 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="12346", legal_entity_congressional="01", correction_delete_indicatr=None) det_award_3 = DetachedAwardFinancialAssistanceFactory(legal_entity_zip5="12345", legal_entity_congressional="03", correction_delete_indicatr='C') errors = number_of_errors(_FILE, database, models=[det_award_1, det_award_2, det_award_3, zip1, sc1, sc2]) assert errors == 3
def test_success(database): """ LegalEntityZIP5 is not a valid zip code. Null/blank zip codes ignored. """ zip_1 = ZipsFactory(zip5='12345') det_award_1 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='12345', correction_delete_indicatr='') det_award_2 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5=None, correction_delete_indicatr=None) det_award_3 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='', correction_delete_indicatr='c') # Ignore correction delete indicator of D det_award_4 = DetachedAwardFinancialAssistanceFactory( legal_entity_zip5='54321', correction_delete_indicatr='d') errors = number_of_errors( _FILE, database, models=[zip_1, det_award_1, det_award_2, det_award_3, det_award_4]) assert errors == 0
def test_success(database): """ LegalEntityZIP5 + LegalEntityZIPLast4 is not a valid 9 digit zip. Null/blank zip codes ignored. """ zip_1 = ZipsFactory(zip5='12345', zip_last4='6789') fabs_1 = FABSFactory(legal_entity_zip5='12345', legal_entity_zip_last4='6789', correction_delete_indicatr='') fabs_2 = FABSFactory(legal_entity_zip5='12345', legal_entity_zip_last4=None, correction_delete_indicatr=None) fabs_3 = FABSFactory(legal_entity_zip5=None, legal_entity_zip_last4='6789', correction_delete_indicatr='c') fabs_4 = FABSFactory(legal_entity_zip5='12345', legal_entity_zip_last4='', correction_delete_indicatr='C') fabs_5 = FABSFactory(legal_entity_zip5='', legal_entity_zip_last4='6789', correction_delete_indicatr='') # half bad code but other half blank ignored fabs_6 = FABSFactory(legal_entity_zip5='', legal_entity_zip_last4='9876', correction_delete_indicatr='') fabs_7 = FABSFactory(legal_entity_zip5='54321', legal_entity_zip_last4='', correction_delete_indicatr='') # Ignore correction delete indicator of D fabs_8 = FABSFactory(legal_entity_zip5='12345', legal_entity_zip_last4='9876', correction_delete_indicatr='d') errors = number_of_errors(_FILE, database, models=[zip_1, fabs_1, fabs_2, fabs_3, fabs_4, fabs_5, fabs_6, fabs_7, fabs_8]) assert errors == 0
def initialize_db_values(db, cfda_title=None, cgac_code=None, frec_code=None, use_frec=False): """ Initialize the values in the DB that can be used throughout the tests """ if cgac_code: cgac = CGACFactory(cgac_code=cgac_code, agency_name="Test CGAC Agency") else: cgac = CGACFactory() if frec_code: frec = FRECFactory(frec_code=frec_code, agency_name="Test FREC Agency", cgac=cgac) else: frec = FRECFactory(cgac=cgac) db.session.add_all([cgac, frec]) db.session.commit() cfda_number = CFDAProgramFactory(program_number=12.345, program_title=cfda_title) sub_tier = SubTierAgencyFactory(sub_tier_agency_code="1234", cgac=cgac, frec=frec, is_frec=use_frec, sub_tier_agency_name="Test Subtier Agency") state = StatesFactory(state_code="NY", state_name="New York") zip_code_1 = ZipsFactory(zip5="12345", zip_last4="6789", state_abbreviation=state.state_code, county_number="001", congressional_district_no="01") zip_code_2 = ZipsFactory(zip5="12345", zip_last4="4321", state_abbreviation=state.state_code, county_number="001", congressional_district_no="02") zip_code_3 = ZipsFactory(zip5="54321", zip_last4="4321", state_abbreviation=state.state_code, county_number="001", congressional_district_no="05") zip_code_4 = ZipsFactory(zip5="98765", zip_last4="4321", state_abbreviation=state.state_code, county_number="001", congressional_district_no=None) zip_city = ZipCityFactory(zip_code=zip_code_1.zip5, city_name="Test Zip City") zip_city_2 = ZipCityFactory(zip_code=zip_code_3.zip5, city_name="Test Zip City 2") zip_city_3 = ZipCityFactory(zip_code=zip_code_4.zip5, city_name="Test Zip City 3") county_code = CountyCodeFactory(state_code=state.state_code, county_number=zip_code_1.county_number, county_name="Test County") city_code = CityCodeFactory(feature_name="Test City", city_code="00001", state_code=state.state_code, county_number=zip_code_1.county_number, county_name="Test City County") contracting_office = FPDSContractingOfficeFactory( contracting_office_code='033103', contracting_office_name='Office') country_code = CountryCodeFactory(country_code='USA', country_name='United States of America') db.session.add_all([ sub_tier, state, cfda_number, zip_code_1, zip_code_2, zip_code_3, zip_code_4, zip_city, zip_city_2, zip_city_3, county_code, city_code, contracting_office, country_code ]) db.session.commit()
def initialize_db_values(db): """ Initialize the values in the DB that can be used throughout the tests """ zip_code_1 = ZipsFactory(zip5='12345', zip_last4='6789', state_abbreviation='NY', county_number='001', congressional_district_no='01') zip_code_2 = ZipsFactory(zip5='12345', zip_last4='4321', state_abbreviation='NY', county_number='001', congressional_district_no='02') zip_code_3 = ZipsFactory(zip5='54321', zip_last4='4321', state_abbreviation='NY', county_number='001', congressional_district_no='05') zip_code_4 = ZipsFactory(zip5='98765', zip_last4='4321', state_abbreviation='NY', county_number='001', congressional_district_no=None) zip_city = ZipCityFactory(zip_code=zip_code_1.zip5, city_name='Test City') zip_city_2 = ZipCityFactory(zip_code=zip_code_3.zip5, city_name='Test City 2') zip_city_3 = ZipCityFactory(zip_code=zip_code_4.zip5, city_name='Test City 3') city_code = CityCodeFactory(feature_name='Test City', city_code='00001', state_code='NY', county_number=zip_code_1.county_number, county_name='Test City County') duns_1 = DunsFactory(awardee_or_recipient_uniqu='123456789', ultimate_parent_unique_ide='234567890', ultimate_parent_legal_enti='Parent 1') duns_2a = DunsFactory(awardee_or_recipient_uniqu='234567890', ultimate_parent_unique_ide='234567890', ultimate_parent_legal_enti='Parent 2') duns_2b = DunsFactory(awardee_or_recipient_uniqu='234567890', ultimate_parent_unique_ide=None, ultimate_parent_legal_enti=None) duns_3 = DunsFactory(awardee_or_recipient_uniqu='345678901', ultimate_parent_unique_ide=None, ultimate_parent_legal_enti=None) # record type 2 pafas pafa_1 = PublishedAwardFinancialAssistanceFactory( awarding_sub_tier_agency_c='1234', fain='12345', uri='123456', action_date='04/28/2000', funding_office_code=None, awarding_office_code='033103', is_active=True, record_type=2, award_modification_amendme='0') pafa_2 = PublishedAwardFinancialAssistanceFactory( awarding_sub_tier_agency_c='1234', fain='123456', uri='1234567', action_date='04/28/2000', funding_office_code='033103', awarding_office_code=None, is_active=True, record_type=2, award_modification_amendme=None) # record type 1 pafas pafa_3 = PublishedAwardFinancialAssistanceFactory( awarding_sub_tier_agency_c='1234', fain='54321', uri='654321', action_date='04/28/2000', funding_office_code=None, awarding_office_code='033103', is_active=True, record_type=1, award_modification_amendme=None) pafa_4 = PublishedAwardFinancialAssistanceFactory( awarding_sub_tier_agency_c='1234', fain='654321', uri='7654321', action_date='04/28/2000', funding_office_code='033103', awarding_office_code=None, is_active=True, record_type=1, award_modification_amendme='0') # record type 1 base pafa with invalid office codes pafa_5 = PublishedAwardFinancialAssistanceFactory( awarding_sub_tier_agency_c='1234', fain='abcd', uri='efg', action_date='04/28/2000', funding_office_code='123456', awarding_office_code='123456', is_active=True, record_type=1, award_modification_amendme='0') # record type 1 base pafa with valid office codes but they aren't grant or funding type pafa_6 = PublishedAwardFinancialAssistanceFactory( awarding_sub_tier_agency_c='1234', fain='efg', uri='abcd', action_date='04/28/2000', funding_office_code='654321', awarding_office_code='654321', is_active=True, record_type=1, award_modification_amendme='0') db.session.add_all([ zip_code_1, zip_code_2, zip_code_3, zip_code_4, zip_city, zip_city_2, zip_city_3, city_code, duns_1, duns_2a, duns_2b, duns_3, pafa_1, pafa_2, pafa_3, pafa_4, pafa_5, pafa_6 ]) db.session.commit()