def test_failure(database):
    """ Test failure PrimaryPlaceOfPerformanceCongressionalDistrict exists in the state indicated by the
        PrimaryPlaceOfPerformanceCode or is 90 in a state with multiple districts or when PrimaryPlaceOfPerformanceCode
        is 00***** """
    state_congr_1 = StateCongressional(congressional_district_no="01",
                                       state_code="NY")
    state_congr_2 = StateCongressional(congressional_district_no="02",
                                       state_code="NY")
    state_congr_3 = StateCongressional(congressional_district_no="01",
                                       state_code="PA")
    det_award_1 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="nY12345", place_of_performance_congr="03")
    det_award_2 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="PA12345", place_of_performance_congr="02")
    det_award_3 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="PA**345", place_of_performance_congr="90")
    det_award_4 = DetachedAwardFinancialAssistanceFactory(
        place_of_performance_code="00*****", place_of_performance_congr="01")

    errors = number_of_errors(_FILE,
                              database,
                              models=[
                                  det_award_1, det_award_2, det_award_3,
                                  det_award_4, state_congr_1, state_congr_2,
                                  state_congr_3
                              ])
    assert errors == 4
def update_state_congr_table_current(sess):
    logger.info("Loading zip codes complete, beginning update of state_congressional table")
    # clear old data out
    sess.query(StateCongressional).delete(synchronize_session=False)
    sess.commit()

    # get new data
    distinct_list = sess.query(Zips.state_abbreviation, Zips.congressional_district_no).distinct().\
        order_by(Zips.state_abbreviation, Zips.congressional_district_no)
    sess.bulk_save_objects([StateCongressional(state_code=state_data.state_abbreviation,
                                               congressional_district_no=state_data.congressional_district_no)
                            for state_data in distinct_list])
    sess.commit()