Exemple #1
0
def test_failure(database):
    """ Test failure for when provided, PrimaryPlaceofPerformanceZIP+4 must be in the state specified by
        PrimaryPlaceOfPerformanceCode. In this specific submission row, the ZIP5 (and by extension the full ZIP+4) is
        not a valid ZIP code in the state in question.
    """

    zips = Zips(zip5='12345', zip_last4='6789', state_abbreviation='NY')
    # invalid 5 digit zip
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny10986',
        place_of_performance_zip4a='12346',
        correction_delete_indicatr='')
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='NA*****',
        place_of_performance_zip4a='12345',
        correction_delete_indicatr='c')
    errors = number_of_errors(_FILE,
                              database,
                              models=[det_award_1, det_award_2, zips])
    assert errors == 2

    # invalid 9 digit zip - first five fail (see d41_5 for the last four to fail)
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny10986',
        place_of_performance_zip4a='123466789',
        correction_delete_indicatr=None)
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='NY*****',
        place_of_performance_zip4a='12346-6789',
        correction_delete_indicatr='C')
    errors = number_of_errors(_FILE,
                              database,
                              models=[det_award_1, det_award_2, zips])
    assert errors == 2
def add_to_table(data, sess):
    try:
        sess.bulk_save_objects(
            [Zips(**zip_data) for _, zip_data in data.items()])
        sess.commit()
    except IntegrityError:
        sess.rollback()
        logger.error(
            "Attempted to insert duplicate zip. Inserting each row in batch individually."
        )

        i = 0
        # loop through all the items in the current array
        for _, new_zip in data.items():
            # create an insert statement that overrides old values if there's a conflict
            insert_statement = insert(Zips).values(**new_zip). \
                on_conflict_do_update(index_elements=[Zips.zip5, Zips.zip_last4],
                                      set_=dict(state_abbreviation=new_zip["state_abbreviation"],
                                                county_number=new_zip["county_number"],
                                                congressional_district_no=new_zip["congressional_district_no"]))
            sess.execute(insert_statement)

            if i % 10000 == 0:
                logger.info("Inserting row %s of current batch", str(i))
            i += 1
        sess.commit()
Exemple #3
0
def test_get_county_by_zip(database):
    """ Test that getting the county by zip works """
    sess = database.session
    zip_code = Zips(zip5='12345', zip_last4='6789', county_number='000')
    sess.add(zip_code)
    sess.commit()

    assert pullFPDSData.get_county_by_zip(sess, 'abcde') is None
    assert pullFPDSData.get_county_by_zip(sess, '123456789') == '000'
    assert pullFPDSData.get_county_by_zip(sess, '12345') == '000'
    assert pullFPDSData.get_county_by_zip(sess, '123459876') == '000'
    assert pullFPDSData.get_county_by_zip(sess, '12345678') is None
    assert pullFPDSData.get_county_by_zip(sess, '56789') is None
Exemple #4
0
def test_failure(database):
    """ Test failure for when the provided PrimaryPlaceofPerformanceZIP+4 must be in the state specified by
        PrimaryPlaceOfPerformanceCode. In this specific submission row, the first five digits are valid and located
        in the correct state, but the last 4 are invalid."""
    zips = Zips(zip5="12345", zip_last4="6789", state_abbreviation="NY")

    # invalid 9 digit zip - first 5 digits good
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="123456788")
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NY*****",
        place_of_performance_zip4a='123456788')
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="Ny**123",
        place_of_performance_zip4a='12345-6788')
    errors = number_of_errors(
        _FILE, database, models=[det_award_1, det_award_2, det_award_3, zips])
    assert errors == 3
