def test_derive_pii_redacted_ppop_data(database): initialize_db_values(database) # Test derivations when country code is USA obj = initialize_test_obj(record_type=3, legal_country='USA', le_zip5='54321') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perform_country_c'] == 'USA' assert obj['place_of_perform_country_n'] == 'United States of America' assert obj['place_of_performance_city'] == 'Test City 2' assert obj['place_of_perform_county_co'] == '001' assert obj['place_of_perform_county_na'] == 'Test County' assert obj['place_of_perform_state_nam'] == 'New York' assert obj['place_of_performance_zip4a'] == '54321' assert obj['place_of_performance_congr'] == '05' # Test derivations when country code isn't USA obj = initialize_test_obj(record_type=3, legal_country='GBR', legal_foreign_city='London') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perform_country_c'] == 'GBR' assert obj['place_of_perform_country_n'] == 'Great Britain' assert obj['place_of_performance_city'] == 'London' assert obj['place_of_performance_forei'] == 'London'
def test_derive_labels(database): initialize_db_values(database) # Testing when these values are blank obj = initialize_test_obj() obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['action_type_description'] is None assert obj['assistance_type_desc'] is None assert obj['correction_delete_ind_desc'] is None assert obj['business_types_desc'] is None assert obj['business_funds_ind_desc'] is None # Testing for valid values of each obj = initialize_test_obj(cdi='c', action_type='a', assist_type='02', busi_type='d', busi_fund='non') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['action_type_description'] == ACTION_TYPE_DICT['A'] assert obj['assistance_type_desc'] == ASSISTANCE_TYPE_DICT['02'] assert obj['correction_delete_ind_desc'] == CORRECTION_DELETE_IND_DICT['C'] assert obj['record_type_description'] == RECORD_TYPE_DICT[2] assert obj['business_types_desc'] == BUSINESS_TYPE_DICT['D'] assert obj['business_funds_ind_desc'] == BUSINESS_FUNDS_IND_DICT['NON'] # Testing for invalid values of each obj = initialize_test_obj(cdi='f', action_type='z', assist_type='01', record_type=5, busi_type='Z', busi_fund='ab') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['action_type_description'] is None assert obj['assistance_type_desc'] is None assert obj['correction_delete_ind_desc'] is None assert obj['record_type_description'] is None assert obj['business_types_desc'] is None assert obj['business_funds_ind_desc'] is None # Test multiple business types (2 valid, one invalid) obj = initialize_test_obj(cdi='f', action_type='z', assist_type='01', record_type=5, busi_type='azb') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['business_types_desc'] == BUSINESS_TYPE_DICT[ 'A'] + ';' + BUSINESS_TYPE_DICT['B']
def test_derive_ppop_code(database): initialize_db_values(database) # Making sure nothing is changing if record type isn't 3 obj = initialize_test_obj(record_type=1, legal_country='USA', le_zip5='12345') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_code'] == 'NY00000' # 00FORGN if country isn't USA obj = initialize_test_obj(record_type=3, ppop_code=None, legal_country='GBD') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_code'] == '00FORGN' # No derivation if country is USA and there is no state code obj = initialize_test_obj(record_type=3, ppop_code=None, legal_country='USA') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_code'] is None # Default to 00000 if legal entity city code is nothing and country is USA obj = initialize_test_obj(record_type=3, ppop_code=None, legal_country='USA', le_zip5='54321') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_code'] == 'NY00000' # Properly set city code if legal entity city code is there and country is USA obj = initialize_test_obj(record_type=3, ppop_code=None, legal_country='USA', le_zip5='12345') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_code'] == 'NY00001'
def test_funding_office_codes(database): initialize_db_values(database) # if funding office_code is present, get office name obj = initialize_test_obj() obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['funding_office_name'] == 'Office' obj = initialize_test_obj(funding_office='111111') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['funding_office_name'] is None
def test_legal_country(database): initialize_db_values(database) # if primary_place_of_performance_country_code is present get country name obj = initialize_test_obj(legal_country='USA') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_country_name'] == 'United States of America' obj = initialize_test_obj(legal_country='NK') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_country_name'] is None
def test_cfda_title(database): initialize_db_values(database) # when cfda_number isn't in the database obj = initialize_test_obj() obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['cfda_title'] is None # when cfda_number is in the database obj = initialize_test_obj(cfda_num='12.345') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['cfda_title'] == 'CFDA Title'
def test_derive_parent_duns_no_parent_info(database): initialize_db_values(database) obj = initialize_test_obj(awardee_or_recipient_uniqu='345678901') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['ultimate_parent_legal_enti'] is None assert obj['ultimate_parent_unique_ide'] is None
def test_awarding_agency_frec(database): initialize_db_values(database) obj = initialize_test_obj(sub_tier_code='4321') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['awarding_agency_code'] == '1111' assert obj['awarding_agency_name'] == 'Test FREC Agency' assert obj['awarding_sub_tier_agency_n'] == 'Test Frec Subtier Agency'
def test_split_zip(database): initialize_db_values(database) # testing with 5-digit obj = initialize_test_obj(ppop_zip4a='12345') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_zip5'] == '12345' assert obj['place_of_perform_zip_last4'] is None # testing with 9-digit obj = initialize_test_obj(ppop_zip4a='123456789') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_zip5'] == '12345' assert obj['place_of_perform_zip_last4'] == '6789' # testing with 9-digit and dash obj = initialize_test_obj(ppop_zip4a='12345-6789') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_zip5'] == '12345' assert obj['place_of_perform_zip_last4'] == '6789' # testing with city-wide obj = initialize_test_obj(ppop_zip4a='city-wide') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_zip5'] is None assert obj['place_of_perform_zip_last4'] is None # testing without ppop_zip4 obj = initialize_test_obj(ppop_zip4a='') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_zip5'] is None assert obj['place_of_perform_zip_last4'] is None
def test_funding_sub_tier_agency_na(database): initialize_db_values(database) # when funding_sub_tier_agency_co is not provided obj = initialize_test_obj() obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['funding_sub_tier_agency_na'] is None assert obj['funding_agency_code'] is None assert obj['funding_agency_name'] is None # when funding_sub_tier_agency_co is provided obj = initialize_test_obj(sub_fund_agency_code='1234') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['funding_sub_tier_agency_na'] == 'Test Subtier Agency' assert obj['funding_agency_code'] == '000' assert obj['funding_agency_name'] == 'Test CGAC Agency'
def test_is_active(database): initialize_db_values(database) # Testing with none values obj = initialize_test_obj() obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['is_active'] is True # Testing with value other than D obj = initialize_test_obj(cdi='c') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['is_active'] is True # Testing with D obj = initialize_test_obj(cdi='D') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['is_active'] is False
def test_ppop_state(database): initialize_db_values(database) obj = initialize_test_obj() obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perfor_state_code'] == 'NY' assert obj['place_of_perform_state_nam'] == 'New York' obj = initialize_test_obj(ppop_code='00*****') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perfor_state_code'] is None assert obj['place_of_perform_state_nam'] == 'Multi-state' obj = initialize_test_obj(ppop_code='', record_type=3) obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perfor_state_code'] is None assert obj['place_of_perform_state_nam'] is None
def test_total_funding_amount(database): initialize_db_values(database) # when fao and nffa are empty obj = initialize_test_obj() obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['total_funding_amount'] == 0 # when one of fao and nffa is empty and the other isn't obj = initialize_test_obj(fao=5.3) obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['total_funding_amount'] == 5.3 # when fao and nffa aren't empty obj = initialize_test_obj(fao=-10.6, nffa=123) obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['total_funding_amount'] == 112.4
def test_legal_entity_derivations(database): initialize_db_values(database) # if there is a legal_entity_zip5, record_type is always 2 or 3 # when we have legal_entity_zip5 and zip4 obj = initialize_test_obj(le_zip5='12345', le_zip4='6789') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_city_name'] == 'Test City' assert obj['legal_entity_congressional'] == '01' assert obj['legal_entity_county_code'] == '001' assert obj['legal_entity_county_name'] == 'Test County' assert obj['legal_entity_state_code'] == 'NY' assert obj['legal_entity_state_name'] == 'New York' # when we have legal_entity_zip5 but no zip4 obj = initialize_test_obj(le_zip5='12345') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_city_name'] == 'Test City' # there are multiple options so this should be 90 assert obj['legal_entity_congressional'] == '90' assert obj['legal_entity_county_code'] == '001' assert obj['legal_entity_county_name'] == 'Test County' assert obj['legal_entity_state_code'] == 'NY' assert obj['legal_entity_state_name'] == 'New York' # when we have legal_entity_zip5 and congressional but no zip4 obj = initialize_test_obj(le_zip5='12345', legal_congr='95') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_congressional'] == '95' # if there is no legal_entity_zip5 and record_type is 1, ppop_code is always in format XX**### obj = initialize_test_obj(record_type=1, ppop_cd='03', ppop_code='NY**001') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_city_name'] is None assert obj['legal_entity_congressional'] == '03' assert obj['legal_entity_county_code'] == '001' assert obj['legal_entity_county_name'] == 'Test County' assert obj['legal_entity_state_code'] == 'NY' assert obj['legal_entity_state_name'] == 'New York' # if there is no legal_entity_zip5, record_type is always 1 and ppop_code can be format XX***** obj = initialize_test_obj(record_type=1, ppop_cd=None, ppop_code='NY*****') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_city_name'] is None assert obj['legal_entity_congressional'] is None assert obj['legal_entity_county_code'] is None assert obj['legal_entity_county_name'] is None assert obj['legal_entity_state_code'] == 'NY' assert obj['legal_entity_state_name'] == 'New York' # if there is no legal_entity_zip5, record_type is always 1 and ppop_code can be format 00FORGN obj = initialize_test_obj(record_type=1, ppop_cd=None, ppop_code='00FORGN') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['legal_entity_city_name'] is None assert obj['legal_entity_congressional'] is None assert obj['legal_entity_county_code'] is None assert obj['legal_entity_county_name'] is None assert obj['legal_entity_state_code'] is None assert obj['legal_entity_state_name'] is None
def test_ppop_derivations(database): initialize_db_values(database) # when ppop_zip4a is 5 digits and no congressional district obj = initialize_test_obj(ppop_zip4a='123454321') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_congr'] == '02' assert obj['place_of_perform_county_co'] == '001' assert obj['place_of_perform_county_na'] == 'Test County' assert obj['place_of_performance_city'] == 'Test City' # when ppop_zip4a is 5 digits and has congressional district obj = initialize_test_obj(ppop_zip4a='12345-4321', ppop_cd='03') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_congr'] == '03' # when ppop_zip4a is 5 digits obj = initialize_test_obj(ppop_zip4a='12345') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) # cd should be 90 if there's more than one option assert obj['place_of_performance_congr'] == '90' assert obj['place_of_perform_county_co'] == '001' assert obj['place_of_perform_county_na'] == 'Test County' assert obj['place_of_performance_city'] == 'Test City' # when ppop_zip4 is 9 digits but last 4 are invalid (one cd available) obj = initialize_test_obj(ppop_zip4a='543210000') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_congr'] == '05' assert obj['place_of_perform_county_co'] == '001' assert obj['place_of_perform_county_na'] == 'Test County' assert obj['place_of_performance_city'] == 'Test City 2' # when ppop_zip4 is 9 digits (no cd available) obj = initialize_test_obj(ppop_zip4a='987654321') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_performance_congr'] == '90' assert obj['place_of_perform_county_co'] == '001' assert obj['place_of_perform_county_na'] == 'Test County' assert obj['place_of_performance_city'] == 'Test City 3' # when we don't have ppop_zip4a and ppop_code is in XX**### format obj = initialize_test_obj(ppop_code='NY**001') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perform_county_co'] == '001' assert obj['place_of_perform_county_na'] == 'Test County' assert obj['place_of_performance_city'] is None assert obj['place_of_performance_congr'] is None # when we don't have ppop_zip4a and ppop_code is in XX##### format obj = initialize_test_obj(ppop_code='NY00001') obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perform_county_co'] == '001' assert obj['place_of_perform_county_na'] == 'Test City County' assert obj['place_of_performance_city'] == 'Test City' assert obj['place_of_performance_congr'] is None # when we don't have a ppop_code at all obj = initialize_test_obj(ppop_code='', record_type=3) obj = fabs_derivations(obj, database.session, STATE_DICT, COUNTRY_DICT, SUB_TIER_DICT, CFDA_DICT, COUNTY_DICT, FPDS_OFFICE_DICT) assert obj['place_of_perform_county_co'] is None assert obj['place_of_perform_county_na'] is None assert obj['place_of_performance_city'] is None assert obj['place_of_performance_congr'] is None