Exemple #5
0
def test_failure(database):
    """ Test failure for when the provided PrimaryPlaceofPerformanceZIP+4 must be in the state specified by
        PrimaryPlaceOfPerformanceCode. In this specific submission row, the first five digits are valid and located
        in the correct state, but the last 4 are invalid.
    """
    zips = Zips(zip5='12345', zip_last4='6789', state_abbreviation='NY')

    # invalid 9 digit zip - first 5 digits good
    fabs_1 = FABSFactory(place_of_performance_code='ny10986',
                         place_of_performance_zip4a='123456788',
                         correction_delete_indicatr='')
    fabs_2 = FABSFactory(place_of_performance_code='NY*****',
                         place_of_performance_zip4a='123456788',
                         correction_delete_indicatr=None)
    fabs_3 = FABSFactory(place_of_performance_code='Ny**123',
                         place_of_performance_zip4a='12345-6788',
                         correction_delete_indicatr='c')
    errors = number_of_errors(_FILE,
                              database,
                              models=[fabs_1, fabs_2, fabs_3, zips])
    assert errors == 3
Exemple #6
0
def test_calculate_remaining_fields(database):
    """ Test that calculate_remaining_fields calculates fields based on content in the DB and inserts 999 for the code
        if the sub tier agency doesn't exist """
    sess = database.session
    cgac = CGAC(cgac_id=1, cgac_code='1700', agency_name='test name')
    zip_code = Zips(zip5='12345', zip_last4='6789', county_number='123')
    sub_tier = SubTierAgency(sub_tier_agency_code='0000', cgac_id=1)
    sess.add(cgac)
    sess.add(zip_code)
    sess.add(sub_tier)
    sess.commit()

    county_by_name = {
        'GA': {
            'COUNTY ONE': '123',
            'GA COUNTY TWO': '321'
        },
        'MD': {
            'JUST ONE MD': '024'
        }
    }
    county_by_code = {
        'MD': {
            '024': 'JUST ONE MD'
        },
        'GA': {
            '123': 'COUNTY ONE'
        },
        'GU': {
            '123': 'GU COUNTY'
        }
    }
    state_codes = {
        'GA': 'GEORGIA',
        'MD': 'MARYLAND',
        'PR': 'PUERTO RICO',
        'GU': 'GUAM'
    }
    country_list = {'USA': 'UNITED STATES'}

    # build business category values
    business_category_dict = {}
    for field in BUSINESS_CATEGORY_FIELDS:
        business_category_dict[field] = None

    tmp_obj_data = {
        'awarding_sub_tier_agency_c': "0000",
        'funding_sub_tier_agency_co': None,
        'place_of_perform_county_na': 'JUST ONE MD',
        'place_of_performance_state': 'MD',
        'place_of_perfor_state_desc': None,
        'place_of_perform_country_c': 'USA',
        'place_of_perf_country_desc': 'UNITED STATES',
        'place_of_performance_zip4a': None,
        'legal_entity_zip4': '987654321',
        'legal_entity_country_code': 'USA',
        'legal_entity_country_name': 'UNITED STATES',
        'legal_entity_state_code': 'GA',
        'legal_entity_state_descrip': 'GEORGIA'
    }
    tmp_obj_data.update(business_category_dict.copy())
    tmp_obj_data['emerging_small_business'] = 'Y'
    tmp_obj = pullFPDSData.calculate_remaining_fields(
        tmp_obj_data, sess, {sub_tier.sub_tier_agency_code: sub_tier},
        county_by_name, county_by_code, state_codes, country_list)

    tmp_obj_2_data = {
        'awarding_sub_tier_agency_c': None,
        'funding_sub_tier_agency_co': "0001",
        'funding_sub_tier_agency_na': "Not Real",
        'place_of_perform_county_na': 'JUST ONE MD',
        'place_of_performance_state': 'GA',
        'place_of_perfor_state_desc': 'GEORGIA',
        'place_of_perform_country_c': 'USA',
        'place_of_perf_country_desc': 'UNITED STATES',
        'place_of_performance_zip4a': None,
        'legal_entity_zip4': '123456789',
        'legal_entity_country_code': 'USA',
        'legal_entity_country_name': 'UNITED STATES',
        'legal_entity_state_code': 'GA',
        'legal_entity_state_descrip': 'GEORGIA'
    }
    tmp_obj_2_data.update(business_category_dict.copy())
    tmp_obj_2_data['contracting_officers_deter'] = 'O'
    tmp_obj_2 = pullFPDSData.calculate_remaining_fields(
        tmp_obj_2_data, sess, {sub_tier.sub_tier_agency_code: sub_tier},
        county_by_name, county_by_code, state_codes, country_list)

    tmp_obj_3_data = {
        'awarding_sub_tier_agency_c': None,
        'funding_sub_tier_agency_co': None,
        'funding_sub_tier_agency_na': None,
        'place_of_perform_county_na': None,
        'place_of_performance_state': None,
        'place_of_perfor_state_desc': None,
        'place_of_perform_country_c': 'PRI',
        'place_of_perf_country_desc': 'PUERTO RICO',
        'place_of_performance_zip4a': '123456789',
        'legal_entity_zip4': '12345',
        'legal_entity_country_code': 'GUM',
        'legal_entity_country_name': 'GUAM',
        'legal_entity_state_code': 'GA',
        'legal_entity_state_descrip': 'GEORGIA'
    }
    tmp_obj_3_data.update(business_category_dict.copy())
    tmp_obj_3_data['alaskan_native_owned_corpo'] = 'True'
    tmp_obj_3 = pullFPDSData.calculate_remaining_fields(
        tmp_obj_3_data, sess, {sub_tier.sub_tier_agency_code: sub_tier},
        county_by_name, county_by_code, state_codes, country_list)

    assert tmp_obj['awarding_agency_code'] == '1700'
    assert tmp_obj['awarding_agency_name'] == 'test name'
    assert tmp_obj['place_of_perform_county_co'] == '024'
    assert tmp_obj['place_of_perfor_state_desc'] == 'MARYLAND'
    assert tmp_obj['legal_entity_county_code'] is None
    assert tmp_obj['legal_entity_county_name'] is None
    assert sorted(tmp_obj['business_categories']) == [
        'category_business', 'emerging_small_business', 'small_business',
        'special_designations'
    ]
    assert tmp_obj_2['funding_agency_code'] == '999'
    assert tmp_obj_2['funding_agency_name'] is None
    assert tmp_obj_2['place_of_perform_county_co'] is None
    assert tmp_obj_2['legal_entity_zip5'] == '12345'
    assert tmp_obj_2['legal_entity_zip_last4'] == '6789'
    assert tmp_obj_2['legal_entity_county_code'] == '123'
    assert tmp_obj_2['legal_entity_county_name'] == 'COUNTY ONE'
    assert sorted(tmp_obj_2['business_categories']) == [
        'category_business', 'other_than_small_business'
    ]
    assert tmp_obj_3['place_of_perform_country_c'] == 'USA'
    assert tmp_obj_3['place_of_perf_country_desc'] == 'UNITED STATES'
    assert tmp_obj_3['place_of_performance_state'] == 'PR'
    assert tmp_obj_3['place_of_perfor_state_desc'] == 'PUERTO RICO'
    assert tmp_obj_3['place_of_perform_county_co'] == '123'
    assert tmp_obj_3['place_of_performance_zip5'] == '12345'
    assert tmp_obj_3['place_of_perform_zip_last4'] == '6789'
    assert tmp_obj_3['legal_entity_country_code'] == 'USA'
    assert tmp_obj_3['legal_entity_country_name'] == 'UNITED STATES'
    assert tmp_obj_3['legal_entity_state_code'] == 'GU'
    assert tmp_obj_3['legal_entity_state_descrip'] == 'GUAM'
    assert tmp_obj_3['legal_entity_county_code'] == '123'
    assert tmp_obj_3['legal_entity_county_name'] == 'GU COUNTY'
    assert sorted(tmp_obj_3['business_categories']) == [
        'alaskan_native_owned_business', 'minority_owned_business'
    ]
def test_group_zips(database):
    """ Testing the grouping of zips. """
    sess = database.session
    # Only difference is the zip_last4, these will be merged together
    zip_same1 = Zips(zip5='12345',
                     zip_last4='6789',
                     state_abbreviation='VA',
                     county_number='000',
                     congressional_district_no='01')
    zip_same2 = Zips(zip5='12345',
                     zip_last4='6780',
                     state_abbreviation='VA',
                     county_number='000',
                     congressional_district_no='01')

    # Different states, same everything else
    zip_state1 = Zips(zip5='54321',
                      zip_last4='6789',
                      state_abbreviation='VA',
                      county_number='000',
                      congressional_district_no='01')
    zip_state2 = Zips(zip5='54321',
                      zip_last4='6780',
                      state_abbreviation='WA',
                      county_number='000',
                      congressional_district_no='01')

    # Different county codes, same everything else
    zip_county1 = Zips(zip5='11111',
                       zip_last4='1111',
                       state_abbreviation='VA',
                       county_number='000',
                       congressional_district_no='01')
    zip_county2 = Zips(zip5='11111',
                       zip_last4='1112',
                       state_abbreviation='VA',
                       county_number='001',
                       congressional_district_no='01')

    # Everything matches except for congressional district
    zip_cd1 = Zips(zip5='22222',
                   zip_last4='2222',
                   state_abbreviation='VA',
                   county_number='000',
                   congressional_district_no='01')
    zip_cd2 = Zips(zip5='22222',
                   zip_last4='2223',
                   state_abbreviation='VA',
                   county_number='000',
                   congressional_district_no='02')

    # Different states, different congressional district
    zip_state_cd1 = Zips(zip5='33333',
                         zip_last4='3333',
                         state_abbreviation='VA',
                         county_number='000',
                         congressional_district_no='01')
    zip_state_cd2 = Zips(zip5='33333',
                         zip_last4='3334',
                         state_abbreviation='WA',
                         county_number='000',
                         congressional_district_no='02')

    # Null congressional district
    zip_null_cd = Zips(zip5='44444',
                       zip_last4='4444',
                       state_abbreviation='WA',
                       county_number='000',
                       congressional_district_no=None)

    sess.add_all([
        zip_same1, zip_same2, zip_state1, zip_state2, zip_county1, zip_county2,
        zip_cd1, zip_cd2, zip_state_cd1, zip_state_cd2, zip_null_cd
    ])
    sess.commit()

    # Creating the temp tables to use for testing
    sess.execute("""
        CREATE TABLE temp_zips AS
        SELECT * FROM zips;

        CREATE TABLE temp_zips_grouped (LIKE zips_grouped INCLUDING ALL);
    """)
    sess.commit()

    group_zips(sess)

    # Moving into zips_grouped for easier parsing
    sess.execute("""
        INSERT INTO zips_grouped
        SELECT *
        FROM temp_zips_grouped
    """)
    sess.commit()

    # Combined first set of zips
    zips = sess.query(ZipsGrouped).filter_by(zip5=zip_same1.zip5).all()
    assert len(zips) == 1
    assert zips[0].zip5 == zip_same1.zip5
    assert zips[0].state_abbreviation == zip_same1.state_abbreviation
    assert zips[0].county_number == zip_same1.county_number
    assert zips[
        0].congressional_district_no == zip_same1.congressional_district_no

    # Different states, same everything else
    zips = sess.query(ZipsGrouped).filter_by(zip5=zip_state1.zip5).order_by(
        ZipsGrouped.state_abbreviation).all()
    assert len(zips) == 2
    assert zips[0].zip5 == zip_state1.zip5
    assert zips[0].state_abbreviation == zip_state1.state_abbreviation
    assert zips[0].county_number == zip_state1.county_number
    assert zips[
        0].congressional_district_no == zip_state1.congressional_district_no
    assert zips[1].zip5 == zip_state2.zip5
    assert zips[1].state_abbreviation == zip_state2.state_abbreviation
    assert zips[1].county_number == zip_state2.county_number
    assert zips[
        1].congressional_district_no == zip_state2.congressional_district_no

    # Different counties, same everything else
    zips = sess.query(ZipsGrouped).filter_by(zip5=zip_county1.zip5).order_by(
        ZipsGrouped.county_number).all()
    assert len(zips) == 2
    assert zips[0].zip5 == zip_county1.zip5
    assert zips[0].state_abbreviation == zip_county1.state_abbreviation
    assert zips[0].county_number == zip_county1.county_number
    assert zips[
        0].congressional_district_no == zip_county1.congressional_district_no
    assert zips[1].zip5 == zip_county2.zip5
    assert zips[1].state_abbreviation == zip_county2.state_abbreviation
    assert zips[1].county_number == zip_county2.county_number
    assert zips[
        1].congressional_district_no == zip_county2.congressional_district_no

    # Different congressional districts
    zips = sess.query(ZipsGrouped).filter_by(zip5=zip_cd1.zip5).all()
    assert len(zips) == 1
    assert zips[0].zip5 == zip_cd1.zip5
    assert zips[0].state_abbreviation == zip_cd1.state_abbreviation
    assert zips[0].county_number == zip_cd1.county_number
    assert zips[0].congressional_district_no == '90'

    # Different states, different congressional districts
    zips = sess.query(ZipsGrouped).filter_by(zip5=zip_state_cd1.zip5).order_by(
        ZipsGrouped.state_abbreviation).all()
    assert len(zips) == 2
    assert zips[0].zip5 == zip_state_cd1.zip5
    assert zips[0].state_abbreviation == zip_state_cd1.state_abbreviation
    assert zips[0].county_number == zip_state_cd1.county_number
    assert zips[0].congressional_district_no == '90'
    assert zips[1].zip5 == zip_state_cd2.zip5
    assert zips[1].state_abbreviation == zip_state_cd2.state_abbreviation
    assert zips[1].county_number == zip_state_cd2.county_number
    assert zips[1].congressional_district_no == '90'

    # Null congressional district
    zips = sess.query(ZipsGrouped).filter_by(zip5=zip_null_cd.zip5).all()
    assert len(zips) == 1
    assert zips[0].zip5 == zip_null_cd.zip5
    assert zips[0].state_abbreviation == zip_null_cd.state_abbreviation
    assert zips[0].county_number == zip_null_cd.county_number
    assert zips[0].congressional_district_no == '90'
Exemple #8
0
def test_success(database):
    """ The provided PrimaryPlaceofPerformanceZIP+4 must be in the state specified by PrimaryPlaceOfPerformanceCode.
        In this specific submission row, the first five digits are valid and located in the correct state, but the
        last 4 are invalid.
    """

    zips = Zips(zip5='12345', zip_last4='6789', state_abbreviation='NY')
    # ignored because no zip4
    fabs_1 = FABSFactory(place_of_performance_code='NY*****',
                         place_of_performance_zip4a='',
                         correction_delete_indicatr='')
    fabs_2 = FABSFactory(place_of_performance_code='Ny**123',
                         place_of_performance_zip4a=None,
                         correction_delete_indicatr='c')
    fabs_3 = FABSFactory(place_of_performance_code='Ny**123',
                         place_of_performance_zip4a='city-wide',
                         correction_delete_indicatr='')
    # valid 9 digit zip
    fabs_4 = FABSFactory(place_of_performance_code='NY98765',
                         place_of_performance_zip4a='123456789',
                         correction_delete_indicatr=None)
    fabs_5 = FABSFactory(place_of_performance_code='ny98765',
                         place_of_performance_zip4a='123456789',
                         correction_delete_indicatr='C')
    fabs_6 = FABSFactory(place_of_performance_code='ny98765',
                         place_of_performance_zip4a='12345-6789',
                         correction_delete_indicatr='')
    # Ignore correction delete indicator of D
    fabs_7 = FABSFactory(place_of_performance_code='ny10986',
                         place_of_performance_zip4a='123456788',
                         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, zips])
    assert errors == 0

    # random wrong length zips and zips with '-' in the wrong place, formatting is checked in another rule
    fabs_1 = FABSFactory(place_of_performance_code='ny10986',
                         place_of_performance_zip4a='12345678',
                         correction_delete_indicatr='')
    fabs_2 = FABSFactory(place_of_performance_code='ny10986',
                         place_of_performance_zip4a='1234567898',
                         correction_delete_indicatr='')
    fabs_3 = FABSFactory(place_of_performance_code='ny10986',
                         place_of_performance_zip4a='12345678-9',
                         correction_delete_indicatr='')
    fabs_4 = FABSFactory(place_of_performance_code='ny10986',
                         place_of_performance_zip4a='123-456789',
                         correction_delete_indicatr='')
    errors = number_of_errors(_FILE,
                              database,
                              models=[fabs_1, fabs_2, fabs_3, fabs_4, zips])
    assert errors == 0

    # invalid 5 digit zip - this should pass but is handled in d41_3
    fabs_1 = FABSFactory(place_of_performance_code='ny10986',
                         place_of_performance_zip4a='12346',
                         correction_delete_indicatr='')
    fabs_2 = FABSFactory(place_of_performance_code='NA*****',
                         place_of_performance_zip4a='12345',
                         correction_delete_indicatr='')
    fabs_3 = FABSFactory(place_of_performance_code='NA*****',
                         place_of_performance_zip4a='12346-6789',
                         correction_delete_indicatr='')
    # valid 5 digit zip
    fabs_4 = FABSFactory(place_of_performance_code='Ny**123',
                         place_of_performance_zip4a='12345',
                         correction_delete_indicatr='')
    errors = number_of_errors(_FILE,
                              database,
                              models=[fabs_1, fabs_2, fabs_3, fabs_4, zips])
    assert errors == 0
Exemple #9
0
def test_success(database):
    """ The provided PrimaryPlaceofPerformanceZIP+4 must be in the state specified by PrimaryPlaceOfPerformanceCode.
        In this specific submission row, the first five digits are valid and located in the correct state, but the
        last 4 are invalid."""

    zips = Zips(zip5="12345", zip_last4="6789", state_abbreviation="NY")
    # ignored because no zip4
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NY*****", place_of_performance_zip4a="")
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="Ny**123", place_of_performance_zip4a=None)
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="Ny**123",
        place_of_performance_zip4a='city-wide')
    # valid 9 digit zip
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NY98765",
        place_of_performance_zip4a="123456789")
    det_award_5 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny98765",
        place_of_performance_zip4a="123456789")
    det_award_6 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny98765",
        place_of_performance_zip4a="12345-6789")
    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, zips
                              ])
    assert errors == 0

    # random wrong length zips and zips with '-' in the wrong place, formatting is checked in another rule
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="12345678")
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="1234567898")
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="12345678-9")
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="123-456789")
    errors = number_of_errors(
        _FILE,
        database,
        models=[det_award_1, det_award_2, det_award_3, det_award_4, zips])
    assert errors == 0

    # invalid 5 digit zip - this should pass but is handled in d41_3
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="12346")
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NA*****",
        place_of_performance_zip4a='12345')
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NA*****",
        place_of_performance_zip4a='12346-6789')
    # valid 5 digit zip
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="Ny**123",
        place_of_performance_zip4a="12345")
    errors = number_of_errors(
        _FILE,
        database,
        models=[det_award_1, det_award_2, det_award_3, det_award_4, zips])
    assert errors == 0
Exemple #10
0
def test_success(database):
    """ When provided, PrimaryPlaceofPerformanceZIP+4 must be in the state specified by PrimaryPlaceOfPerformanceCode.
        In this specific submission row, the ZIP5 (and by extension the full ZIP+4) is not a valid ZIP code in the
        state in question.
    """

    zips = Zips(zip5='12345', zip_last4='6789', state_abbreviation='NY')
    # ignored because no zip4
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='NY*****',
        place_of_performance_zip4a='',
        correction_delete_indicatr='')
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='Ny**123',
        place_of_performance_zip4a=None,
        correction_delete_indicatr=None)
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='Ny**123',
        place_of_performance_zip4a='city-wide',
        correction_delete_indicatr='')
    # valid 5 digit zip
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='Ny**123',
        place_of_performance_zip4a='12345',
        correction_delete_indicatr='c')
    det_award_5 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='NY98765',
        place_of_performance_zip4a='12345',
        correction_delete_indicatr='')
    # valid 9 digit zip
    det_award_6 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='NY98765',
        place_of_performance_zip4a='123456789',
        correction_delete_indicatr='C')
    det_award_7 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny98765',
        place_of_performance_zip4a='123456789',
        correction_delete_indicatr='')
    det_award_8 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny98765',
        place_of_performance_zip4a='12345-6789',
        correction_delete_indicatr='')
    # invalid 9 digit zip but this should pass for this rule, it will be handled for d_41_5
    det_award_9 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny98765',
        place_of_performance_zip4a='12345-6788',
        correction_delete_indicatr='')
    # Ignore correction delete indicator of D
    det_award_10 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny10986',
        place_of_performance_zip4a='12346',
        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, det_award_9,
                                  det_award_10, zips
                              ])
    assert errors == 0

    # random wrong length zips and zips with '-' in the wrong place, formatting is checked in another rule
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny10986',
        place_of_performance_zip4a='12345678',
        correction_delete_indicatr='')
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny10986',
        place_of_performance_zip4a='1234567898',
        correction_delete_indicatr='')
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny10986',
        place_of_performance_zip4a='12345678-9',
        correction_delete_indicatr='')
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code='ny10986',
        place_of_performance_zip4a='123-456789',
        correction_delete_indicatr='')
    errors = number_of_errors(
        _FILE,
        database,
        models=[det_award_1, det_award_2, det_award_3, det_award_4, zips])
    assert errors == 0
Exemple #11
0
def test_success(database):
    """ When provided, PrimaryPlaceofPerformanceZIP+4 must be in the state specified by PrimaryPlaceOfPerformanceCode.
        In this specific submission row, the ZIP5 (and by extension the full ZIP+4) is not a valid ZIP code in the
        state in question."""

    zips = Zips(zip5="12345", zip_last4="6789", state_abbreviation="NY")
    # ignored because no zip4
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NY*****", place_of_performance_zip4a="")
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="Ny**123", place_of_performance_zip4a=None)
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="Ny**123",
        place_of_performance_zip4a="city-wide")
    # valid 5 digit zip
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="Ny**123",
        place_of_performance_zip4a="12345")
    det_award_5 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NY98765",
        place_of_performance_zip4a="12345")
    # valid 9 digit zip
    det_award_6 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="NY98765",
        place_of_performance_zip4a="123456789")
    det_award_7 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny98765",
        place_of_performance_zip4a="123456789")
    det_award_8 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny98765",
        place_of_performance_zip4a="12345-6789")
    # invalid 9 digit zip but this should pass for this rule, it will be handled for d_41_5
    det_award_9 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny98765",
        place_of_performance_zip4a="12345-6788")
    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, det_award_9, zips
                              ])
    assert errors == 0

    # random wrong length zips and zips with '-' in the wrong place, formatting is checked in another rule
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="12345678")
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="1234567898")
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="12345678-9")
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="ny10986",
        place_of_performance_zip4a="123-456789")
    errors = number_of_errors(
        _FILE,
        database,
        models=[det_award_1, det_award_2, det_award_3, det_award_4, zips])
    assert errors == 0